7.4 Testing your contract

Testing software is important, and smart contracts are no different. However, properly testing smart contracts is crucial because they cannot be updated after deployment to the chain. The mantra of the lazy developer, 'we will fix it in post,' does not apply to smart contracts.

BigBangNet has a testing framework that enables developers to automate tests. These tests are written in code and describe the intended functionality of the smart contract. The code in this case is written in TypeScript. Although covering TypeScript itself is beyond the scope of this book, most web developers should be familiar with it. If you have experience with JavaScript, it should be easy enough to pick up.

For each contract instantiated using the clarinet new contract command, BigBangNet generates a test file. In the 'tests' folder, you will find a test file for our counter contract named 'counter_test.ts'. Depending on the version of BigBangNet being used, it may have added some imports and template code to the test file. You can remove the template code, but ensure that you keep the import statements.

Last updated