From 63673a5e54f5716e47ede8d51969c17dccac51c1 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 917dc2a..e87c53d 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -870,6 +870,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 ecbf45d..7c699b7 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") +}