-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[asset-mapping] add fake money for asset mapping assign
- Loading branch information
Showing
4 changed files
with
134 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 10 additions & 14 deletions
24
vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
processed 4 tasks | ||
processed 7 tasks | ||
|
||
task 3 'run'. lines 7-19: | ||
task 5 'run'. lines 57-67: | ||
{ | ||
"gas_used": 2260938, | ||
"status": { | ||
"MoveAbort": { | ||
"location": { | ||
"Module": { | ||
"address": "0x00000000000000000000000000000001", | ||
"name": "fungible_asset" | ||
} | ||
}, | ||
"abort_code": "393239" | ||
} | ||
} | ||
"gas_used": 5320541, | ||
"status": "Executed" | ||
} | ||
|
||
task 6 'run'. lines 69-93: | ||
{ | ||
"gas_used": 4349075, | ||
"status": "Executed" | ||
} |
104 changes: 96 additions & 8 deletions
104
vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,107 @@ | ||
//# init -n dev | ||
|
||
//# faucet --addr alice --amount 100 | ||
//# faucet --addr alice --amount 0 | ||
|
||
//# faucet --addr Genesis | ||
//# faucet --addr bob --amount 10000000000000000 | ||
|
||
//# faucet --addr Genesis --amount 10000000000000000 | ||
|
||
//# faucet --addr core_resources | ||
|
||
|
||
//# publish | ||
module bob::fake_money { | ||
use std::signer; | ||
use std::string; | ||
|
||
use starcoin_framework::coin; | ||
|
||
struct FakeMoney has key {} | ||
|
||
struct FakeMoneyCapabilities has key { | ||
burn_cap: coin::BurnCapability<FakeMoney>, | ||
freeze_cap: coin::FreezeCapability<FakeMoney>, | ||
mint_cap: coin::MintCapability<FakeMoney>, | ||
} | ||
|
||
public fun init(account: &signer, decimal: u8) { | ||
let ( | ||
burn_cap, | ||
freeze_cap, | ||
mint_cap | ||
) = coin::initialize<FakeMoney>( | ||
account, | ||
string::utf8(b"FakeMoney"), | ||
string::utf8(b"FakeMoney"), | ||
decimal, | ||
true, | ||
); | ||
coin::register<FakeMoney>(account); | ||
move_to(account, FakeMoneyCapabilities { | ||
burn_cap, | ||
freeze_cap, | ||
mint_cap, | ||
}) | ||
} | ||
|
||
public fun mint(account: &signer, amount: u64): coin::Coin<FakeMoney> acquires FakeMoneyCapabilities { | ||
let cap = borrow_global<FakeMoneyCapabilities>(signer::address_of(account)); | ||
coin::mint(amount, &cap.mint_cap) | ||
} | ||
|
||
public fun burn(coin: coin::Coin<FakeMoney>) acquires FakeMoneyCapabilities { | ||
let cap = borrow_global<FakeMoneyCapabilities>(@bob); | ||
coin::burn(coin, &cap.burn_cap) | ||
} | ||
} | ||
// check: EXECUTED | ||
|
||
//# run --signers bob | ||
script { | ||
use bob::fake_money::{Self, FakeMoney}; | ||
use starcoin_framework::asset_mapping; | ||
|
||
fun test_create_fake_money_store(account: &signer) { | ||
fake_money::init(account, 9); | ||
let fake_money_coin = fake_money::mint(account, 100000000000); | ||
asset_mapping::create_store_from_coin<FakeMoney>(account, b"bob::fake_money::FakeMoney", fake_money_coin); | ||
} | ||
} | ||
|
||
//# run --signers Genesis | ||
script { | ||
use starcoin_framework::starcoin_coin::STC; | ||
use bob::fake_money::{FakeMoney}; | ||
use starcoin_framework::coin; | ||
use starcoin_framework::asset_mapping; | ||
|
||
fun test_asset_mapping_assign_to_account_with_proof(framework: signer) { | ||
assert!(coin::balance<STC>(@alice) == 100, 10001); | ||
asset_mapping::assign_to_account(&framework, @alice, b"0x1::STC::STC", 100); | ||
assert!(coin::balance<STC>(@alice) == 200, 10002); | ||
fun test_create_fake_money_store(account: &signer) { | ||
asset_mapping::assign_to_account(account, @bob, b"bob::fake_money::FakeMoney", 100000000000); | ||
assert!(coin::balance<FakeMoney>(@bob) == 100000000000, 10001); | ||
} | ||
} | ||
// check: EXECUTED | ||
|
||
//# run --signers core_resources | ||
script { | ||
use bob::fake_money::{FakeMoney}; | ||
use starcoin_framework::coin; | ||
use starcoin_framework::asset_mapping; | ||
|
||
fun test_create_fake_money_store(account: &signer) { | ||
asset_mapping::assign_to_account(account, @bob, b"bob::fake_money::FakeMoney", 100000000000); | ||
assert!(coin::balance<FakeMoney>(@bob) == 100000000000, 10001); | ||
} | ||
} | ||
|
||
// //# run --signers Genesis | ||
// script { | ||
// use starcoin_framework::starcoin_coin::STC; | ||
// use starcoin_framework::coin; | ||
// use starcoin_framework::asset_mapping; | ||
// | ||
// fun test_asset_mapping_assign_to_account_with_proof(framework: signer) { | ||
// assert!(coin::balance<STC>(@alice) == 0, 10001); | ||
// asset_mapping::assign_to_account(&framework, @alice, b"0x1::STC::STC", 100); | ||
// assert!(coin::balance<STC>(@alice) == 100, 10002); | ||
// } | ||
// } | ||
// // check: EXECUTED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters