From 8c8e4a6d859cc3cb44584d3468f5214154f9d57d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 21 Oct 2021 18:59:59 +0300 Subject: [PATCH] [#156] container: fix domain owner check Container contract owns all registered domains. Signed-off-by: Evgenii Stratonikov --- container/container_contract.go | 4 ++-- tests/container_test.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/container/container_contract.go b/container/container_contract.go index f477fe7..03799ee 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -272,8 +272,8 @@ func checkNiceNameAvailable(nnsContractAddr interop.Hash160, domain string) bool owner := contract.Call(nnsContractAddr, "ownerOf", contract.ReadStates|contract.AllowCall, domain).(string) - if string(owner) != string(common.CommitteeAddress()) { - panic("committee must own registered domain") + if owner != string(common.CommitteeAddress()) && owner != string(runtime.GetExecutingScriptHash()) { + panic("committee or container contract must own registered domain") } res := contract.Call(nnsContractAddr, "getRecords", diff --git a/tests/container_test.go b/tests/container_test.go index 605a8d9..f0c3e37 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -117,6 +117,12 @@ func TestContainerPut(t *testing.T) { stackitem.NewByteArray([]byte(base58.Encode(c.id[:]))), })) + t.Run("name is already taken", func(t *testing.T) { + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "putNamed", putArgs...) + AddBlock(t, bc, tx) + CheckFault(t, bc, tx.Hash(), "name is already taken") + }) + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "delete", c.id[:], c.sig, c.token) AddBlockCheckHalt(t, bc, tx) @@ -136,7 +142,7 @@ func TestContainerPut(t *testing.T) { tx = PrepareInvoke(t, bc, acc, h, "putNamed", c.value, c.sig, c.pub, c.token, "baddomain", "neofs") AddBlock(t, bc, tx) - CheckFault(t, bc, tx.Hash(), "committee must own registered domain") + CheckFault(t, bc, tx.Hash(), "committee or container contract must own registered domain") }) tx = PrepareInvoke(t, bc, CommitteeAcc, nnsHash, "register",