07 / 07Advanced
Test the dapp
To test the dapp by hand, you run three blockchains locally, submit a customer order, and follow that order as it moves across the chains.
Before you begin, check that the chains in your chromia.yml file appear in this order:
blockchains: order_chain: # internal id 1 ... delivery_chain: # internal id 2 ... factory-chain: # internal id 3 ...The Chromia CLI starts the chains one after another according to the internal IDs defined here. These IDs are easier to work with during testing than the referential ID (brid), so keep them in mind.
Open a separate terminal window and start the node:
chr node start --directory-chain-mockNext, finish the setup by registering two products with the IDs 101 and 102:
chr tx --cid 1 register_product 101 --awaitchr tx --cid 1 register_product 102 --awaitYou can now place the first order. make_customer_order takes one argument, a struct of type order_details. When you pass a struct through the CLI, encode it as an array. For example, an order of 1 product of type 101 and 10 products of type 102, shipped to customer 1104 at Homestreet 2, becomes [1104, "Homestreet 2", [[101, 1], [102, 10]]]. Send an order with these details to chain 0:
chr tx --cid 1 make_customer_order '[1104, "Homestreet 2", [[101, 1], [102, 10]]]' --awaitThe extra quotes around the order details make your terminal treat them as one program argument.
To confirm the order exists, query the order chain for all orders:
chr query --cid 1 list_orders[{details=[{product_id=102, quantity=10}, {product_id=101, quantity=1}], order_id=3}]Then check that the factory chain (ID 2) manufactured the products in the right quantities by running this query:
chr query --cid 3 get_total_manufactured_products[{id=101, quantity=1}, {id=102, quantity=10}]Last, confirm that the delivery chain (ID 1) created a delivery with a status:
chr query --cid 2 list_deliveries[{customer_id=1104, order_id=3, shipping_address="Homestreet 2", shipping_state="DISPATCHED"}]The shipping_state shows CREATED if the chain has not yet processed the second message, and DISPATCHED once it has. If you see CREATED, wait a few seconds and query again. To complete the flow, mark the delivery as DELIVERED with this command:
chr tx --cid 2 accept_delivery 3You have now built your first multi-chain app.