Skip to main content

Testing the dapp

We test the dapp manually by starting the corresponding blockchains, creating a subscription, and using it to access the warehouse.

First, ensure that the blockchains are defined in the following order to align with the internal IDs used in this course:

chromia.yml
blockchains:
subscription-chain: # Chain id 0
...
digital-warehouse-chain: # Chain id 1
...

To start the blockchains, you need to run the node from the project folder in a separate terminal window:

chr node start

Proceed with the setup by creating a new keypair and storing it in the .chromia/config directory, the default search path for Chromia CLI:

chr keygen --file .chromia/config

Note down the pubkey printed to the console. You will use this as the account ID input for our operations.

Next, attempt to register a new product category to observe that making a transaction towards the digital warehouse will fail:

chr tx --cid 1 register_product_category 555 0 --await
Result
... Operation 'digital_warehouse_chain:register_product_category' failed: No account found

Create a new subscription on the Subscription chain before attempting again. First, we need to determine the blockchain rid of the digital warehouse. You can obtain this by querying the node and storing the value in a variable:

DW_BRID=$(curl -s localhost:7740/brid/iid_1) && echo $DW_BRID

Now, you can create a new subscription. Replace <pubkey> with the previously generated one:

chr tx --cid 0 subscribe $DW_BRID '["<pubkey>", 0]' --await

Note the transaction rid that was output from the command. You can now use the following command to authenticate the digital warehouse. Replace <tx-rid> with the previously obtained value.

This command specifies that we intend to make a transaction towards chain ID 1 and include an iccf-transaction that needs verification against chain 0:

chr tx --cid 1 --iccf-source 0 --iccf-tx <tx-rid> authorize --await

Now, we should be able to access the system. Let's attempt to register a product category and update the inventory again:

chr tx --cid 1 register_product_category 555 0 --await
chr tx --cid 1 update_inventory '[555, 1500, "Got some stuff"]' --await

Let's wrap up by generating a warehouse report and checking the receipts in the subscription chain:

chr query --cid 1 create_report 'from=0' 'to=null'
Result
[
"history": [
[555, [
["amount": 1500, "comment": "Got some stuff", "product_category": 555, "transaction": 5]]
]
],
"inventory": [
["UNIT": "LITRE", "product_category": 555, "stock": 1500]
],
"warehouse_id": 1
]
chr query --cid 0 get_receipts 'account_id=null' 'blockchain_rid=null' 'from=null'
Result
[
[
"account_id": x"02EEB43C7400CA3CEBDECF1C8AC049EAC05EB361FE4C003EF6D298DEA792F58526",
"blockchain_rid": x"237B0EE3C60CBB1884E63F883F8230FED5C804A9C6933B28FD9214D65FD033B5",
"payment_amount": 30,
"period": "WEEK",
"receipt_id": x"6006EFC423E9032EA4C9584CDE791623A015749FD8BA4831457CCE0769BCA20A",
"timestamp": 1705504892289
]
]

Congratulations! You have now learned how to develop a dapp that verifies transactions on another chain to authenticate users.