[#1] Add simple test for example contract
Tests added: invalid key test, valid key test and get-without-put test. neo-go v0.101.3 is a dependency now. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
93d1cbf208
commit
72578fc4be
3 changed files with 648 additions and 1 deletions
|
@ -1 +1,41 @@
|
|||
package contract
|
||||
|
||||
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 = "../impulse"
|
||||
|
||||
// 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(t *testing.T) {
|
||||
e := newExecutor(t)
|
||||
ctr := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "config.yml"))
|
||||
e.DeployContract(t, ctr, nil)
|
||||
inv := e.CommitteeInvoker(ctr.Hash)
|
||||
|
||||
// test get without put
|
||||
inv.InvokeFail(t, "Cannot get number", "getNumber", validKey)
|
||||
|
||||
// test put-get with valid key
|
||||
inv.Invoke(t, stackitem.Null{}, "putNumber", validKey, 42)
|
||||
inv.Invoke(t, 42, "getNumber", validKey)
|
||||
|
||||
// test invalid key
|
||||
inv.InvokeFail(t, "Invalid key size", "putNumber", invalidKey, 42)
|
||||
inv.InvokeFail(t, "Invalid key size", "getNumber", invalidKey)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue