core: return *interop.Context from GetTestVM

Return everything needed, fix #2273.
This commit is contained in:
Roman Khimov 2022-01-13 01:20:08 +03:00
parent ab2e60458d
commit 9f9bd7261c
9 changed files with 57 additions and 56 deletions

View file

@ -6,13 +6,13 @@ import (
gio "io"
"github.com/nspcc-dev/neo-go/pkg/core/fee"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/vm"
"go.uber.org/zap"
)
@ -138,24 +138,24 @@ func (o *Oracle) testVerify(tx *transaction.Transaction) (int64, bool) {
// method caches transaction hash, but tx building is not yet completed and hash will be changed.
// So make a copy of tx to avoid wrong hash caching.
cp := *tx
v, finalize := o.Chain.GetTestVM(trigger.Verification, &cp, nil)
v.GasLimit = o.Chain.GetMaxVerificationGAS()
v.LoadScriptWithHash(o.oracleScript, o.oracleHash, callflag.ReadOnly)
v.Context().Jump(o.verifyOffset)
ic := o.Chain.GetTestVM(trigger.Verification, &cp, nil)
ic.VM.GasLimit = o.Chain.GetMaxVerificationGAS()
ic.VM.LoadScriptWithHash(o.oracleScript, o.oracleHash, callflag.ReadOnly)
ic.VM.Context().Jump(o.verifyOffset)
ok := isVerifyOk(v, finalize)
return v.GasConsumed(), ok
ok := isVerifyOk(ic)
return ic.VM.GasConsumed(), ok
}
func isVerifyOk(v *vm.VM, finalize func()) bool {
defer finalize()
if err := v.Run(); err != nil {
func isVerifyOk(ic *interop.Context) bool {
defer ic.Finalize()
if err := ic.VM.Run(); err != nil {
return false
}
if v.Estack().Len() != 1 {
if ic.VM.Estack().Len() != 1 {
return false
}
ok, err := v.Estack().Pop().Item().TryBool()
ok, err := ic.VM.Estack().Pop().Item().TryBool()
return err == nil && ok
}