core: remove nnsrecords package from native

Use nns from examples instead.
This commit is contained in:
Anna Shaleva 2021-05-17 21:10:09 +03:00
parent c9099fa555
commit 2d20b0fa23
5 changed files with 86 additions and 98 deletions

View file

@ -14,6 +14,7 @@ import (
"testing" "testing"
"time" "time"
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
"github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/internal/testchain"
"github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config"
@ -22,7 +23,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/chaindump" "github.com/nspcc-dev/neo-go/pkg/core/chaindump"
"github.com/nspcc-dev/neo-go/pkg/core/fee" "github.com/nspcc-dev/neo-go/pkg/core/fee"
"github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native"
"github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/storage"
@ -489,7 +489,7 @@ func initBasicChain(t *testing.T, bc *Blockchain) {
require.NoError(t, err) require.NoError(t, err)
checkResult(t, res, stackitem.NewBool(true)) checkResult(t, res, stackitem.NewBool(true))
res, err = invokeContractMethodGeneric(bc, defaultNameServiceSysfee, nsHash, res, err = invokeContractMethodGeneric(bc, defaultNameServiceSysfee, nsHash,
"setRecord", acc0, "neo.com", int64(nnsrecords.A), "1.2.3.4") // block #15 "setRecord", acc0, "neo.com", int64(nns.A), "1.2.3.4") // block #15
require.NoError(t, err) require.NoError(t, err)
checkResult(t, res, stackitem.Null{}) checkResult(t, res, stackitem.Null{})

View file

@ -1,12 +0,0 @@
package nnsrecords
// Type represents name record type.
type Type byte
// Pre-defined record types.
const (
A Type = 1
CNAME Type = 5
TXT Type = 16
AAAA Type = 28
)

View file

@ -3,10 +3,10 @@ package core
import ( import (
"testing" "testing"
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
"github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/internal/testchain"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
@ -66,7 +66,7 @@ func TestExpiration(t *testing.T) {
true, "first.com", acc.Contract.ScriptHash()) true, "first.com", acc.Contract.ScriptHash())
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc,
"setRecord", stackitem.Null{}, "first.com", int64(nnsrecords.TXT), "sometext") "setRecord", stackitem.Null{}, "first.com", int64(nns.TXT), "sometext")
b1 := bc.topBlock.Load().(*block.Block) b1 := bc.topBlock.Load().(*block.Block)
tx, err := prepareContractMethodInvokeGeneric(bc, defaultRegisterSysfee, nsHash, tx, err := prepareContractMethodInvokeGeneric(bc, defaultRegisterSysfee, nsHash,
@ -107,7 +107,7 @@ func TestExpiration(t *testing.T) {
checkResult(t, &aer[0], stackitem.NewBool(false)) checkResult(t, &aer[0], stackitem.NewBool(false))
tx, err = prepareContractMethodInvokeGeneric(bc, defaultNameServiceSysfee, nsHash, tx, err = prepareContractMethodInvokeGeneric(bc, defaultNameServiceSysfee, nsHash,
"getRecord", acc, "first.com", int64(nnsrecords.TXT)) "getRecord", acc, "first.com", int64(nns.TXT))
require.NoError(t, err) require.NoError(t, err)
b5 := newBlockCustom(bc.GetConfig(), func(b *block.Block) { b5 := newBlockCustom(bc.GetConfig(), func(b *block.Block) {
b.Index = b4.Index + 1 b.Index = b4.Index + 1
@ -180,88 +180,88 @@ func TestSetGetRecord(t *testing.T) {
testNameServiceInvoke(t, bc, nsHash, "addRoot", stackitem.Null{}, "com") testNameServiceInvoke(t, bc, nsHash, "addRoot", stackitem.Null{}, "com")
t.Run("set before register", func(t *testing.T) { t.Run("set before register", func(t *testing.T) {
testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(nnsrecords.TXT), "sometext") testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(nns.TXT), "sometext")
}) })
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, true, "register", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, true, "register",
true, "neo.com", testchain.CommitteeScriptHash()) true, "neo.com", testchain.CommitteeScriptHash())
t.Run("invalid parameters", func(t *testing.T) { t.Run("invalid parameters", func(t *testing.T) {
testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(0xFF), "1.2.3.4") testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(0xFF), "1.2.3.4")
testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(nnsrecords.A), "not.an.ip.address") testNameServiceInvoke(t, bc, nsHash, "setRecord", nil, "neo.com", int64(nns.A), "not.an.ip.address")
}) })
t.Run("invalid witness", func(t *testing.T) { t.Run("invalid witness", func(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", nil, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", nil,
"neo.com", int64(nnsrecords.A), "1.2.3.4") "neo.com", int64(nns.A), "1.2.3.4")
}) })
testNameServiceInvoke(t, bc, nsHash, "getRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.A)) testNameServiceInvoke(t, bc, nsHash, "getRecord", stackitem.Null{}, "neo.com", int64(nns.A))
testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.A), "1.2.3.4") testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nns.A), "1.2.3.4")
testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nnsrecords.A)) testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nns.A))
testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.A), "1.2.3.4") testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nns.A), "1.2.3.4")
testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nnsrecords.A)) testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nns.A))
testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.AAAA), "2002:0000:1f1f:0000:0000:0100:11a0:addf") testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nns.AAAA), "2002:0000:1f1f:0000:0000:0100:11a0:addf")
testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.CNAME), "nspcc.ru") testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nns.CNAME), "nspcc.ru")
testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.TXT), "sometext") testNameServiceInvoke(t, bc, nsHash, "setRecord", stackitem.Null{}, "neo.com", int64(nns.TXT), "sometext")
// Delete record. // Delete record.
t.Run("invalid witness", func(t *testing.T) { t.Run("invalid witness", func(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", nil, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", nil,
"neo.com", int64(nnsrecords.CNAME)) "neo.com", int64(nns.CNAME))
}) })
testNameServiceInvoke(t, bc, nsHash, "getRecord", "nspcc.ru", "neo.com", int64(nnsrecords.CNAME)) testNameServiceInvoke(t, bc, nsHash, "getRecord", "nspcc.ru", "neo.com", int64(nns.CNAME))
testNameServiceInvoke(t, bc, nsHash, "deleteRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.CNAME)) testNameServiceInvoke(t, bc, nsHash, "deleteRecord", stackitem.Null{}, "neo.com", int64(nns.CNAME))
testNameServiceInvoke(t, bc, nsHash, "getRecord", stackitem.Null{}, "neo.com", int64(nnsrecords.CNAME)) testNameServiceInvoke(t, bc, nsHash, "getRecord", stackitem.Null{}, "neo.com", int64(nns.CNAME))
testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nnsrecords.A)) testNameServiceInvoke(t, bc, nsHash, "getRecord", "1.2.3.4", "neo.com", int64(nns.A))
t.Run("SetRecord_compatibility", func(t *testing.T) { t.Run("SetRecord_compatibility", func(t *testing.T) {
// tests are got from the NNS C# implementation and changed accordingly to non-native implementation behaviour // tests are got from the NNS C# implementation and changed accordingly to non-native implementation behaviour
testCases := []struct { testCases := []struct {
Type nnsrecords.Type Type nns.RecordType
Name string Name string
ShouldFail bool ShouldFail bool
}{ }{
{Type: nnsrecords.A, Name: "0.0.0.0", ShouldFail: true}, {Type: nns.A, Name: "0.0.0.0", ShouldFail: true},
{Type: nnsrecords.A, Name: "1.1.0.1"}, {Type: nns.A, Name: "1.1.0.1"},
{Type: nnsrecords.A, Name: "10.10.10.10", ShouldFail: true}, {Type: nns.A, Name: "10.10.10.10", ShouldFail: true},
{Type: nnsrecords.A, Name: "255.255.255.255", ShouldFail: true}, {Type: nns.A, Name: "255.255.255.255", ShouldFail: true},
{Type: nnsrecords.A, Name: "192.168.1.1", ShouldFail: true}, {Type: nns.A, Name: "192.168.1.1", ShouldFail: true},
{Type: nnsrecords.A, Name: "1a", ShouldFail: true}, {Type: nns.A, Name: "1a", ShouldFail: true},
{Type: nnsrecords.A, Name: "256.0.0.0", ShouldFail: true}, {Type: nns.A, Name: "256.0.0.0", ShouldFail: true},
{Type: nnsrecords.A, Name: "01.01.01.01", ShouldFail: true}, {Type: nns.A, Name: "01.01.01.01", ShouldFail: true},
{Type: nnsrecords.A, Name: "00.0.0.0", ShouldFail: true}, {Type: nns.A, Name: "00.0.0.0", ShouldFail: true},
{Type: nnsrecords.A, Name: "0.0.0.-1", ShouldFail: true}, {Type: nns.A, Name: "0.0.0.-1", ShouldFail: true},
{Type: nnsrecords.A, Name: "0.0.0.0.1", ShouldFail: true}, {Type: nns.A, Name: "0.0.0.0.1", ShouldFail: true},
{Type: nnsrecords.A, Name: "11111111.11111111.11111111.11111111", ShouldFail: true}, {Type: nns.A, Name: "11111111.11111111.11111111.11111111", ShouldFail: true},
{Type: nnsrecords.A, Name: "11111111.11111111.11111111.11111111", ShouldFail: true}, {Type: nns.A, Name: "11111111.11111111.11111111.11111111", ShouldFail: true},
{Type: nnsrecords.A, Name: "ff.ff.ff.ff", ShouldFail: true}, {Type: nns.A, Name: "ff.ff.ff.ff", ShouldFail: true},
{Type: nnsrecords.A, Name: "0.0.256", ShouldFail: true}, {Type: nns.A, Name: "0.0.256", ShouldFail: true},
{Type: nnsrecords.A, Name: "0.0.0", ShouldFail: true}, {Type: nns.A, Name: "0.0.0", ShouldFail: true},
{Type: nnsrecords.A, Name: "0.257", ShouldFail: true}, {Type: nns.A, Name: "0.257", ShouldFail: true},
{Type: nnsrecords.A, Name: "1.1", ShouldFail: true}, {Type: nns.A, Name: "1.1", ShouldFail: true},
{Type: nnsrecords.A, Name: "257", ShouldFail: true}, {Type: nns.A, Name: "257", ShouldFail: true},
{Type: nnsrecords.A, Name: "1", ShouldFail: true}, {Type: nns.A, Name: "1", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "2001:db8::8:800:200c:417a", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:db8::8:800:200c:417a", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "ff01:db8::8:800:200c:417a"}, {Type: nns.AAAA, Name: "ff01:db8::8:800:200c:417a"},
{Type: nnsrecords.AAAA, Name: "ff01::101"}, {Type: nns.AAAA, Name: "ff01::101"},
{Type: nnsrecords.AAAA, Name: "::1"}, {Type: nns.AAAA, Name: "::1"},
{Type: nnsrecords.AAAA, Name: "::"}, {Type: nns.AAAA, Name: "::"},
{Type: nnsrecords.AAAA, Name: "2001:db8:0:0:8:800:200c:417a", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:db8:0:0:8:800:200c:417a", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "ff01:db8:0:0:8:800:200c:417a"}, {Type: nns.AAAA, Name: "ff01:db8:0:0:8:800:200c:417a"},
{Type: nnsrecords.AAAA, Name: "ff01:0:0:0:0:0:0:101"}, {Type: nns.AAAA, Name: "ff01:0:0:0:0:0:0:101"},
{Type: nnsrecords.AAAA, Name: "2001:0:0:0:0:0:0:101", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:0:0:0:0:0:0:101", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "ff01:0:0:0:0:0:0:101"}, {Type: nns.AAAA, Name: "ff01:0:0:0:0:0:0:101"},
{Type: nnsrecords.AAAA, Name: "0:0:0:0:0:0:0:1"}, {Type: nns.AAAA, Name: "0:0:0:0:0:0:0:1"},
{Type: nnsrecords.AAAA, Name: "2001:0:0:0:0:0:0:1", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:0:0:0:0:0:0:1", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "0:0:0:0:0:0:0:0"}, {Type: nns.AAAA, Name: "0:0:0:0:0:0:0:0"},
{Type: nnsrecords.AAAA, Name: "2001:0:0:0:0:0:0:0", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:0:0:0:0:0:0:0", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "2001:DB8::8:800:200C:417A", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:DB8::8:800:200C:417A", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "FF01:DB8::8:800:200C:417A"}, {Type: nns.AAAA, Name: "FF01:DB8::8:800:200C:417A"},
{Type: nnsrecords.AAAA, Name: "FF01::101"}, {Type: nns.AAAA, Name: "FF01::101"},
{Type: nnsrecords.AAAA, Name: "fF01::101"}, {Type: nns.AAAA, Name: "fF01::101"},
{Type: nnsrecords.AAAA, Name: "2001:DB8:0:0:8:800:200C:417A", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:DB8:0:0:8:800:200C:417A", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "FF01:DB8:0:0:8:800:200C:417A"}, {Type: nns.AAAA, Name: "FF01:DB8:0:0:8:800:200C:417A"},
{Type: nnsrecords.AAAA, Name: "FF01:0:0:0:0:0:0:101"}, {Type: nns.AAAA, Name: "FF01:0:0:0:0:0:0:101"},
{Type: nnsrecords.AAAA, Name: "::ffff:1.01.1.01", ShouldFail: true}, {Type: nns.AAAA, Name: "::ffff:1.01.1.01", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "2001:DB8:0:0:8:800:200C:4Z", ShouldFail: true}, {Type: nns.AAAA, Name: "2001:DB8:0:0:8:800:200C:4Z", ShouldFail: true},
{Type: nnsrecords.AAAA, Name: "::13.1.68.3", ShouldFail: true}, {Type: nns.AAAA, Name: "::13.1.68.3", ShouldFail: true},
} }
for _, testCase := range testCases { for _, testCase := range testCases {
var expected interface{} var expected interface{}
@ -302,20 +302,20 @@ func TestSetAdmin(t *testing.T) {
t.Run("set and delete by admin", func(t *testing.T) { t.Run("set and delete by admin", func(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "setRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.TXT), "sometext") "neo.com", int64(nns.TXT), "sometext")
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, guest, "deleteRecord", nil, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, guest, "deleteRecord", nil,
"neo.com", int64(nnsrecords.TXT)) "neo.com", int64(nns.TXT))
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "deleteRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "deleteRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.TXT)) "neo.com", int64(nns.TXT))
}) })
t.Run("set admin to null", func(t *testing.T) { t.Run("set admin to null", func(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "setRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.TXT), "sometext") "neo.com", int64(nns.TXT), "sometext")
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, owner, "setAdmin", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, owner, "setAdmin", stackitem.Null{},
"neo.com", nil) "neo.com", nil)
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "deleteRecord", nil, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, admin, "deleteRecord", nil,
"neo.com", int64(nnsrecords.TXT)) "neo.com", int64(nns.TXT))
}) })
} }
@ -330,7 +330,7 @@ func TestTransfer(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, from, "register", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, from, "register",
true, "neo.com", from.PrivateKey().GetScriptHash()) true, "neo.com", from.PrivateKey().GetScriptHash())
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, from, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, from, "setRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.A), "1.2.3.4") "neo.com", int64(nns.A), "1.2.3.4")
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, from, "transfer", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, from, "transfer",
nil, to.Contract.ScriptHash().BytesBE(), []byte("not.exists"), nil) nil, to.Contract.ScriptHash().BytesBE(), []byte("not.exists"), nil)
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, true, "transfer", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, true, "transfer",
@ -418,23 +418,23 @@ func TestResolve(t *testing.T) {
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, acc, "register", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, acc, "register",
true, "neo.com", acc.PrivateKey().GetScriptHash()) true, "neo.com", acc.PrivateKey().GetScriptHash())
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.A), "1.2.3.4") "neo.com", int64(nns.A), "1.2.3.4")
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{},
"neo.com", int64(nnsrecords.CNAME), "alias.com") "neo.com", int64(nns.CNAME), "alias.com")
testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, acc, "register", testNameServiceInvokeAux(t, bc, nsHash, defaultRegisterSysfee, acc, "register",
true, "alias.com", acc.PrivateKey().GetScriptHash()) true, "alias.com", acc.PrivateKey().GetScriptHash())
testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{}, testNameServiceInvokeAux(t, bc, nsHash, defaultNameServiceSysfee, acc, "setRecord", stackitem.Null{},
"alias.com", int64(nnsrecords.TXT), "sometxt") "alias.com", int64(nns.TXT), "sometxt")
testNameServiceInvoke(t, bc, nsHash, "resolve", "1.2.3.4", testNameServiceInvoke(t, bc, nsHash, "resolve", "1.2.3.4",
"neo.com", int64(nnsrecords.A)) "neo.com", int64(nns.A))
testNameServiceInvoke(t, bc, nsHash, "resolve", "alias.com", testNameServiceInvoke(t, bc, nsHash, "resolve", "alias.com",
"neo.com", int64(nnsrecords.CNAME)) "neo.com", int64(nns.CNAME))
testNameServiceInvoke(t, bc, nsHash, "resolve", "sometxt", testNameServiceInvoke(t, bc, nsHash, "resolve", "sometxt",
"neo.com", int64(nnsrecords.TXT)) "neo.com", int64(nns.TXT))
testNameServiceInvoke(t, bc, nsHash, "resolve", stackitem.Null{}, testNameServiceInvoke(t, bc, nsHash, "resolve", stackitem.Null{},
"neo.com", int64(nnsrecords.AAAA)) "neo.com", int64(nns.AAAA))
} }
const ( const (

View file

@ -6,8 +6,8 @@ import (
"errors" "errors"
"fmt" "fmt"
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
@ -64,8 +64,8 @@ func (c *Client) GetDesignatedByRole(role noderoles.Role, index uint32) (keys.Pu
} }
// NNSResolve invokes `resolve` method on a NameService contract with the specified hash. // NNSResolve invokes `resolve` method on a NameService contract with the specified hash.
func (c *Client) NNSResolve(nnsHash util.Uint160, name string, typ nnsrecords.Type) (string, error) { func (c *Client) NNSResolve(nnsHash util.Uint160, name string, typ nns.RecordType) (string, error) {
if typ == nnsrecords.CNAME { if typ == nns.CNAME {
return "", errors.New("can't resolve CNAME record type") return "", errors.New("can't resolve CNAME record type")
} }
result, err := c.InvokeFunction(nnsHash, "resolve", []smartcontract.Parameter{ result, err := c.InvokeFunction(nnsHash, "resolve", []smartcontract.Parameter{

View file

@ -5,10 +5,10 @@ import (
"encoding/base64" "encoding/base64"
"testing" "testing"
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
"github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/internal/testchain"
"github.com/nspcc-dev/neo-go/pkg/core/fee" "github.com/nspcc-dev/neo-go/pkg/core/fee"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/core/native/nnsrecords"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
@ -864,16 +864,16 @@ func TestClient_NNS(t *testing.T) {
require.Equal(t, true, b) require.Equal(t, true, b)
}) })
t.Run("NNSResolve, good", func(t *testing.T) { t.Run("NNSResolve, good", func(t *testing.T) {
b, err := c.NNSResolve(nsHash, "neo.com", nnsrecords.A) b, err := c.NNSResolve(nsHash, "neo.com", nns.A)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "1.2.3.4", b) require.Equal(t, "1.2.3.4", b)
}) })
t.Run("NNSResolve, bad", func(t *testing.T) { t.Run("NNSResolve, bad", func(t *testing.T) {
_, err := c.NNSResolve(nsHash, "neogo.com", nnsrecords.A) _, err := c.NNSResolve(nsHash, "neogo.com", nns.A)
require.Error(t, err) require.Error(t, err)
}) })
t.Run("NNSResolve, forbidden", func(t *testing.T) { t.Run("NNSResolve, forbidden", func(t *testing.T) {
_, err := c.NNSResolve(nsHash, "neogo.com", nnsrecords.CNAME) _, err := c.NNSResolve(nsHash, "neogo.com", nns.CNAME)
require.Error(t, err) require.Error(t, err)
}) })
} }