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")