[#XX] Added 'Get before Put' test
Also changed GetNumber() to check on nil interface Signed-off-by: Lebedeva Ekaterina <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
0c99f24850
commit
b6cdd15be1
2 changed files with 9 additions and 10 deletions
|
@ -19,13 +19,18 @@ func RuntimeNotify(args []interface{}) {
|
||||||
|
|
||||||
// the answer to the “Great Question” of “Life, the Universe and Everything”
|
// the answer to the “Great Question” of “Life, the Universe and Everything”
|
||||||
func GetNumber() int {
|
func GetNumber() int {
|
||||||
|
|
||||||
|
// var num int
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
// it := storage.Find(ctx, 123, storage.None)
|
// it := storage.Find(ctx, 123, storage.ValuesOnly)
|
||||||
// for iterator.Next(it) {
|
// for iterator.Next(it) {
|
||||||
// num = iterator.Value(it).(int)
|
// num = iterator.Value(it).(int)
|
||||||
// }
|
// }
|
||||||
num := storage.Get(ctx, 123).(int)
|
num := storage.Get(ctx, 123)
|
||||||
return num
|
if num == nil {
|
||||||
|
panic("Cannot get number")
|
||||||
|
}
|
||||||
|
return num.(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PutNumber(num int) {
|
func PutNumber(num int) {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"FirstContract/contract"
|
|
||||||
"fmt"
|
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -14,15 +12,11 @@ import (
|
||||||
const ctrPath = "../contract"
|
const ctrPath = "../contract"
|
||||||
|
|
||||||
func TestContract_GetNumber(t *testing.T) {
|
func TestContract_GetNumber(t *testing.T) {
|
||||||
fmt.Println(contract.GetNumber())
|
|
||||||
|
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
ctrGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
ctrGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
|
||||||
e.DeployContract(t, ctrGetNum, nil)
|
e.DeployContract(t, ctrGetNum, nil)
|
||||||
inv := e.CommitteeInvoker(ctrGetNum.Hash)
|
inv := e.CommitteeInvoker(ctrGetNum.Hash)
|
||||||
//acc := inv.NewAccount(t)
|
inv.InvokeFail(t, "Cannot get number", "getNumber")
|
||||||
inv.Invoke(t, 42, "getNumber")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newExecutor(t *testing.T) *neotest.Executor {
|
func newExecutor(t *testing.T) *neotest.Executor {
|
||||||
|
|
Loading…
Reference in a new issue