[#84] policy: Fix IteratorChainsByPrefix method
All checks were successful
DCO action / DCO (pull_request) Successful in 1m11s
Tests / Tests (1.20) (pull_request) Successful in 1m24s
Tests / Tests (1.19) (pull_request) Successful in 1m37s

* If numeric mapping does not exists, then assign id to 0.
* Add check to unit-test.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-04-03 16:52:05 +03:00
parent 2574b2840e
commit 694daebb19
2 changed files with 4 additions and 1 deletions

View file

@ -115,7 +115,7 @@ func mapToNumeric(ctx storage.Context, kind Kind, name []byte) (mapped int, mapp
mKey := mapKey(kind, name) mKey := mapKey(kind, name)
numericID := storage.Get(ctx, mKey) numericID := storage.Get(ctx, mKey)
if numericID == nil { if numericID == nil {
return return 0, false
} }
mapped = numericID.(int) mapped = numericID.(int)
mappingExists = true mappingExists = true

View file

@ -32,6 +32,9 @@ func newPolicyInvoker(t *testing.T) *neotest.ContractInvoker {
func TestPolicy(t *testing.T) { func TestPolicy(t *testing.T) {
e := newPolicyInvoker(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. // Policies are opaque to the contract and are just raw bytes to store.
p1 := []byte("chain1") p1 := []byte("chain1")
p2 := []byte("chain2") p2 := []byte("chain2")