2019-12-23 13:08:58 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
2020-06-18 09:00:51 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
2020-04-07 09:41:12 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
2020-04-08 10:35:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2019-12-23 13:08:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-04-08 10:35:39 +00:00
|
|
|
func testNonInterop(t *testing.T, value interface{}, f func(*interop.Context, *vm.VM) error) {
|
2019-12-23 13:08:58 +00:00
|
|
|
v := vm.New()
|
|
|
|
v.Estack().PushVal(value)
|
2020-01-10 08:47:55 +00:00
|
|
|
chain := newTestChain(t)
|
|
|
|
defer chain.Close()
|
2020-06-18 09:00:51 +00:00
|
|
|
context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet), nil, nil)
|
2019-12-23 13:08:58 +00:00
|
|
|
require.Error(t, f(context, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnexpectedNonInterops(t *testing.T) {
|
|
|
|
vals := map[string]interface{}{
|
|
|
|
"int": 1,
|
|
|
|
"bool": false,
|
|
|
|
"string": "smth",
|
|
|
|
"array": []int{1, 2, 3},
|
|
|
|
}
|
|
|
|
|
|
|
|
// All of these functions expect an interop item on the stack.
|
2020-04-08 10:35:39 +00:00
|
|
|
funcs := []func(*interop.Context, *vm.VM) error{
|
2020-04-08 10:29:15 +00:00
|
|
|
storageContextAsReadOnly,
|
|
|
|
storageDelete,
|
|
|
|
storageFind,
|
|
|
|
storageGet,
|
|
|
|
storagePut,
|
|
|
|
storagePutEx,
|
2019-12-23 13:08:58 +00:00
|
|
|
}
|
|
|
|
for _, f := range funcs {
|
|
|
|
for k, v := range vals {
|
|
|
|
fname := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
|
|
t.Run(k+"/"+fname, func(t *testing.T) {
|
|
|
|
testNonInterop(t, v, f)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|