[#139] nns: allow to resolve FQDN

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-10-16 12:47:52 +03:00 committed by Alex Vanin
parent 05d372e882
commit 63673a5e54
2 changed files with 37 additions and 0 deletions

View file

@ -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) {

View file

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