-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnamingservice_test.go
177 lines (137 loc) · 5.37 KB
/
namingservice_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package resolution
import (
"reflect"
"testing"
"time"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"github.com/unstoppabledomains/resolution-go/v3/namingservice"
)
func TestEnforceImplementInterface(t *testing.T) {
t.Parallel()
assert.Implements(t, (*NamingService)(nil), &Zns{provider: nil})
assert.Implements(t, (*NamingService)(nil), &Uns{
l1Service: UnsService{},
l2Service: UnsService{},
})
}
func TestDetectNamingServiceType(t *testing.T) {
t.Parallel()
var serviceType string
serviceType, err := DetectNamingService("test.zil")
assert.Nil(t, err)
assert.Equal(t, namingservice.ZNS, serviceType)
serviceType, err = DetectNamingService("test.crypto")
assert.Nil(t, err)
assert.Equal(t, namingservice.UNS, serviceType)
serviceType, err = DetectNamingService("test.asdasdas")
assert.Nil(t, err)
assert.Equal(t, namingservice.UNS, serviceType)
serviceType, err = DetectNamingService("test.wallet")
assert.Nil(t, err)
assert.Equal(t, namingservice.UNS, serviceType)
}
func TestDetectNamingServiceTypeInvalidDomain(t *testing.T) {
t.Parallel()
var expectedError *DomainNotSupportedError
_, err := DetectNamingService("aaaazzsd..")
assert.ErrorAs(t, err, &expectedError)
_, err = DetectNamingService("aaaazzsd")
assert.ErrorAs(t, err, &expectedError)
}
var testWeb3Domains = map[string]DomainData{
"UnsDomain": {Name: "reseller-test-udtesting-459239285.crypto"},
"EnsDomain": {Name: "test.eth"},
}
func getWeb3Domain() *Web3Domain {
builder := NewWeb3DomainBuilder()
builder = builder.SetEthereumNetwork("goerli").SetEthContractBackendProviderUrl(getL1TestProviderUrl())
builder = builder.SetMaticNetwork("mumbai").SetMaticContractBackendProviderUrl(getL2TestProviderUrl())
web3Domain, _ := builder.Build()
return web3Domain
}
func TestWeb3DomainBuilderWithUrl(t *testing.T) {
t.Parallel()
builder := NewWeb3DomainBuilder()
builder = builder.SetEthereumNetwork("goerli").SetEthContractBackendProviderUrl(getL1TestProviderUrl())
builder = builder.SetMaticNetwork("mumbai").SetMaticContractBackendProviderUrl(getL2TestProviderUrl())
web3Domain, _ := builder.Build()
assert.NotNil(t, web3Domain)
}
func TestWeb3DomainBuilderWithContractBackend(t *testing.T) {
builder := NewWeb3DomainBuilder()
ethBackend, _ := ethclient.Dial(getL1TestProviderUrl())
backendL2, _ := ethclient.Dial(getL2TestProviderUrl())
builder = builder.SetEthContractBackend(ethBackend)
builder = builder.SetMaticContractBackend(backendL2)
web3Domain, _ := builder.Build()
assert.NotNil(t, web3Domain)
}
func TestWeb3DomainBuilderWithApiKey(t *testing.T) {
builder := NewWeb3DomainBuilder().SetUdClient("some key")
web3Domain, _ := builder.Build()
assert.NotNil(t, web3Domain)
}
func TestWeb3DomainGetNamingServiceForUnsDomain(t *testing.T) {
t.Parallel()
namingservice := getWeb3Domain().getNamingServiceForDomain(testWeb3Domains["UnsDomain"].Name)
assert.NotNil(t, namingservice)
assert.Equal(t, reflect.TypeOf(namingservice) == reflect.TypeOf(&Uns{}), true)
}
func TestWeb3DomainGetNamingServiceForEnsDomain(t *testing.T) {
t.Parallel()
namingservice := getWeb3Domain().getNamingServiceForDomain(testWeb3Domains["EnsDomain"].Name)
assert.NotNil(t, namingservice)
assert.Equal(t, reflect.TypeOf(namingservice) == reflect.TypeOf(&Ens{}), true)
}
func TestWeb3DomainDomainExpiryForUnsDomain(t *testing.T) {
t.Parallel()
_, err := getWeb3Domain().DomainExpiry(testWeb3Domains["UnsDomain"].Name)
assert.NotNil(t, err)
}
func TestWeb3DomainDomainExpiryForEnsDomain(t *testing.T) {
t.Parallel()
expiry, err := getWeb3Domain().DomainExpiry(testWeb3Domains["EnsDomain"].Name)
assert.Nil(t, err)
assert.Equal(t, expiry.After(time.Now().Add(1)), true) // assuming this domain last for years
}
func TestWeb3DomainNameHashForEthDomain(t *testing.T) {
t.Parallel()
nameHash, _ := getWeb3Domain().Namehash(testWeb3Domains["EnsDomain"].Name)
assert.Equal(t, nameHash, "0xeb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1")
}
func TestWeb3DomainNameHashForEthSubDomain(t *testing.T) {
t.Parallel()
nameHash, _ := getWeb3Domain().Namehash("test1.test.eth")
assert.Equal(t, nameHash, "0x2fae416d6dd9ac2a3d1035f5de2c4ee6905fd34bf1918c7a497cafbc696b20e7")
}
func TestWeb3DomainGetEnsResolver(t *testing.T) {
t.Parallel()
resolver, err := getWeb3Domain().Resolver(testWeb3Domains["EnsDomain"].Name)
assert.Nil(t, err)
assert.Equal(t, resolver, "0x4B1488B7a6B320d2D721406204aBc3eeAa9AD329")
}
func TestWeb3DomainGetEnsOwner(t *testing.T) {
t.Parallel()
owner, err := getWeb3Domain().Owner(testWeb3Domains["EnsDomain"].Name)
assert.Nil(t, err)
assert.Equal(t, owner, "0x145E8aa4ECff3Bdea8d98739105AE038f1f0E352")
}
func TestWeb3DomainGetEnsReverse(t *testing.T) {
t.Parallel()
domain, err := getWeb3Domain().ReverseOf("0x2ba39217d82d0d4b1ff90125909973a8572fb2a4")
assert.Nil(t, err)
assert.Equal(t, domain, "ppi.eth")
}
func TestWeb3DomainGetNoReverseResult(t *testing.T) {
t.Parallel()
domain, err := getWeb3Domain().ReverseOf("0x2ba39217d82d0d4b1ff90125909973a8572fb2a1")
assert.Nil(t, err)
assert.Equal(t, domain, "")
}
func TestWeb3DomainGetEnsTokenUri(t *testing.T) {
t.Parallel()
tokenUri, err := getWeb3Domain().TokenURI(testWeb3Domains["EnsDomain"].Name)
assert.Nil(t, err)
assert.Equal(t, tokenUri, "https://metadata.ens.domains/mainnet/0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85/0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658")
}