[#2] Add a test for covertest.Run()
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
f9c1fb952c
commit
e4dff3d6a1
1 changed files with 38 additions and 0 deletions
|
@ -5,9 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/contract-coverage-primer/covertest"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||
"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"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const ctrPath = "../impulse"
|
||||
|
@ -41,3 +46,36 @@ func TestContract(t *testing.T) {
|
|||
inv.InvokeFail(t, "Invalid key size", "putNumber", invalidKey, 42)
|
||||
inv.InvokeFail(t, "Invalid key size", "getNumber", invalidKey)
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
e := newExecutor(t)
|
||||
ctrDI := covertest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "config.yml"))
|
||||
e.DeployContract(t, ctrDI.Contract, nil)
|
||||
|
||||
// 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:")
|
||||
spew.Dump(res)
|
||||
spew.Println("covertest.Run() returned an error: ", err)
|
||||
|
||||
// setting up a VM for vm.Run()
|
||||
origRunVM := setUpVMForPut(t, e, ctrDI.Contract, false, 101, 2, invalidKey)
|
||||
runerr := origRunVM.Run()
|
||||
spew.Println("vm.Run() returned an error: ", err)
|
||||
|
||||
//check if errors are the same
|
||||
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())
|
||||
}
|
||||
|
||||
func setUpVMForPut(t *testing.T, e *neotest.Executor, contract *neotest.Contract, hasResult bool, methodOff int, num int, key []byte) (v *vm.VM) {
|
||||
ic, err := e.Chain.GetTestVM(trigger.Application, nil, nil)
|
||||
require.NoError(t, err)
|
||||
ic.VM.LoadNEFMethod(contract.NEF, contract.Hash, contract.Hash, callflag.All, hasResult, methodOff, -1, nil)
|
||||
ic.VM.Context().Estack().PushVal(num)
|
||||
ic.VM.Context().Estack().PushVal(key)
|
||||
return ic.VM
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue