From 99c81fe26a85a4711d90d7057a1e906f612ca8f9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 17 Nov 2021 17:10:07 +0300 Subject: [PATCH] [#165] nns: disallow duplicating records Signed-off-by: Evgenii Stratonikov --- nns/nns_contract.go | 7 ++++++- tests/nns_test.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nns/nns_contract.go b/nns/nns_contract.go index e87c53d..90815af 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -584,9 +584,14 @@ func addRecord(ctx storage.Context, tokenId []byte, name string, typ RecordType, recordsKey := getRecordsKeyByType(tokenId, name, typ) var id byte - records := storage.Find(ctx, recordsKey, storage.KeysOnly) + records := storage.Find(ctx, recordsKey, storage.ValuesOnly|storage.DeserializeValues) for iterator.Next(records) { id++ + + r := iterator.Value(records).(RecordState) + if r.Name == name && r.Type == typ && r.Data == data { + panic("record already exists") + } } if typ == CNAME && id != 0 { diff --git a/tests/nns_test.go b/tests/nns_test.go index fe3d62f..4bf0846 100644 --- a/tests/nns_test.go +++ b/tests/nns_test.go @@ -95,6 +95,8 @@ func TestNNSRegister(t *testing.T) { cAcc := c.WithSigners(acc) cAcc.Invoke(t, stackitem.Null{}, "addRecord", "testdomain.com", int64(nns.TXT), "first TXT record") + cAcc.InvokeFail(t, "record already exists", "addRecord", + "testdomain.com", int64(nns.TXT), "first TXT record") cAcc.Invoke(t, stackitem.Null{}, "addRecord", "testdomain.com", int64(nns.TXT), "second TXT record")