06 / 06Intermediate
Testing the dapp
To test the dapp by hand, start both blockchains, create a subscription, and then use that subscription to get into the warehouse.
The internal chain IDs used throughout this course depend on the order of the blockchain definitions. Make sure yours are listed in this order:
blockchains: subscription_chain: # Chain id 1 ... digital-warehouse-chain: # Chain id 2 ...Open a separate terminal window and run the node from the project folder to start the blockchains:
chr node start --directory-chain-mockThe logs should look similar to this:
...Starting blockchain directory-chain with brid B39406781EE6CA71391B519AA1D3B009DA77A0A63B12DCB2BD4DD59C679E2703 on id 0Starting blockchain subscription_chain with brid EB0A24835FC5B49CFCB6A9C3DC688FBC7D457455E69B9B2956E7689BC830CA49 on id 1Starting blockchain digital_warehouse_chain with brid 42C95A7CCDAE9B78524A32428E7B313F60AEB31BA66FF41A0ECE2FCB576D5FF4 on id 2...Your brid values may differ from the ones shown.
Store the brids in environment variables so you can reuse them in later steps:
SUBSCRIPTION_CHAIN_BRID=$(curl -s localhost:7740/brid/iid_1) && echo $SUBSCRIPTION_CHAIN_BRIDDIGITAL_WAREHOUSE_BRID=$(curl -s localhost:7740/brid/iid_2) && echo $DIGITAL_WAREHOUSE_BRIDNext, generate a new keypair and save it in .chromia/config, which is where Chromia CLI looks by default:
chr keygen --file .chromia/configCopy the pubkey shown in the console. It serves as the account ID for the operations that follow.
Try registering a new product category. Because you have no subscription yet, the transaction to the digital warehouse fails:
chr tx -brid $DIGITAL_WAREHOUSE_BRID register_product_category 555 0 --await -cfg .chromia/config... Operation 'digital_warehouse_chain:register_product_category' failed: No account foundBefore retrying, you need a subscription on the Subscription chain.
Create one now, substituting your generated key for <pubkey>:
chr tx -brid $SUBSCRIPTION_CHAIN_BRID subscribe 'x"<digital_warehouse_brid>" '[x"<pubkey>", 0]' --await -cfg .chromia/configHere is the same command using environment variable substitution:
chr tx -brid $SUBSCRIPTION_CHAIN_BRID subscribe 'x"'"$DIGITAL_WAREHOUSE_BRID"'"' '[x"021E6EE49D997C6DF7721F87027BB56D7436A9CC78F344AE6FF2E8A08789D37F5A", 0]' --await -cfg .chromia/configYou should see output like this:
transaction with rid F300CBD62F22917145F8594DB63F1780803CD123CA7F89DBE952431409EE2629 was posted CONFIRMEDKeep the transaction rid from that output. Use it in the next command, in place of <tx-rid>, to authenticate with the digital warehouse.
The command targets chain ID 2 and attaches an iccf-transaction that must be verified against chain 1:
chr tx -brid $DIGITAL_WAREHOUSE_BRID --iccf-source $SUBSCRIPTION_CHAIN_BRID --iccf-tx <tx-rid> authorize --await -cfg .chromia/configYou now have access to the system. Register a product category and update the inventory once more:
chr tx -brid $DIGITAL_WAREHOUSE_BRID register_product_category 555 0 --await -cfg .chromia/configchr tx -brid $DIGITAL_WAREHOUSE_BRID update_inventory '[555, 1500, "Got some stuff"]' --await -cfg .chromia/configFinally, generate a warehouse report and inspect the receipts on the subscription chain:
chr query -brid $DIGITAL_WAREHOUSE_BRID create_report 'from=0' 'to=null' -cfg .chromia/config[ "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 -brid $SUBSCRIPTION_CHAIN_BRID 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 ]]You have built a dapp that authenticates users by verifying transactions made on a different chain.