From 4041924a75a7d292b2e42b83f5795d7cb961bcba Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Sat, 16 Oct 2021 12:47:52 +0300 Subject: [PATCH] [#139] nns: allow to resolve FQDN Signed-off-by: Evgenii Stratonikov --- nns/nns_contract.go | 6 ++++++ tests/nns_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/nns/nns_contract.go b/nns/nns_contract.go index 7a672884..9811eb8e 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -864,6 +864,12 @@ func resolve(ctx storage.Context, res []string, name string, typ RecordType, red if redirect < 0 { panic("invalid redirect") } + if len(name) == 0 { + panic("invalid name") + } + if name[len(name)-1] == '.' { + name = name[:len(name)-1] + } records := getAllRecords(ctx, name) cname := "" for iterator.Next(records) { diff --git a/tests/nns_test.go b/tests/nns_test.go index ecbf45d5..7c699b75 100644 --- a/tests/nns_test.go +++ b/tests/nns_test.go @@ -315,3 +315,34 @@ func TestNNSRenew(t *testing.T) { {stackitem.Make("expiration"), stackitem.Make(b.Timestamp + 2*uint64(msPerYear))}, })) } + +func TestNNSResolve(t *testing.T) { + bc := NewChain(t) + h := DeployContract(t, bc, nnsPath, nil) + + refresh, retry, expire, ttl := int64(101), int64(102), int64(103), int64(104) + tx := PrepareInvoke(t, bc, CommitteeAcc, h, "register", + "com", CommitteeAcc.Contract.ScriptHash(), + "myemail@nspcc.ru", refresh, retry, expire, ttl) + AddBlockCheckHalt(t, bc, tx) + + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "register", + "test.com", CommitteeAcc.Contract.ScriptHash(), + "myemail@nspcc.ru", refresh, retry, expire, ttl) + AddBlockCheckHalt(t, bc, tx) + + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "addRecord", + "test.com", int64(nns.TXT), "expected result") + AddBlockCheckHalt(t, bc, tx) + + records := stackitem.NewArray([]stackitem.Item{stackitem.Make("expected result")}) + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "resolve", "test.com", int64(nns.TXT)) + CheckTestInvoke(t, bc, tx, records) + + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "resolve", "test.com.", int64(nns.TXT)) + CheckTestInvoke(t, bc, tx, records) + + tx = PrepareInvoke(t, bc, CommitteeAcc, h, "resolve", "test.com..", int64(nns.TXT)) + AddBlock(t, bc, tx) + CheckFault(t, bc, tx.Hash(), "invalid domain name format") +}