Compare commits
2 commits
caa0544ada
...
eea212af58
Author | SHA1 | Date | |
---|---|---|---|
eea212af58 | |||
f4795cfb31 |
4 changed files with 48 additions and 8 deletions
|
@ -38,3 +38,7 @@ func PutNumber(key []byte, num int) {
|
|||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, append([]byte{prefixNumber}, key...), num)
|
||||
}
|
||||
|
||||
func Add(a, b int) int {
|
||||
return a + b
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,11 +1,3 @@
|
|||
name: FirstContract
|
||||
sourceurl: http://example.com/
|
||||
safemethods: []
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: Hello world!
|
||||
parameters:
|
||||
- name: args
|
||||
type: Array
|
||||
permissions:
|
||||
- methods: '*'
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
_ "github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||
"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/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -48,3 +53,42 @@ func TestContract_InvalidKey(t *testing.T) {
|
|||
inv.InvokeFail(t, "Invalid key size", "putNumber", invalidKey, 42)
|
||||
inv.InvokeFail(t, "Invalid key size", "getNumber", invalidKey)
|
||||
}
|
||||
|
||||
func TestContract_Add(t *testing.T) {
|
||||
e := newExecutor(t)
|
||||
ctrAdd := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
||||
e.DeployContract(t, ctrAdd, nil)
|
||||
inv := e.CommitteeInvoker(ctrAdd.Hash)
|
||||
inv.Invoke(t, 3, "add", 1, 2)
|
||||
|
||||
govm := vm.New()
|
||||
govm.LoadNEFMethod(ctrAdd.NEF, ctrAdd.Hash, ctrAdd.Hash, callflag.All, true, 170, -1, nil)
|
||||
govm.Context().Estack().PushVal(1)
|
||||
govm.Context().Estack().PushVal(2)
|
||||
|
||||
fmt.Println("\nPrinting opcodes:")
|
||||
for !govm.HasStopped() {
|
||||
nStr, curInstr := govm.Context().NextInstr()
|
||||
fmt.Println(nStr, " ", curInstr)
|
||||
govm.Step()
|
||||
}
|
||||
|
||||
res := govm.Estack().Pop().Value()
|
||||
fmt.Println("\nresult = ", res)
|
||||
}
|
||||
|
||||
func Test(t *testing.T) {
|
||||
govm := vm.New()
|
||||
err := govm.LoadFileWithFlags(path.Join(ctrPath, "contract.nef"), callflag.All)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "NEF loading failed")
|
||||
t.FailNow()
|
||||
}
|
||||
govm.PrintOps(os.Stdout)
|
||||
govm.Context().Jump(170)
|
||||
govm.Context().Estack().PushVal(1)
|
||||
govm.Context().Estack().PushVal(2)
|
||||
govm.Run()
|
||||
res := govm.Estack().Pop().Value()
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue