Skip to main content

Testing the dapp

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

First, make sure that the blockchains are defined in the following order to ensure that the internal IDs are the same as those used in this course:

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

We then start the blockchains by running the following command from the project folder in a separate terminal window:

$ chr node start

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

$ chr keygen --save .chromia/config

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

We can then see that making a transaction towards the digital warehouse will fail by trying to register a new product category:

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

Let's create a new subscription on the Subscription chain before trying again. We must figure out the blockchain rid of the digital warehouse to do this. We can do this by asking the node and storing the value to a variable:

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

now we can make a new subscription:

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

Note down the transaction rid that was output from the command. The following command can now do authentication towards the digital warehouse:

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

This command says that we want to make a transaction towards chain id 1, and with it we want to include a iccf-transaction that should be verified against chain 0.

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

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

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

$ chr query --cid 1 create_report 'from=0' 'to=null'
[
"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'
[
[
"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 write a dapp that confirms transactions made on another chain to authenticate the user.