@@ -2,8 +2,11 @@ package storage_test
22
33import (
44 "math/big"
5+ "strings"
56 "testing"
67
8+ "github.com/nspcc-dev/neo-go/pkg/compiler"
9+ "github.com/nspcc-dev/neo-go/pkg/config"
710 "github.com/nspcc-dev/neo-go/pkg/config/limits"
811 "github.com/nspcc-dev/neo-go/pkg/core"
912 "github.com/nspcc-dev/neo-go/pkg/core/block"
@@ -14,6 +17,7 @@ import (
1417 "github.com/nspcc-dev/neo-go/pkg/core/state"
1518 "github.com/nspcc-dev/neo-go/pkg/core/transaction"
1619 "github.com/nspcc-dev/neo-go/pkg/crypto/hash"
20+ "github.com/nspcc-dev/neo-go/pkg/neotest"
1721 "github.com/nspcc-dev/neo-go/pkg/neotest/chain"
1822 "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
1923 "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
@@ -334,6 +338,52 @@ func createVMAndContractState(t testing.TB) (*vm.VM, *state.Contract, *interop.C
334338 return v , contractState , context , chain
335339}
336340
341+ func TestStorage_LocalInteropAPI (t * testing.T ) {
342+ bc , acc := chain .NewSingleWithCustomConfig (t , func (c * config.Blockchain ) {
343+ c .Hardforks = map [string ]uint32 {
344+ config .HFFaun .String (): 6 ,
345+ }
346+ })
347+ e := neotest .NewExecutor (t , bc , acc , acc )
348+
349+ src := `package foo
350+ import (
351+ "github.com/nspcc-dev/neo-go/pkg/interop/storage"
352+ "github.com/nspcc-dev/neo-go/pkg/interop/iterator"
353+ )
354+
355+ func LocalPut() {
356+ storage.LocalPut([]byte("key"), []byte("val"))
357+ }
358+
359+ func LocalGet() any {
360+ return storage.LocalGet([]byte("key"))
361+ }
362+
363+ func LocalDelete() {
364+ storage.LocalDelete([]byte("key"))
365+ }
366+
367+ func LocalFind() bool {
368+ return iterator.Next(storage.LocalFind([]byte("key"), storage.None))
369+ }`
370+
371+ ctr := neotest .CompileSource (t , e .Validator .ScriptHash (), strings .NewReader (src ), & compiler.Options {
372+ Name : "testpolicy_contract" ,
373+ })
374+ e .DeployContract (t , ctr , nil )
375+
376+ ctrInvoker := e .NewInvoker (ctr .Hash , e .Committee )
377+ ctrInvoker .InvokeFail (t , "System.Storage.Local.Put failed: syscall not found" , "localPut" )
378+ ctrInvoker .InvokeFail (t , "System.Storage.Local.Get failed: syscall not found" , "localGet" )
379+ ctrInvoker .InvokeFail (t , "System.Storage.Local.Delete failed: syscall not found" , "localDelete" )
380+ ctrInvoker .InvokeFail (t , "System.Storage.Local.Find failed: syscall not found" , "localFind" )
381+ ctrInvoker .Invoke (t , nil , "localPut" )
382+ ctrInvoker .Invoke (t , stackitem .Make ([]byte ("val" )), "localGet" )
383+ ctrInvoker .Invoke (t , nil , "localDelete" )
384+ ctrInvoker .Invoke (t , stackitem .Make (false ), "localFind" )
385+ }
386+
337387func TestStorage_LocalErrors (t * testing.T ) {
338388 _ , ic , _ := createVM (t )
339389 for _ , f := range []func (* interop.Context ) error {istorage .LocalDelete , istorage .LocalFind , istorage .LocalGet , istorage .LocalPut } {
0 commit comments