Skip to main content

Testing

In this lesson, we will cover important security considerations and how to test our FT4 asset implementation.

1. End-to-end tests

The test cases can be found in the repo.

To run the tests, use the following command:

chr build & chr test

2. Manual testing on local node

Start the node locally

chr node start

Generate keypairs of the test users

Generate key pairs for the test users:

Alice:

chr keygen --file .chromia/alice_keypair

Trudy:

chr keygen --file .chromia/trudy_keypair

Initialize the dapp

Initialize the dapp using the admin key pair to create the pool account:

chr tx initialize_dapp --secret .chromia/admin_keypair

Mint initial assets

Mint initial assets to the pool account:

chr tx mint --secret .chromia/admin_keypair

Check pool account balance

To verify the pool account's balance, use:

chr query get_pool_account_balance

Output:

1000000000L

Create user accounts

User accounts are required for authentication in calling operations.

Alice:

chr tx ft4.ras_open '[0, [["A","T"],x"ALICE_PUBKEY"], null]' 'null' --ft-register-account --secret .chromia/alice_keypair --await

The authorization flags for the auth descriptor are described there.

Trudy:

chr tx ft4.ras_open '[0, [["A","T"],x"TRUDY_PUBKEY"], null]' 'null' --ft-register-account --secret .chromia/trudy_keypair --await

Faucet assets

To get test assets from the faucet:

Alice:

chr tx faucet --ft-auth --secret .chromia/alice_keypair

Trudy:

chr tx faucet --ft-auth --secret .chromia/trudy_keypair

Transfer assets

To transfer assets to another account, use:

chr tx transfer 'x"TRUDY_PUBKEY"' 100L --ft-auth --secret .chromia/alice_keypair

Lock/Unlock assets

To lock assets for a specific account, run:

chr tx lock_asset "FT4_LOCK" 'x"ALICE_PUBKEY"' 10L --secret .chromia/admin_keypair

FT4_LOCK is a default FT4 lock type.

To unlock assets, use:

chr tx unlock_asset "FT4_LOCK" 'x"ALICE_PUBKEY"' 10L --secret .chromia/admin_keypair

Check user balances

To check a user's asset balance, run:

chr query get_user_account_balance pubkey='x"ALICE_PUBKEY"'

To check a user's locked asset balance, use:

chr query get_user_lock_account_balance pubkey='x"ALICE_PUBKEY"'