[#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:
Ekaterina Lebedeva 2023-07-17 18:57:48 +03:00
parent 0c99f24850
commit b6cdd15be1
2 changed files with 9 additions and 10 deletions

View file

@ -19,13 +19,18 @@ func RuntimeNotify(args []interface{}) {
// the answer to the “Great Question” of “Life, the Universe and Everything”
func GetNumber() int {
// var num int
ctx := storage.GetContext()
// it := storage.Find(ctx, 123, storage.None)
// it := storage.Find(ctx, 123, storage.ValuesOnly)
// for iterator.Next(it) {
// num = iterator.Value(it).(int)
// }
num := storage.Get(ctx, 123).(int)
return num
num := storage.Get(ctx, 123)
if num == nil {
panic("Cannot get number")
}
return num.(int)
}
func PutNumber(num int) {

View file

@ -1,8 +1,6 @@
package tests
import (
"FirstContract/contract"
"fmt"
"path"
"testing"
@ -14,15 +12,11 @@ import (
const ctrPath = "../contract"
func TestContract_GetNumber(t *testing.T) {
fmt.Println(contract.GetNumber())
e := newExecutor(t)
ctrGetNum := neotest.CompileFile(t, e.CommitteeHash, ctrPath, path.Join(ctrPath, "neo-go.yml"))
e.DeployContract(t, ctrGetNum, nil)
inv := e.CommitteeInvoker(ctrGetNum.Hash)
//acc := inv.NewAccount(t)
inv.Invoke(t, 42, "getNumber")
inv.InvokeFail(t, "Cannot get number", "getNumber")
}
func newExecutor(t *testing.T) *neotest.Executor {