Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
movekevin committed Dec 18, 2022
1 parent 11ff1d6 commit 7089c7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-framework/doc/aptos_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Set whether <code><a href="account.md#0x1_account">account</a></code> can receiv
<b>if</b> (<b>exists</b>&lt;<a href="aptos_account.md#0x1_aptos_account_DirectTransferConfig">DirectTransferConfig</a>&gt;(addr)) {
<b>let</b> direct_transfer_config = <b>borrow_global_mut</b>&lt;<a href="aptos_account.md#0x1_aptos_account_DirectTransferConfig">DirectTransferConfig</a>&gt;(addr);
// Short-circuit <b>to</b> avoid emitting an <a href="event.md#0x1_event">event</a> <b>if</b> direct transfer config is not changing.
<b>if</b> (direct_transfer_config.allow_arbitrary_coin_transfers != allow) {
<b>if</b> (direct_transfer_config.allow_arbitrary_coin_transfers == allow) {
<b>return</b>
};

Expand Down
14 changes: 13 additions & 1 deletion aptos-move/framework/aptos-framework/sources/aptos_account.move
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module aptos_framework::aptos_account {
if (exists<DirectTransferConfig>(addr)) {
let direct_transfer_config = borrow_global_mut<DirectTransferConfig>(addr);
// Short-circuit to avoid emitting an event if direct transfer config is not changing.
if (direct_transfer_config.allow_arbitrary_coin_transfers != allow) {
if (direct_transfer_config.allow_arbitrary_coin_transfers == allow) {
return
};

Expand Down Expand Up @@ -253,6 +253,18 @@ module aptos_framework::aptos_account {
coin::destroy_freeze_cap(freeze_cap);
}

#[test(user = @0x123)]
public fun test_set_allow_direct_coin_transfers(user: &signer) acquires DirectTransferConfig {
let addr = signer::address_of(user);
create_account_for_test(addr);
set_allow_direct_coin_transfers(user, true);
assert!(can_receive_direct_coin_transfers(addr), 0);
set_allow_direct_coin_transfers(user, false);
assert!(!can_receive_direct_coin_transfers(addr), 1);
set_allow_direct_coin_transfers(user, true);
assert!(can_receive_direct_coin_transfers(addr), 2);
}

#[test(from = @0x1, to = @0x12)]
public fun test_direct_coin_transfers_with_explicit_direct_coin_transfer_config(
from: &signer, to: &signer) acquires DirectTransferConfig {
Expand Down

0 comments on commit 7089c7b

Please sign in to comment.