Add a custom vm.Run() function #9
No reviewers
Labels
No labels
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/contract-coverage-primer#9
Loading…
Reference in a new issue
No description provided.
Delete branch "elebedeva/contract-coverage-primer:covertest/run"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #2
Adding
covertest.Run()
function which executes loaded program and accumulates all seen opcodes together with the scripthash they belong to.@ -0,0 +9,4 @@
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
)
// InstrHash maps Instruction with its Script Hash.
Instruction doesn't have a script hash, a contract it belongs to does.
Fixed
@ -0,0 +11,4 @@
// InstrHash maps Instruction with its Script Hash.
type InstrHash struct {
Num int
Position
orOffset
would be more descriptive IMO (each opcode has a "number" which isInstruction
here)Fixed
@ -0,0 +18,4 @@
// Run starts execution of the loaded program and accumulates all seen opcodes
// together with the scripthash they belong to.
func Run(v *vm.VM) ([]InstrHash, error) {
Could you give a permalink to the original code of this function in comment?
It would benefit both reviewers and anyone who touches this code in a year.
Fixed
@ -0,0 +19,4 @@
// Run starts execution of the loaded program and accumulates all seen opcodes
// together with the scripthash they belong to.
func Run(v *vm.VM) ([]InstrHash, error) {
First line of the function should not be empty (there is a linter for this, we just don't have it in this repo)
Fixed
@ -44,0 +53,4 @@
e.DeployContract(t, ctrDI.Contract, nil)
// setting up a VM for covertest.Run()
covertestRunVM := setUpVMForPut(t, e, ctrDI.Contract, false, 101, 2, invalidKey)
101
and2
look like magic constants. Can we calculate them somehow?Fixed
@ -44,0 +55,4 @@
// setting up a VM for covertest.Run()
covertestRunVM := setUpVMForPut(t, e, ctrDI.Contract, false, 101, 2, invalidKey)
res, err := covertest.Run(covertestRunVM)
spew.Println("Printing collected instructions:")
We use
spew
for debug-printing big structs. In other cases (tests)t.Log
ort.Logf
might be more appropriate.Fixed
@ -44,0 +64,4 @@
runerr := origRunVM.Run()
spew.Println("vm.Run() returned an error: ", err)
//check if errors are the same
Comment should have a space after
//
(this is not a rule per se, but being uniform is a nice quality for a codebase). See also https://tip.golang.org/doc/commentFixed
@ -44,0 +68,4 @@
spew.Println("Are errors the same? ", runerr.Error() == runerr.Error())
//check if the number of elements on the stack is the same
spew.Println("Is the number of elements on the stack the same? ", origRunVM.Estack().Len() == covertestRunVM.Estack().Len())
For this case you might want to look at https://pkg.go.dev/github.com/stretchr/testify/require package.
We want the test to fail, not just print info.
Example of usage:
require.Equal(t, key, a.Key())
Fixed
@ -44,0 +56,4 @@
e.DeployContract(t, ctrDI.Contract, nil)
startOffsetPutNumber, err := getStartOffset(ctrDI.DebugInfo, "PutNumber")
if err != nil {
require.NoError(t, err)
?Fixed
@ -44,0 +62,4 @@
}
hasResult, err := hasResult(ctrDI.DebugInfo, "PutNumber")
if err != nil {
same here
Fixed
d3b48812bb
to4d48eff4c0
4d48eff4c0
to401d54dda4