github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/interop/storage/interops_test.go (about)

     1  package storage_test
     2  
     3  import (
     4  	"reflect"
     5  	"runtime"
     6  	"testing"
     7  
     8  	"github.com/nspcc-dev/neo-go/pkg/core/interop"
     9  	"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestUnexpectedNonInterops(t *testing.T) {
    14  	vals := map[string]any{
    15  		"int":    1,
    16  		"bool":   false,
    17  		"string": "smth",
    18  		"array":  []int{1, 2, 3},
    19  	}
    20  
    21  	// All of these functions expect an interop item on the stack.
    22  	funcs := []func(*interop.Context) error{
    23  		storage.ContextAsReadOnly,
    24  		storage.Delete,
    25  		storage.Find,
    26  		storage.Get,
    27  		storage.Put,
    28  	}
    29  	for _, f := range funcs {
    30  		for k, v := range vals {
    31  			fname := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
    32  			t.Run(k+"/"+fname, func(t *testing.T) {
    33  				vm, ic, _ := createVM(t)
    34  				vm.Estack().PushVal(v)
    35  				require.Error(t, f(ic))
    36  			})
    37  		}
    38  	}
    39  }