Writing the unit test of the voting smart contract
To make sure the smart contract works well, you need to confirm it with unit tests. The way you write the unit test is similar to what you did in the previous chapter.
First, create the conftest.py
file inside the tests
folder, then 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.VotingApp)
This file contains the initial setup and configuration required for your test file to run properly. The deployer
function returns the deployer, which uses the first test account. The contract
function is used to deploy the voting smart contract.
Next, let’s create the test_voting_app.py
file inside the tests
folder and add the following code to it:
import pytest from ape.exceptions import ContractLogicError def test_chairperson(contract, deployer...