Skip to main content

Test using Chromia CLI

We now have all the building blocks for our marketplace, so let's test them out using Chromia CLI. Chromia CLI is a command-line tool that allows interaction with the Chromia blockchain utilizing a set of commands. You can read more about it here.

Queries for verification

To make data verification easier, we will add two helper queries to our app. They will help us fetch and verify accounts and account balances.

rell_marketplace/module.rell
import lib.ft4.assets. { asset, Unsafe, balance };
rell_marketplace/queries.rell
query get_all_accounts()
{
return account @* {} ($.to_struct());
}

query get_all_balances()
{
return balance @* {} ($.account.to_struct(), $.to_struct());
}

Begin testing

Now we can begin our testing, and we start our blockchain node by running:

Create accounts

chr node start

Open a new terminal, where we will start issuing commands using the CLI. First, we can make sure that the dapp account was created by querying the accounts.

chr query get_all_accounts

Now, we can create two users, Alice and Bob.

chr keygen --save .chromia/alice.keypair
chr keygen --save .chromia/bob.keypair

chr tx --await create_user "<alice pubkey>" --secret .chromia/alice.keypair
chr tx --await create_user "<bob pubkey>" --secret .chromia/bob.keypair

chr tx will send a transaction to call an operation on the blockchain.

We can now run a query to fetch the balances for all accounts. We want to confirm that our minting operation works correctly, so both Alice's and Bob's accounts should have 1000 CRDs.

chr query get_all_balances

This will generate a result similar to this, which contains our two created accounts and their balance (1000 CRD) that we minted in create_user

[
[[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 1000L]],
[[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 1000L]]
]

Buy a mystery card

Now that we have verified that the balances are okay, we can let Alice buy a mystery card.

chr tx --await buy_mystery_card --ft-auth --ft-account-id=<first id from get_all_balances query> --secret .chromia/alice.keypair

We can now have a look at the currently listed nft_cards and also check the balances to make sure the transaction has been completed.

chr query get_all_nfts

It should result in something similar to this, showing a card NFT with its properties.

[["health": 10, "nft_id": 22, "owner_id": x"<owner id>", "strength": 8]]

Checking the balance by using the following query

chr query get_all_balances

will result in the following balances for Alice, Bob, and the Economy Account.

ParticipantActionAmountBalance
AliceBought a mystery card-100 CRD900 CRD
BobNo action1000 CRD
Economy AccountReceived from Alice+100 CRD100 CRD
[
[[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 900L]], // Alice
[[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 1000L]], // Bob
[[x"522546AF72636ABA2AFE34E1BF2D7BF2B9C0A483C20F87E145BE32992339962C"], [2, 1, 100L]] // Economy account
]

List cards on the marketplace

We let Alice list her card on the marketplace for 25 CRD. We can get the nft_id from our previous query get_all_nfts and the FT4 account id for Alice from get_all_balances

chr tx --await list_nft "<nft_id from query>" "25L" --secret .chromia/alice.keypair --ft-auth --ft-account-id=<FT4 account from query>

and then we query using get_cards and pass arguments for filtering and sorting

chr query get_cards "amount=10" "card_sorting=PRICE_HIGH" 

This should generate a single result with the card Alice listed on the marketplace.

Buy a card from the marketplace

Now, we will let Bob buy Alice's card by calling the buy_card operation

chr tx --await buy_nft "<nft id>" --secret .chromia/bob.keypair --ft-auth --ft-account-id=<Bobs FT4 account id from get_all_balances>

followed by query.

chr query get_all_balances

This will generate our final balances, which should look like this

ParticipantActionBalance
AliceBought a mystery card for 10 CRD
Received 25 CRD from Bob
925 CRD
BobBought Alice's card for 25 CRD975 CRD
Economy AccountReceived fee of 100 CRD from Alice100 CRD

and from our query.

[
[[x"3A0153952DCB30A904B1E3461321892C916B10E51897F32B3352DB65DDDA4562"], [7, 1, 925L]], // Alice
[[x"8EF62426BA321FB23D6163DCFBFC53049E9A078500264F012BC4E4AB5048A859"], [13, 1, 975L]], // Bob
[[x"522546AF72636ABA2AFE34E1BF2D7BF2B9C0A483C20F87E145BE32992339962C"], [2, 1, 100L]] // Economy account
]

This concludes our testing using Chromia CLI and also ends this course. We hope that you enjoyed it, and happy coding!