From 694daebb1928ffc4eb54e314933dfafe121dad93 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 3 Apr 2024 16:52:05 +0300 Subject: [PATCH] [#84] policy: Fix IteratorChainsByPrefix method * If numeric mapping does not exists, then assign id to 0. * Add check to unit-test. Signed-off-by: Airat Arifullin --- policy/policy_contract.go | 2 +- tests/policy_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/policy/policy_contract.go b/policy/policy_contract.go index 1e5b7bd..dd5876b 100644 --- a/policy/policy_contract.go +++ b/policy/policy_contract.go @@ -115,7 +115,7 @@ func mapToNumeric(ctx storage.Context, kind Kind, name []byte) (mapped int, mapp mKey := mapKey(kind, name) numericID := storage.Get(ctx, mKey) if numericID == nil { - return + return 0, false } mapped = numericID.(int) mappingExists = true diff --git a/tests/policy_test.go b/tests/policy_test.go index 781a308..6690a1a 100644 --- a/tests/policy_test.go +++ b/tests/policy_test.go @@ -32,6 +32,9 @@ func newPolicyInvoker(t *testing.T) *neotest.ContractInvoker { func TestPolicy(t *testing.T) { e := newPolicyInvoker(t) + checkChainsIteratorByPrefix(t, e, policy.Namespace, "mynamespace", "ingress", [][]byte{}) + checkChainsIteratorByPrefix(t, e, policy.Container, "cnr1", "ingress", [][]byte{}) + // Policies are opaque to the contract and are just raw bytes to store. p1 := []byte("chain1") p2 := []byte("chain2")