Testing smart contracts
It’s true that you can test the smart contract manually like you did before by using scripts, but that’s not efficient. It’s better to create unit tests to test your smart contract. It helps you develop smart contracts better. The project that you work on has a tests
folder. You can put unit tests there.
Create a file named test_simple_storage.py
inside the tests
folder and add the following code to it:
import pytest @pytest.fixture def deployer(accounts): return accounts[0] @pytest.fixture def contract(deployer, project): return deployer.deploy(project.SimpleStorage) def test_retrieve(contract): num = contract.retrieve.call() assert num == 0 def test_store(contract, deployer): contract.store(19, sender=deployer) num = contract.retrieve.call() assert num == 19
In this...