Writing and Testing an Ante Test
Writing the Ante Test
Fork the Ante Community Repo and use it to develop and write your new Ante Test.
Check the
contracts
folder and see if the protocol in question is already created. If not, create theprotocol
folder there.Create the Ante Test in its respective folder testing the invariant earlier.
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.
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.
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.Locate the protocol folder for the test in question, if it doesn't exist, create a new one.
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:
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)
Going back to the main folder of your forked community repo, run the following commands to run through the unit tests.
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 updated