05 / 06Advanced
Testing
This lesson shows you how to test your FT4 asset implementation.
1. End-to-end tests
The test cases are in src/test/assets_test.rell in the course repository. Copy that file into your project's src/test/ folder.
Run the tests with this command:
chr build & chr test2. Manual testing on local node
Start the node locally
chr node startGenerate keypairs of the test users
Create a key pair for each test user.
Alice:
chr keygen --file .chromia/alice_keypairTrudy:
chr keygen --file .chromia/trudy_keypairInitialize the dapp
Run the initialization with the admin key pair. This creates the pool account. You only need to do it once, and it is not strictly required.
chr tx initialize_dapp --secret .chromia/admin_keypairMint initial assets
Mint a starting supply of assets into the pool account:
chr tx mint --secret .chromia/admin_keypairYou should see output like this:
transaction with rid D6A1E290E9E00E25453D182742CB92D6707BD38B89712C8AE6A53EF9452BF55A was posted and confirmedNote: Each transaction execution produces a different transaction RID.
Check pool account balance
Confirm the pool account's balance with:
chr query get_pool_account_balanceOutput:
1000000000LCreate user accounts
Operations require authentication, so each user needs an account.
Alice:
chr tx ft4.ras_open '[0, [["A","T"],x"ALICE_PUBKEY"], null]' 'null' --ft-register-account --secret .chromia/alice_keypair --awaitFor details on the auth descriptor's authorization flags, see the built-in authorization flags documentation.
Trudy:
chr tx ft4.ras_open '[0, [["A","T"],x"TRUDY_PUBKEY"], null]' 'null' --ft-register-account --secret .chromia/trudy_keypair --awaitFaucet assets
Request test assets from the faucet.
Alice:
chr tx faucet --ft-auth --secret .chromia/alice_keypairTrudy:
chr tx faucet --ft-auth --secret .chromia/trudy_keypairTransfer assets
Send assets to another account with:
chr tx transfer 'x"TRUDY_PUBKEY"' 100L --ft-auth --secret .chromia/alice_keypairLock/Unlock assets
Lock assets on a given account with:
chr tx lock_asset "FT4_LOCK" 'x"ALICE_PUBKEY"' 10L --secret .chromia/admin_keypairFT4_LOCK is the default
lock type in FT4.
Release locked assets with:
chr tx unlock_asset "FT4_LOCK" 'x"ALICE_PUBKEY"' 10L --secret .chromia/admin_keypairCheck user balances
Query a user's asset balance with:
chr query get_user_account_balance pubkey='x"ALICE_PUBKEY"'Output:
99900LNote: Your balance may differ, since it depends on the account's current state and any transactions already made.
Query a user's locked asset balance with:
chr query get_user_lock_account_balance pubkey='x"ALICE_PUBKEY"'Output:
[]Sample output when locked balances are present:
[ [ "data": [ "amount": 20L, "type": "FT4_LOCK" ], "rowid": 31 ]]Note:
- An empty array
[]means the account has no locked balances- Each locked balance entry has these fields:
amount: the locked quantity in the smallest unit, written with anLsuffixtype: the lock type, such as "FT4_LOCK"rowid: a unique ID for the lock record