[#XX] Fixed problem with TestContract_Add

Panic occurred due to absence of context.
Changed the loop condition, CurrInstr() changed to NextInstr(),
removed an attempt to get context from vm before poppint value
from the estack (also in Test).

Signed-off-by: Lebedeva Ekaterina <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2023-07-24 16:27:39 +03:00
parent f4795cfb31
commit eea212af58

View file

@ -6,7 +6,6 @@ import (
"path"
"testing"
"github.com/davecgh/go-spew/spew"
_ "github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
@ -59,31 +58,23 @@ func TestContract_Add(t *testing.T) {
e := newExecutor(t)
ctrAdd := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
e.DeployContract(t, ctrAdd, nil)
spew.Dump(ctrAdd.Manifest)
inv := e.CommitteeInvoker(ctrAdd.Hash)
inv.Invoke(t, 3, "add", 1, 2)
govm := vm.New()
govm.LoadNEFMethod(ctrAdd.NEF, ctrAdd.Hash, ctrAdd.Hash, callflag.All, true, 170, -1, nil)
govm.Context().Estack().PushVal(1)
govm.Context().Estack().PushVal(3)
//fmt.Println(govm.Context().CurrInstr())
_, curInstr := govm.Context().CurrInstr()
//while curInstr != RET do
for curInstr != 0x40 {
fmt.Println(curInstr)
govm.Context().Estack().PushVal(2)
fmt.Println("\nPrinting opcodes:")
for !govm.HasStopped() {
nStr, curInstr := govm.Context().NextInstr()
fmt.Println(nStr, " ", curInstr)
govm.Step()
_, curInstr = govm.Context().CurrInstr()
}
fmt.Println(govm.Context().CurrInstr())
//govm.DumpEStack()
//govm.Run()
res := govm.Context().Estack().Pop().Value()
fmt.Println(res)
// manif, _ := json.MarshalIndent(ctrAdd.Manifest, "", " ")
// fmt.Println(string(manif))
inv := e.CommitteeInvoker(ctrAdd.Hash)
inv.Invoke(t, 3, "add", 1, 2)
res := govm.Estack().Pop().Value()
fmt.Println("\nresult = ", res)
}
func Test(t *testing.T) {
@ -94,13 +85,10 @@ func Test(t *testing.T) {
t.FailNow()
}
govm.PrintOps(os.Stdout)
//step in a loop for debug
//
govm.Context().Jump(170)
govm.Context().Estack().PushVal(1)
govm.Context().Estack().PushVal(2)
govm.Run()
res := govm.Context().Estack().Pop().Value()
res := govm.Estack().Pop().Value()
fmt.Println(res)
}