[#XX] Added Put-Get contracts with test
Tried to implement PutNumber and GetNumber funcs based on contracts in frostfsid_contract.go Added just one test for now, it's not failing Signed-off-by: Lebedeva Ekaterina <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
1a4da784a3
commit
0c99f24850
2 changed files with 27 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
package contract
|
||||
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
||||
var notificationName string
|
||||
|
||||
|
@ -16,5 +19,16 @@ func RuntimeNotify(args []interface{}) {
|
|||
|
||||
// the answer to the “Great Question” of “Life, the Universe and Everything”
|
||||
func GetNumber() int {
|
||||
return 42
|
||||
ctx := storage.GetContext()
|
||||
// it := storage.Find(ctx, 123, storage.None)
|
||||
// for iterator.Next(it) {
|
||||
// num = iterator.Value(it).(int)
|
||||
// }
|
||||
num := storage.Get(ctx, 123).(int)
|
||||
return num
|
||||
}
|
||||
|
||||
func PutNumber(num int) {
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, 123, num)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
const ctrPath = "../contract"
|
||||
|
@ -28,3 +29,13 @@ func newExecutor(t *testing.T) *neotest.Executor {
|
|||
bc, acc := chain.NewSingle(t)
|
||||
return neotest.NewExecutor(t, bc, acc, acc)
|
||||
}
|
||||
|
||||
func TestContract_PutNumber(t *testing.T) {
|
||||
e := newExecutor(t)
|
||||
ctrPutGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
||||
e.DeployContract(t, ctrPutGetNum, nil)
|
||||
inv := e.CommitteeInvoker(ctrPutGetNum.Hash)
|
||||
inv.Invoke(t, stackitem.Null{}, "putNumber", 42)
|
||||
|
||||
inv.Invoke(t, 42, "getNumber")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue