Chromia
Start Building

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:

bash
chr build & chr test

2. Manual testing on local node

Start the node locally

bash
chr node start

Generate keypairs of the test users

Create a key pair for each test user.

Alice:

bash
chr keygen --file .chromia/alice_keypair

Trudy:

bash
chr keygen --file .chromia/trudy_keypair

Initialize 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.

bash
chr tx initialize_dapp --secret .chromia/admin_keypair

Mint initial assets

Mint a starting supply of assets into the pool account:

bash
chr tx mint --secret .chromia/admin_keypair

You should see output like this:

bash
transaction with rid D6A1E290E9E00E25453D182742CB92D6707BD38B89712C8AE6A53EF9452BF55A was posted and confirmed

Note: Each transaction execution produces a different transaction RID.

Check pool account balance

Confirm the pool account's balance with:

bash
chr query get_pool_account_balance

Output:

bash
1000000000L

Create user accounts

Operations require authentication, so each user needs an account.

Alice:

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

For details on the auth descriptor's authorization flags, see the built-in authorization flags documentation.

Trudy:

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

Faucet assets

Request test assets from the faucet.

Alice:

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

Trudy:

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

Transfer assets

Send assets to another account with:

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

Lock/Unlock assets

Lock assets on a given account with:

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

FT4_LOCK is the default lock type in FT4.

Release locked assets with:

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

Check user balances

Query a user's asset balance with:

bash
chr query get_user_account_balance pubkey='x"ALICE_PUBKEY"'

Output:

bash
99900L

Note: 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:

bash
chr query get_user_lock_account_balance pubkey='x"ALICE_PUBKEY"'

Output:

bash
[]

Sample output when locked balances are present:

bash
[  [    "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 an L suffix
    • type: the lock type, such as "FT4_LOCK"
    • rowid: a unique ID for the lock record
Written for this site from Chromia’s public course. Code samples are the course’s own.