Skip to content

Commit

Permalink
[#139] nns: allow to resolve FQDN
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik committed Oct 26, 2021
1 parent 432c02a commit 4041924
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nns/nns_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions tests/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 4041924

Please sign in to comment.