-
Notifications
You must be signed in to change notification settings - Fork 0
/
rns_test.go
85 lines (64 loc) · 2.96 KB
/
rns_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
package rnsgo
import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
const (
TestRNSName Name = "wehmoen.ron"
TestRoninAddress Address = "ronin:3759468f9fd589665c8affbe52414ef77f863f72"
TestEthAddress Address = "0x3759468f9fd589665c8affbe52414ef77f863f72"
)
// TestNewClient function tests the NewClient function with a real API call
func TestNewClient(t *testing.T) {
client := NewClient()
// You can add tests here to ensure that the client is correctly configured
assert.NotNil(t, client, "Client should not be nil")
}
// TestGetAddress function tests the GetAddress method with a real API call
func TestGetAddress(t *testing.T) {
client := NewClient()
address, err := client.GetAddress(TestRNSName)
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, address, "Address should not be empty")
assert.Equal(t, strings.ToLower(TestEthAddress.String()), strings.ToLower(address.String()), "Address should be equal to the expected value")
}
// TestGetName function tests the GetName method with a real API call
func TestGetNameInvalidPrefix(t *testing.T) {
client := NewClient()
_, err := client.GetName(TestRoninAddress)
assert.NotNil(t, err, "Error should not! be nil")
}
// TestGetName function tests the GetName method with a real API call
func TestAddress_Normalize(t *testing.T) {
assert.Equal(t, TestEthAddress, TestRoninAddress.Normalize(), "Address should be equal to the expected value")
}
// TestGetName function tests the GetName method with a real API call
func TestAddress_Valid(t *testing.T) {
assert.False(t, TestRoninAddress.Valid(), "Address should not be valid")
assert.True(t, TestEthAddress.Valid(), "Address should be valid")
}
// TestGetName function tests the GetName method with a real API call
func TestGetName(t *testing.T) {
client := NewClient()
name, err := client.GetName(TestEthAddress)
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, name, "Name should not be empty")
assert.Equal(t, strings.ToLower(TestRNSName.String()), strings.ToLower(name.String()), "Name should be equal to the expected value")
}
func TestRNS_GetNameBatch(t *testing.T) {
client := NewClient()
names, err := client.GetNameBatch([]Address{TestEthAddress})
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, names, "Names should not be empty")
assert.Len(t, names, 1, "Names should have a length of 1")
assert.Equal(t, strings.ToLower(TestRNSName.String()), strings.ToLower(names[TestEthAddress].String()), "Name should be equal to the expected value")
}
func TestRNS_GetAddressBatch(t *testing.T) {
client := NewClient()
addresses, err := client.GetAddressBatch([]Name{TestRNSName})
assert.Nil(t, err, "Error should be nil")
assert.NotEmpty(t, addresses, "Addresses should not be empty")
assert.Len(t, addresses, 1, "Addresses should have a length of 1")
assert.Equal(t, strings.ToLower(TestEthAddress.String()), strings.ToLower(addresses[TestRNSName].String()), "Address should be equal to the expected value")
}