nspcc-dev / neo-go

Go Node and SDK for the NEO blockchain
MIT License
120 stars 78 forks source link

Support coverage in neotest #2657

Open fyrchik opened 2 years ago

fyrchik commented 2 years ago

It would be nice to check that contract tests cover all possible branches.

So basically there are 2 parts:

  1. Execute VM, while tracking executed opcodes and mapping them to the source code lines using DebugInfo. It has a lot of runtime overhead, but we can have a separate package which contains all the logic and use it only with certain test flags.
  2. Create custom coverage file.

As a nice consequence, we can use this to check for the presence of dead-code which can be used to optimize the compiler itself.

The most difficult part of this is to figure out clean interface without a lot of overhead.

Another difficulty (optional feature) is to have nice green lines displayed by GoLand, so far this was my biggest issue.

roman-khimov commented 2 years ago

Yeah, that'd be really cool, but I think it can only be done properly at the VM level and it won't be trivial.

fyrchik commented 2 years ago

The thing I had in mind is to leave VM as it is: make custom Execute which executes code step-by-step and updates seen opcodes/lines. The vm.Run is rather simple so it can be copied with minimum changes.

AnnaShaleva commented 1 year ago

We have POC written by @fyrchik in https://github.com/nspcc-dev/neo-go/tree/neotest-coverage, so let's keep this branch linked for now.