package tests import ( "path" "testing" "github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) const ctrPath = "../contract" // Key for tests var ( validKey = []byte{1, 2, 3, 4, 5} invalidKey = []byte{1, 2, 3} ) func newExecutor(t *testing.T) *neotest.Executor { bc, acc := chain.NewSingle(t) return neotest.NewExecutor(t, bc, acc, acc) } func TestContract_GetNumber(t *testing.T) { e := newExecutor(t) ctrGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml")) e.DeployContract(t, ctrGetNum, nil) inv := e.CommitteeInvoker(ctrGetNum.Hash) inv.InvokeFail(t, "Cannot get number", "getNumber", validKey) } func TestContract_PutNumber(t *testing.T) { e := newExecutor(t) ctrPutGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml")) e.DeployContract(t, ctrPutGetNum, nil) inv := e.CommitteeInvoker(ctrPutGetNum.Hash) inv.Invoke(t, stackitem.Null{}, "putNumber", validKey, 42) inv.Invoke(t, 42, "getNumber", validKey) } func TestContract_InvalidKey(t *testing.T) { e := newExecutor(t) ctrPutGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml")) e.DeployContract(t, ctrPutGetNum, nil) inv := e.CommitteeInvoker(ctrPutGetNum.Hash) inv.InvokeFail(t, "Invalid key size", "putNumber", invalidKey, 42) inv.InvokeFail(t, "Invalid key size", "getNumber", invalidKey) }