Skip to content

Commit 0f11122

Browse files
committed
feat: unit test.
1 parent 89669fa commit 0f11122

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

aptos-move/framework/aptos-framework/sources/aptos_coin.move

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@ module aptos_framework::aptos_coin {
107107
coin::deposit<AptosCoin>(dst_addr, coins_minted);
108108
}
109109

110+
/// Desroy the mint capability from the account.
111+
public fun destroy_mint_capability_from(account: &signer, from: address) acquires MintCapStore {
112+
system_addresses::assert_aptos_framework(account);
113+
let MintCapStore { mint_cap } = move_from<MintCapStore>(from);
114+
coin::destroy_mint_cap(mint_cap);
115+
}
116+
110117
/// Only callable in tests and testnets where the core resources account exists.
111118
/// Create delegated token for the address so the account could claim MintCapability later.
112-
public entry fun delegate_mint_capability(account: signer, to: address) acquires Delegations {
113-
system_addresses::assert_core_resource(&account);
119+
public entry fun delegate_mint_capability(account: &signer, to: address) acquires Delegations {
120+
system_addresses::assert_core_resource(account);
114121
let delegations = &mut borrow_global_mut<Delegations>(@core_resources).inner;
115122
vector::for_each_ref(delegations, |element| {
116123
let element: &DelegatedMintCapability = element;
@@ -201,4 +208,28 @@ module aptos_framework::aptos_coin {
201208
coin::create_pairing<AptosCoin>(aptos_framework);
202209
(burn_cap, mint_cap)
203210
}
211+
212+
#[test(aptos_framework = @aptos_framework, destination = @0x2)]
213+
public entry fun test_destroy_mint_cap(
214+
aptos_framework: &signer,
215+
destination: &signer,
216+
) acquires Delegations, MintCapStore {
217+
218+
// initialize the `aptos_coin`
219+
let (burn_cap, mint_cap) = initialize_for_test(aptos_framework);
220+
let core_resource
221+
222+
// delegate and claim the mint capability
223+
delegate_mint_capability(aptos_framework, signer::address_of(destination));
224+
claim_mint_capability(destination);
225+
226+
// destroy the mint Capability
227+
destroy_mint_capability_from(aptos_framework, signer::address_of(destination));
228+
229+
// check if the mint capability is destroyed
230+
assert!(!exists<MintCapStore>(signer::address_of(destination)), 2);
231+
232+
coin::destroy_burn_cap(burn_cap);
233+
coin::destroy_mint_cap(mint_cap);
234+
}
204235
}

0 commit comments

Comments
 (0)