## 4 Testing and Validation  
Smart contract validation and testing are performed using Truffle Suite [35] and Ganache [36]. Ganache is used to create a simulated local blockchain network, and Truffle is used to deploy contracts to Ganache and execute automated tests. Two separate test files are used for combining several tests inside them. Figure 11: Sequence diagram for transfer flow. Figure 12: Sequence diagram for return transfer flow. Figure 10: Flow of handling of the sensor data. The flow test file includes 36 tests that test the main functions of the contract, such as deploying the contract, product creation, depositing Ether to the contract, checking for party information, adding parties, transferring products to other parties, setting a product for return, and returning the product to its defined return location. In the Truffle-flavoured Mocha tests [37], individual tests are wrapped in a contract instance, usually \"described\" in the vanilla Mocha framework. Two arrays, one with normal and one with reverse sequences, are defined for later use to prompt logs regarding test steps. Then, smart contract instance is deployed before the hook. The hook is used to ensure the contract is deployed to the network before any tests are run. Deploying the contract consumes 4,518,628 gas, as per Figure 13. As the writing of this paper, the price of Ether is $1500, and the average gas price is six gwei (gwei is the lowest denomination of Ether, which is a one after 18 zeros; that makes one quintillion wei equal 1 Ether) and the gas cost of deployment is 4,518,628. The total transaction fee is calculated with the following formula: units of gas used * (base fee + priority fee), meaning that we paid $40.66 for the contract deployment. Nevertheless, this fiat value could be even lower than $0.1 if another EVM-compatible chain were used for the deployment.  
After deploying the contract, some tests are conducted to verify contract deployment, obtain manufacturer account details, and add Ether to the manufacturer's wallet. As per Figure 14, verifying the contract costs around $0.2 with 26,346 gas, checking account details costs around $0.4, and funding a wallet costs $10 with 1,138,258 gas. For testing, adding a product to the smart contract addProduct() method is used. Product creation costs 194,068 gas, as per Figure 15.  
Then, we add a party for each party and each role in the supply chain, thus creating all participants of the proposed chain by simulating it. By passing an additional from: address parameter to the addParty() functions with the help of truffle, we are able to simulate running this function in different accounts, and each party addition costs an estimated 190,000 gas, as can be seen in Figure 16.  
Figure 14: Flow tests pre-checking test gas fees. Figure 12:0 Contract initiation gas fee. Figure 12:1 Gas fee for AddProduct function. Figure 12:2 Gas fee for AddParty function. After adding parties, the product that was created earlier is transferred between parties from the start to the end to test the transfer functionality. Assertions are made to assess whether the product is successfully conducted between parties. The gas cost for each transfer product function call can be seen in Figure 12:3  
Figure 12:4 Gas cost for product transfer. Figure 12:5 Gas cost for return transfer. Besides flow tests, for determining how a smart contract behaves in unwanted situations or for determining whether it abides by the chain rules that are defined or not, edge case tests are used. In edge case tests, the following situations are tested:  
1. A party trying to change its own role. 2. A party trying to add a party that is not allowed (not directly linked). 3. A party trying to send a product to a party that is not allowed (not directly linked). 4. Another party besides the manufacturer trying to add a product. 5. Checking whether a party with insufficient funds can perform a transfer. 6. An unhealthy product trying to move forward in the chain. 7. A product trying to move further after it arrives at its return checkpoint.