neoneo-go/cli/testdata/deploy/main.go
Evgeniy Stratonikov 50d515a3e5 cli: add tests for Storage.Find invocations
It returns values of different types we better be sure that
compiler emits correct code.
2021-01-15 21:12:10 +03:00

63 lines
1.5 KiB
Go

package deploy
import (
"github.com/nspcc-dev/neo-go/cli/testdata/deploy/sub"
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
var key = "key"
const mgmtKey = "mgmt"
func _deploy(isUpdate bool) {
var value string
ctx := storage.GetContext()
if isUpdate {
value = "on update"
} else {
value = "on create"
sh := runtime.GetCallingScriptHash()
storage.Put(ctx, mgmtKey, sh)
}
storage.Put(ctx, key, value)
}
// Fail just fails.
func Fail() {
panic("as expected")
}
// Update updates contract with the new one.
func Update(script, manifest []byte) {
ctx := storage.GetReadOnlyContext()
mgmt := storage.Get(ctx, mgmtKey).(interop.Hash160)
contract.Call(mgmt, "update", contract.All, script, manifest)
}
// GetValue returns stored value.
func GetValue() string {
ctx := storage.GetReadOnlyContext()
val1 := storage.Get(ctx, key)
val2 := storage.Get(ctx, sub.Key)
return val1.(string) + "|" + val2.(string)
}
// TestFind finds items with the specified prefix.
func TestFind(f storage.FindFlags) []interface{} {
ctx := storage.GetContext()
storage.Put(ctx, "findkey1", "value1")
storage.Put(ctx, "findkey2", "value2")
var result []interface{}
iter := storage.Find(ctx, "findkey", f)
for iterator.Next(iter) {
result = append(result, iterator.Value(iter))
}
return result
}