neo-go/cli/smartcontract/testdata/deploy/main.go
Roman Khimov 1ac60ada19 cli: move tests to subpackages
Refs. #2379, but not completely solves it, one package seriously outweights
others:

?       github.com/nspcc-dev/neo-go/cli [no test files]
ok      github.com/nspcc-dev/neo-go/cli/app     0.036s  coverage: 100.0% of statements
ok      github.com/nspcc-dev/neo-go/cli/cmdargs 0.011s  coverage: 60.8% of statements
ok      github.com/nspcc-dev/neo-go/cli/flags   0.009s  coverage: 97.7% of statements
?       github.com/nspcc-dev/neo-go/cli/input   [no test files]
ok      github.com/nspcc-dev/neo-go/cli/options 0.033s  coverage: 50.0% of statements
?       github.com/nspcc-dev/neo-go/cli/paramcontext    [no test files]
ok      github.com/nspcc-dev/neo-go/cli/query   2.155s  coverage: 45.3% of statements
ok      github.com/nspcc-dev/neo-go/cli/server  1.373s  coverage: 67.8% of statements
ok      github.com/nspcc-dev/neo-go/cli/smartcontract   8.819s  coverage: 94.3% of statements
ok      github.com/nspcc-dev/neo-go/cli/util    0.006s  coverage: 10.9% of statements
?       github.com/nspcc-dev/neo-go/cli/vm      [no test files]
ok      github.com/nspcc-dev/neo-go/cli/wallet  72.103s coverage: 88.2% of statements

Still a nice thing to have.
2022-10-06 09:21:26 +03:00

84 lines
2 KiB
Go

package deploy
import (
"github.com/nspcc-dev/neo-go/cli/smartcontract/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(data interface{}, 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)
if data != nil {
arr := data.([]interface{})
for i := 0; i < len(arr)-1; i += 2 {
storage.Put(ctx, arr[i], arr[i+1])
}
}
}
storage.Put(ctx, key, value)
}
// Fail just fails.
func Fail() {
panic("as expected")
}
// CheckSenderWitness checks sender's witness.
func CheckSenderWitness() {
tx := runtime.GetScriptContainer()
if !runtime.CheckWitness(tx.Sender) {
panic("not witnessed")
}
}
// Update updates the contract with a 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 the stored value.
func GetValue() string {
ctx := storage.GetReadOnlyContext()
val1 := storage.Get(ctx, key)
val2 := storage.Get(ctx, sub.Key)
return val1.(string) + "|" + val2.(string)
}
// GetValueWithKey returns the stored value with the specified key.
func GetValueWithKey(key string) string {
ctx := storage.GetReadOnlyContext()
return storage.Get(ctx, key).(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
}