From b6cdd15be1ef6e13287c1d5f24cb4c1f30d4fdf7 Mon Sep 17 00:00:00 2001 From: Lebedeva Ekaterina Date: Mon, 17 Jul 2023 18:57:48 +0300 Subject: [PATCH] [#XX] Added 'Get before Put' test Also changed GetNumber() to check on nil interface Signed-off-by: Lebedeva Ekaterina --- FirstContract/contract/contract.go | 11 ++++++++--- FirstContract/tests/contract_test.go | 8 +------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/FirstContract/contract/contract.go b/FirstContract/contract/contract.go index 82c667f..84ab508 100644 --- a/FirstContract/contract/contract.go +++ b/FirstContract/contract/contract.go @@ -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) { diff --git a/FirstContract/tests/contract_test.go b/FirstContract/tests/contract_test.go index 971bf07..69d4ba4 100644 --- a/FirstContract/tests/contract_test.go +++ b/FirstContract/tests/contract_test.go @@ -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 {