Comment on page
Writing and Testing an Ante Test
- 1.
- 2.Check the
contracts
folder and see if the protocol in question is already created. If not, create theprotocol
folder there. - 3.Create the Ante Test in its respective protocol folder.
- 4.Once completed, a good idea is to compile your test and make sure it compiles. You can do that using the following commands in a bash terminal.
# Install necessary pacakges determined by the repository, be sure you're
# in the root directory of ante-community-tests
npm install
# This hardhat command compiles all tests in the repository.
npx hardhat compile
Now that the test has been written we should always make sure we test it to the best of our knowledge. Make sure it behaves the way we expect it to. To do that, we go through the following process.
- 1.In the Ante Community Repo that you've forked, there's a
test
folder where we write the unit tests for the Ante Test that was just written. - 2.Locate the protocol folder for the test in question, if it doesn't exist, create a new one.
- 3.Tests here are written in Typescript, and labeled as such
ante_{test-name}_test.spec.ts
. We'll go over thetest/examples/ante_eth_dev_rug_test.spec.ts
below:
ante_eth_dev_rug_test.spec.ts
1
import hre from 'hardhat';
2
const { waffle } = hre;
3
4
import { AnteEthDevRugTest__factory, AnteEthDevRugTest } from '../../typechain';li
5
6
import { evmSnapshot, evmRevert } from '../helpers';
7
import { expect } from 'chai';
8
9
describe('AnteETHDevRugTest', function () {
10
let test: AnteEthDevRugTest;
11
12
let globalSnapshotId: string;
13
14
before(async () => {
15
globalSnapshotId = await evmSnapshot();
16
17
const [deployer] = waffle.provider.getWallets();
18
const factory = (await hre.ethers.getContractFactory('AnteEthDevRugTest', deployer)) as AnteEthDevRugTest__factory;
19
test = await factory.deploy('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
20
await test.deployed();
21
});
22
23
after(async () => {
24
await evmRevert(globalSnapshotId);
25
});
26
27
it('should pass', async () => {
28
expect(await test.checkTestPasses()).to.be.true;
29
});
30
});
31
Line 4 - Here you'll want to replace the import with your own
{ANTE_TEST}__factory
and {ANTE_TEST}
Line 18 - Be sure to replace
AnteEthDevRugTest
with the name of your AnteTest in the getContractFactory()
call.Line 19 - Any arguments that your Ante Test requires will need to be applied here. Anything passed into
deploy()
will go directly into the constructor of your AnteTestLines 27-29 - This is the basic test condition where on deployment with no changes applied yet, the Ante Test should pass.
In order to add more tests (for example, you have conditions that change after a change to an address). Then you'll want to add more
it('description, async() => {conditions})
that test these for you.Once a unit test is written that confirms your expectations, then it's time to test it in the real world (well, forked mainnet world to be specific)
- 1.Going back to the main folder of your forked community repo, run the following command to run through the unit tests.
# This command is a scripted command we added to the community repo in
# order to make the test running easier.
npm test
What
npm test
does is run the hardhat commands npx hardhat typechain
and npx hardhat test
to generate the typings for the tests written and then run the unit tests written in the entire repository.It will then run through all unit tests (the ones in the
test
folder) and test each condition there. And finally, generate a summary of how many unit tests pass or fail.If your unit tests fail here, some key points to check are:
- Ante Test - make sure the invariant you want to test here is correct.
- unit test - make sure that your assumptions that the Ante Test is testing is as you expect.
Last modified 10mo ago