Skip to content

Commit

Permalink
nns: Return empty Array from resolve instead of Null
Browse files Browse the repository at this point in the history
In case if no records of the specified type found.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva authored and roman-khimov committed Nov 12, 2024
1 parent 36e7d07 commit f2aaa4a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/nns/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func Resolve(name string, typ recordtype.Type) []string {
}

ctx := storage.GetReadOnlyContext()
return resolve(ctx, nil, name, typ, 2)
return resolve(ctx, []string{}, name, typ, 2)
}

// GetAllRecords returns an Iterator with RecordState items for the given name.
Expand Down
2 changes: 1 addition & 1 deletion tests/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestContainerPut(t *testing.T) {
})

c.Invoke(t, stackitem.Null{}, "delete", cnt.id[:], cnt.sig, cnt.token)
cNNS.Invoke(t, stackitem.Null{}, "resolve", "mycnt."+containerDomain, int64(recordtype.TXT))
cNNS.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "mycnt."+containerDomain, int64(recordtype.TXT))

t.Run("register in advance", func(t *testing.T) {
cnt.value[len(cnt.value)-1]++
Expand Down
3 changes: 3 additions & 0 deletions tests/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ func TestNNSResolve(t *testing.T) {
c.Invoke(t, records, "resolve", "test.com.", int64(recordtype.TXT))
c.InvokeFail(t, "invalid domain fragment", "resolve", "test.com..", int64(recordtype.TXT))

// Empty result.
c.Invoke(t, stackitem.NewArray([]stackitem.Item{}), "resolve", "test.com", int64(recordtype.AAAA))

// Check CNAME is properly resolved and is not included into the result list.
c.Invoke(t, stackitem.NewArray([]stackitem.Item{stackitem.Make("1.2.3.4"), stackitem.Make("5.6.7.8")}), "resolve", "test.com", int64(recordtype.A))
// And this time it should be properly included without resolution.
Expand Down

0 comments on commit f2aaa4a

Please sign in to comment.