diff --git a/packages/actions/sources/currency.move b/packages/actions/sources/currency.move index fa29397..44ee61b 100644 --- a/packages/actions/sources/currency.move +++ b/packages/actions/sources/currency.move @@ -448,6 +448,11 @@ public fun propose_transfer( assert!(has_lock(account), ENoLock); assert!(amounts.length() == recipients.length(), EAmountsRecipentsNotSameLength); + let lock: &CurrencyLock = borrow_lock(account); + assert!(lock.can_mint, EMintDisabled); + let sum = amounts.fold!(0, |sum, amount| sum + amount); + if (lock.max_supply.is_some()) assert!(sum <= *lock.max_supply.borrow(), EMaxSupply); + let mut proposal = account.create_proposal( auth, outcome, @@ -507,6 +512,9 @@ public fun propose_vesting( ctx: &mut TxContext ) { assert!(has_lock(account), ENoLock); + let lock: &CurrencyLock = borrow_lock(account); + assert!(lock.can_mint, EMintDisabled); + if (lock.max_supply.is_some()) assert!(total_amount <= *lock.max_supply.borrow(), EMaxSupply); let mut proposal = account.create_proposal( auth, diff --git a/packages/actions/tests/currency_tests.move b/packages/actions/tests/currency_tests.move index 1cec483..20eb529 100644 --- a/packages/actions/tests/currency_tests.move +++ b/packages/actions/tests/currency_tests.move @@ -1006,6 +1006,56 @@ fun test_error_propose_transfer_not_same_length() { end(scenario, extensions, account, clock, metadata); } +#[test, expected_failure(abort_code = currency::EMintDisabled)] +fun test_error_propose_transfer_mint_disabled() { + let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + currency::lock_cap(auth, &mut account, cap, option::none()); + + currency::toggle_can_mint(&mut account); + + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + let outcome = multisig::new_outcome(&account, scenario.ctx()); + currency::propose_transfer( + auth, + &mut account, + outcome, + b"dummy".to_string(), + b"".to_string(), + 0, + 1, + vector[1], + vector[@0x1], + scenario.ctx() + ); + + end(scenario, extensions, account, clock, metadata); +} + +#[test, expected_failure(abort_code = currency::EMaxSupply)] +fun test_error_propose_transfer_mint_too_many() { + let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + currency::lock_cap(auth, &mut account, cap, option::some(4)); + + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + let outcome = multisig::new_outcome(&account, scenario.ctx()); + currency::propose_transfer( + auth, + &mut account, + outcome, + b"dummy".to_string(), + b"".to_string(), + 0, + 1, + vector[1, 2, 3], + vector[@0x1, @0x2, @0x3], + scenario.ctx() + ); + + end(scenario, extensions, account, clock, metadata); +} + #[test, expected_failure(abort_code = currency::ENoLock)] fun test_error_propose_vesting_no_lock() { let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); @@ -1031,6 +1081,60 @@ fun test_error_propose_vesting_no_lock() { end(scenario, extensions, account, clock, metadata); } +#[test, expected_failure(abort_code = currency::EMintDisabled)] +fun test_error_propose_vesting_mint_disabled() { + let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + currency::lock_cap(auth, &mut account, cap, option::none()); + + currency::toggle_can_mint(&mut account); + + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + let outcome = multisig::new_outcome(&account, scenario.ctx()); + currency::propose_vesting( + auth, + &mut account, + outcome, + b"dummy".to_string(), + b"".to_string(), + 0, + 1, + 5, + 1, + 2, + @0x1, + scenario.ctx() + ); + + end(scenario, extensions, account, clock, metadata); +} + +#[test, expected_failure(abort_code = currency::EMaxSupply)] +fun test_error_propose_vesting_mint_too_many() { + let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + currency::lock_cap(auth, &mut account, cap, option::some(4)); + + let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); + let outcome = multisig::new_outcome(&account, scenario.ctx()); + currency::propose_vesting( + auth, + &mut account, + outcome, + b"dummy".to_string(), + b"".to_string(), + 0, + 1, + 5, + 1, + 2, + @0x1, + scenario.ctx() + ); + + end(scenario, extensions, account, clock, metadata); +} + #[test, expected_failure(abort_code = currency::ENoChange)] fun test_error_disable_nothing() { let (mut scenario, extensions, mut account, clock, cap, metadata) = start(); diff --git a/packages/actions/tests/owned_tests.move b/packages/actions/tests/owned_tests.move index 38e9e5e..c5917df 100644 --- a/packages/actions/tests/owned_tests.move +++ b/packages/actions/tests/owned_tests.move @@ -67,7 +67,7 @@ fun wrong_version(): TypeName { type_name::get() } -fun keep_coin(addr: address, amount: u64, scenario: &mut Scenario): ID { +fun send_coin(addr: address, amount: u64, scenario: &mut Scenario): ID { let coin = coin::mint_for_testing(amount, scenario.ctx()); let id = object::id(&coin); transfer::public_transfer(coin, addr); @@ -104,8 +104,8 @@ fun test_propose_execute_transfer() { let (mut scenario, extensions, mut account, clock) = start(); let key = b"dummy".to_string(); - let id1 = keep_coin(account.addr(), 1, &mut scenario); - let id2 = keep_coin(account.addr(), 2, &mut scenario); + let id1 = send_coin(account.addr(), 1, &mut scenario); + let id2 = send_coin(account.addr(), 2, &mut scenario); let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); let outcome = multisig::new_outcome(&account, scenario.ctx()); @@ -145,7 +145,7 @@ fun test_propose_execute_vesting() { let (mut scenario, extensions, mut account, clock) = start(); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); let auth = multisig::authenticate(&extensions, &account, b"".to_string(), scenario.ctx()); let outcome = multisig::new_outcome(&account, scenario.ctx()); @@ -185,7 +185,7 @@ fun test_withdraw_flow() { let (mut scenario, extensions, mut account, clock) = start(); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions); owned::new_withdraw(&mut proposal, id, DummyProposal()); @@ -213,7 +213,7 @@ fun test_withdraw_expired() { clock.increment_for_testing(1); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions); owned::new_withdraw(&mut proposal, id, DummyProposal()); @@ -256,7 +256,7 @@ fun test_error_do_withdraw_from_wrong_account() { let mut account2 = multisig::new_account(&extensions, b"Main".to_string(), scenario.ctx()); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); // proposal is submitted to other account let mut proposal = create_dummy_proposal(&mut scenario, &mut account2, &extensions); @@ -285,7 +285,7 @@ fun test_error_do_withdraw_from_wrong_constructor_witness() { let (mut scenario, extensions, mut account, clock) = start(); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions); owned::new_withdraw(&mut proposal, id, DummyProposal()); @@ -312,7 +312,7 @@ fun test_error_do_withdraw_from_not_dep() { let (mut scenario, extensions, mut account, clock) = start(); let key = b"dummy".to_string(); - let id = keep_coin(account.addr(), 5, &mut scenario); + let id = send_coin(account.addr(), 5, &mut scenario); let mut proposal = create_dummy_proposal(&mut scenario, &mut account, &extensions); owned::new_withdraw(&mut proposal, id, DummyProposal());