Modify Autogenerated Tests
Learn how to modify autogenerated tests in Go.
The autogenerated tests will help us making sure, that our precompile throw an error in case not enough gas is supplied. To start, go to calculator/contract_test.go, where you will see the following:
There is a lot to digest in contract_test.go
, but the file can be divided into the following three sections:
- Unit Tests
- TestCalculatorEmptyRun
- BenchmarkCalculator
The autogenerated unit tests are stored in the variable var, which is a mapping from strings (the description of the tests cases) to individual unit tests (testutils.PrecompileTest
). Upon inspecting the keys of each pair, you will see that all three autogenerated unit tests are checking the same thing that: add
, nextTwo
, and repeat
fail if not enough gas is provided. Each test expects to fail when supplying too little gas:
As of currently, if you attempt to build and run the test cases, you will not get very far because there is one step we need to do to: pass in arguments for each autogenerated unit test. For each variable testInput defined in each unit test, add an argument. What argument to put down does not matter, it just needs to be a valid argument. An example of what arguments to put in can be found below:
Now run the test by running the following command from the project root: