Testing Your Contracts¶
Testing your contracts with SolidByte is pretty straight forward. SolidByte uses pytest as a test runner and provides some useful fixtures to help ease testing.
contracts fixture is an
attrdict.AttrDict instance with all of your
deployed contracts as
This is the initialized instance of
web3.Web3 that should already be
connected to whatever network you gave on the CLI.
list of addresses of the known local accounts.
Function to update a transaction dict with standard values.
Function to check if a receipt contains an event.
Function to pull the event data from a receipt.
Here’s an example test provided with the
def test_erc20(web3, contracts): print("contracts: ", contracts) """ We're just going to test to make sure the contracts fixture is being populated with deployed contract instances """ assert 'MyERC20' in contracts, "Contract not deployed" assert hasattr(contracts.MyERC20, 'address') assert type(contracts.MyERC20.address) == str assert len(contracts.MyERC20.address) == 42 assert contracts.MyERC20.address[:2] == '0x' assert len(web3.eth.accounts) > 0 admin = web3.eth.accounts # Deployed version should have no tokens to start assert contracts.MyERC20.functions.balanceOf(admin).call() == 0 assert contracts.MyERC20.functions.totalSupply().call() > 0