simple-contract/FirstContract/tests/contract_test.go
Lebedeva Ekaterina caa0544ada [#XX] Added 'key rules' and key test
Removed unnecessary 'Hello world' contracts
Added required key size and prefix
Modified Put and Get contracts so that they take a key as a parameter
Added test for invalid key case
Modified existing tests

Signed-off-by: Lebedeva Ekaterina <ekaterina.lebedeva@yadro.com>
2023-07-18 13:10:32 +03:00

50 lines
1.5 KiB
Go

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)
}