Skip to main content

Testing the dapp

We will test the dapp manually by starting the blockchains locally, making a customer order, and then following it through the blockchains.

First, make sure that your chains are configured in the following order in your chromia.yml.

chromia.yml
blockchains:
order-chain: # internal id 0
...
delivery-chain: # internal id 1
...
factory-chain: # internal id 2
...

The Chromia CLI will start the chain in the defined order with an internal ID. It is helpful to know these instead of the referential id (brid) when testing since they are easier to work with.

Let's start testing by starting the node in a separate terminal window.

$ chr node start

We then proceed with the setup by registering two products, with ID 101 and 102

$ chr tx --cid 0 register_product 101 --await
$ chr tx --cid 0 register_product 102 --await

Now we are ready to make our first order. The input argument to make_customer_order is a struct of type order_details. A struct should be encoded as an array when passed through the CLI, so making an order for 1 product of type 101 and 10 products of type 102 sent to a customer with id 1104 on address Homestreet 2 would be encoded as [1104, "Homestreet 2", [[101, 1], [102, 10]]]. Let's make an order using these details to chain 0:

$ chr tx --cid 0 make_customer_order '[1104, "Homestreet 2", [[101, 1], [102, 10]]]' --await

Note the additional quotes around the order details to ensure our terminal parses it as a single program argument.

To verify that our order was created, we can query the order chain for all orders:

$ chr query --cid 0 list_orders
[{details=[{product_id=102, quantity=10}, {product_id=101, quantity=1}], order_id=3}]

Let's also verify that the factory chain, with id 2, has manufactured the products with the correct amount. We perform the following query.

$ chr query --cid 2 get_total_manufactured_products
[{id=101, quantity=1}, {id=102, quantity=10}]

Finally, verifying that the delivery chain, with ID 1, has created a delivery for us and has a status.

$ chr query --cid 1 list_deliveries
[{customer_id=1104, order_id=3, shipping_address="Homestreet 2", shipping_state="DISPATCHED"}]

The shipping_state will be either CREATED or DISPATCHED depending on whether the chain has processed the second message. If it has not, wait a few seconds. For completeness, we can mark the delivery as DELIVERED by calling.

$ chr tx --cid 1 accept_delivery 3

Congratulations! You have now built your first multi-chain app!