From 20f86e96b27c3e42677ed6cc06cac3152f86a98f Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 17 Nov 2023 15:02:13 +0300 Subject: [PATCH] [#51] policy: Fix tests We don't want to return Null from contract when list is empty because generated policy client cannot parse this. Signed-off-by: Denis Kirillov --- policy/policy_contract.go | 16 ++-------------- tests/policy_test.go | 6 ------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/policy/policy_contract.go b/policy/policy_contract.go index dc1a71f..398468b 100644 --- a/policy/policy_contract.go +++ b/policy/policy_contract.go @@ -68,22 +68,10 @@ func RemoveChainsByPrefix(entity Kind, entityName string, name string) { // ListChains lists all chains for the namespace by prefix. // container may be empty. func ListChains(namespace, container, name string) [][]byte { - ctx := storage.GetReadOnlyContext() - - var result [][]byte - - prefixNs := storageKey(Namespace, namespace, name) - it := storage.Find(ctx, prefixNs, storage.ValuesOnly) - for iterator.Next(it) { - result = append(result, iterator.Value(it).([]byte)) - } + result := ListChainsByPrefix(Namespace, namespace, name) if container != "" { - prefixCnr := storageKey(Container, container, name) - it = storage.Find(ctx, prefixCnr, storage.ValuesOnly) - for iterator.Next(it) { - result = append(result, iterator.Value(it).([]byte)) - } + result = append(result, ListChainsByPrefix(Container, container, name)...) } return result diff --git a/tests/policy_test.go b/tests/policy_test.go index 56a41b8..d484d5a 100644 --- a/tests/policy_test.go +++ b/tests/policy_test.go @@ -89,12 +89,6 @@ func checkChainsByPrefix(t *testing.T, e *neotest.ContractInvoker, kind byte, en func checksChainsOnStack(t *testing.T, s *vm.Stack, expected [][]byte) { require.Equal(t, 1, s.Len()) - if len(expected) == 0 { - _, ok := s.Pop().Item().(stackitem.Null) - require.True(t, ok) - return - } - var actual [][]byte arr := s.Pop().Array() for i := range arr {