logoAcademy

Testing Precompiles via Go

Learn how to test your Precompiles using Golang.

Program testing can be used to show the presence of bugs, but never to show their absence. - Edsger W. Dijkstra

Let's once again examine the functions of the Calculator precompile and what each one does (in layman terms):

  • add: computes the sum of two numbers
  • nextTwo: returns the next two numbers that come after the input given
  • repeat: repeats a string N number of times

While we spent a good amount of time in the previous sections examining Calculator Solidity interface and the Go logic, we forgot to do one thing: test the functionality of Calculator.

But why test? For some, it may seems pointless to test such basic functions. However, testing all functions is important because it helps validate our belief that the logic of our functions is what we intended them to be.

In this section, we will focus on utilizing three types of tests for our Calculator precompile:

  1. Autogenerated Tests
  2. Unit Tests
  3. Fuzz Tests
Updated:

On this page

No Headings
Edit on Github