Writing and Testing an Ante Test

Writing the Ante Test

  1. 1.
    Fork the Ante Community Repo and use it to develop and write your new Ante Test.
  2. 2.
    Check the contracts folder and see if the protocol in question is already created. If not, create the protocol folder there.
  3. 3.
    Create the Ante Test in its respective folder testing the invariant earlier.
  4. 4.
    Once completed, a good idea is to compile your test and test to 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
If npm isn't installed, please follow npm's installation guide to get it.

Writing an Ante Test's unit test

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. 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. 2.
    Locate the protocol folder for the test in question, if it doesn't exist, create a new one.
  3. 3.
    Tests here are written in Typescript, and labeled as such ante_{test-name}_test.spec.ts. We'll go over the test/examples/ante_eth_dev_rug_test.spec.ts below:
ante_eth_dev_rug_test.spec.ts
import hre from 'hardhat';
const { waffle } = hre;
import { AnteEthDevRugTest__factory, AnteEthDevRugTest } from '../../typechain';li
import { evmSnapshot, evmRevert } from '../helpers';
import { expect } from 'chai';
describe('AnteETHDevRugTest', function () {
let test: AnteEthDevRugTest;
let globalSnapshotId: string;
before(async () => {
globalSnapshotId = await evmSnapshot();
const [deployer] = waffle.provider.getWallets();
const factory = (await hre.ethers.getContractFactory('AnteEthDevRugTest', deployer)) as AnteEthDevRugTest__factory;
test = await factory.deploy('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
await test.deployed();
});
after(async () => {
await evmRevert(globalSnapshotId);
});
it('should pass', async () => {
expect(await test.checkTestPasses()).to.be.true;
});
});
Line 4 - Here you'll want to replace the import with your own {ANTE_TEST}__factory and {ANTE_TEST}
Line 18 - Be sure to get your Ante Test name here with getContractFactory
Line 19 - Any arguments that your Ante Test requires will need to be applied here
Lines 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.

Testing the unit test

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. 1.
    Going back to the main folder of your forked community repo, run the following commands 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.
Copy link
Outline
Writing the Ante Test
Writing an Ante Test's unit test
Testing the unit test