2019-12-23 14:05:34 +00:00
|
|
|
package compiler_test
|
2018-04-10 09:45:31 +00:00
|
|
|
|
|
|
|
import (
|
2020-04-16 12:28:34 +00:00
|
|
|
"math/big"
|
2018-04-10 09:45:31 +00:00
|
|
|
"testing"
|
2020-04-05 15:05:40 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-04-10 09:45:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoragePutGet(t *testing.T) {
|
|
|
|
src := `
|
|
|
|
package foo
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
2018-04-10 09:45:31 +00:00
|
|
|
|
|
|
|
func Main() string {
|
2018-05-06 06:03:26 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
key := []byte("token")
|
|
|
|
storage.Put(ctx, key, []byte("foo"))
|
2018-04-10 09:45:31 +00:00
|
|
|
x := storage.Get(ctx, key)
|
|
|
|
return x.(string)
|
|
|
|
}
|
|
|
|
`
|
|
|
|
eval(t, src, []byte("foo"))
|
|
|
|
}
|
2020-04-05 15:05:40 +00:00
|
|
|
|
|
|
|
func TestNotify(t *testing.T) {
|
|
|
|
src := `package foo
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
func Main(arg int) {
|
|
|
|
runtime.Notify(arg, "sum", arg+1)
|
|
|
|
runtime.Notify()
|
|
|
|
runtime.Notify("single")
|
|
|
|
}`
|
|
|
|
|
|
|
|
v, s := vmAndCompileInterop(t, src)
|
|
|
|
v.Estack().PushVal(11)
|
|
|
|
|
|
|
|
require.NoError(t, v.Run())
|
|
|
|
require.Equal(t, 3, len(s.events))
|
|
|
|
|
2020-04-16 12:28:34 +00:00
|
|
|
exp0 := []vm.StackItem{vm.NewBigIntegerItem(big.NewInt(11)), vm.NewByteArrayItem([]byte("sum")), vm.NewBigIntegerItem(big.NewInt(12))}
|
2020-04-05 15:05:40 +00:00
|
|
|
assert.Equal(t, exp0, s.events[0].Value())
|
|
|
|
assert.Equal(t, []vm.StackItem{}, s.events[1].Value())
|
|
|
|
assert.Equal(t, []vm.StackItem{vm.NewByteArrayItem([]byte("single"))}, s.events[2].Value())
|
|
|
|
}
|