This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolynym_test.go
148 lines (131 loc) · 4.76 KB
/
polynym_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
package polynym
import (
"fmt"
"net/http"
"testing"
)
// newMockClient will create a new mock client for testing
func newMockClient(userAgent string) Client {
return Client{
httpClient: &mockHTTP{},
UserAgent: userAgent,
}
}
// TestGetAddress tests the GetAddress()
func TestGetAddress(t *testing.T) {
t.Parallel()
// Create a mock client
client := newMockClient(defaultUserAgent)
// Create the list of tests
var tests = []struct {
input string
expected string
expectedError bool
statusCode int
}{
{"", "", true, http.StatusBadRequest},
{"error", "", true, http.StatusBadRequest},
{"bad-poly-response", "", true, http.StatusBadRequest},
{"bad-poly-status", "", true, http.StatusBadRequest},
{"[email protected]", "", true, http.StatusBadRequest},
{"$mr-z", "124dwBFyFtkcNXGfVWQroGcT9ybnpQ3G3Z", false, http.StatusOK},
{"19gKzz8XmFDyrpk4qFobG7qKoqybe78v9h", "19gKzz8XmFDyrpk4qFobG7qKoqybe78v9h", false, http.StatusOK},
{"1doesnotexisthandle", "", true, http.StatusBadRequest},
{"1mrz", "1Lti3s6AQNKTSgxnTyBREMa6XdHLBnPSKa", false, http.StatusOK},
{"[email protected]", "", true, http.StatusBadRequest},
{"c6ZqP5Tb22KJuvSAbjNkoi", "", true, http.StatusBadRequest},
{"[email protected]", "19gKzz8XmFDyrpk4qFobG7qKoqybe78v9h", false, http.StatusOK},
{"@833", "19ksW6ueSw9nEj88X3QNJ9VkKPGf1zuKbQ", false, http.StatusOK},
}
// Test all
for _, test := range tests {
if output, err := GetAddress(client, test.input); err == nil && test.expectedError {
t.Errorf("%s Failed: expected to throw an error, no error [%s] inputted and [%s] expected", t.Name(), test.input, test.expected)
} else if err != nil && !test.expectedError {
t.Errorf("%s Failed: [%s] inputted and [%s] expected, received: [%v] error [%s]", t.Name(), test.input, test.expected, output, err.Error())
} else if output != nil && output.Address != test.expected && !test.expectedError {
t.Errorf("%s Failed: [%s] inputted and [%s] expected, received: [%s]", t.Name(), test.input, test.expected, output.Address)
} else if output != nil && output.LastRequest.Method != http.MethodGet {
t.Errorf("%s Expected method to be %s, got %s, [%s] inputted", t.Name(), http.MethodGet, output.LastRequest.Method, test.input)
} else if output != nil && output.LastRequest.StatusCode != test.statusCode {
t.Errorf("%s Expected status code to be %d, got %d, [%s] inputted", t.Name(), test.statusCode, output.LastRequest.StatusCode, test.input)
}
}
}
// ExampleGetAddress example using GetAddress()
func ExampleGetAddress() {
client := newMockClient(defaultUserAgent)
resp, _ := GetAddress(client, "16ZqP5Tb22KJuvSAbjNkoiZs13mmRmexZA")
fmt.Println(resp.Address)
// Output:16ZqP5Tb22KJuvSAbjNkoiZs13mmRmexZA
}
// TestHandCashConvert will test the HandCashConvert() method
func TestHandCashConvert(t *testing.T) {
t.Parallel()
// Create the list of tests
var tests = []struct {
input string
beta bool
expected string
}{
{"$mr-z", false, "[email protected]"},
{"invalid$mr-z", false, "invalid$mr-z"},
{"$", false, "@handcash.io"},
{"$", true, "@beta.handcash.io"},
{"1handle", false, "1handle"},
{"$misterz", true, "[email protected]"},
}
// Test all
for _, test := range tests {
if output := HandCashConvert(test.input, test.beta); output != test.expected {
t.Errorf("%s Failed: [%s] inputted and [%s] expected, received: [%s]", t.Name(), test.input, test.expected, output)
}
}
}
// ExampleHandCashConvert example using HandCashConvert()
func ExampleHandCashConvert() {
paymail := HandCashConvert("$mr-z", false)
fmt.Println(paymail)
// Output:[email protected]
}
// BenchmarkHandCashConvert benchmarks the HandCashConvert method
func BenchmarkHandCashConvert(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = HandCashConvert("$mr-z", false)
}
}
// TestRelayXConvert will test the RelayXConvert() method
func TestRelayXConvert(t *testing.T) {
t.Parallel()
// Create the list of tests
var tests = []struct {
input string
expected string
}{
{"1mr-z", "[email protected]"},
{"invalid1mr-z", "invalid1mr-z"},
{"1", "@relayx.io"},
{"1mrz", "[email protected]"},
{"1handle", "[email protected]"},
{"1misterz", "[email protected]"},
{"[email protected]", "[email protected]"},
}
// Test all
for _, test := range tests {
if output := RelayXConvert(test.input); output != test.expected {
t.Errorf("%s Failed: [%s] inputted and [%s] expected, received: [%s]", t.Name(), test.input, test.expected, output)
}
}
}
// ExampleHandCashConvert example using RelayXConvert()
func ExampleRelayXConvert() {
paymail := RelayXConvert("1mr-z")
fmt.Println(paymail)
// Output:[email protected]
}
// BenchmarkHandCashConvert benchmarks the RelayXConvert method
func BenchmarkRelayXConvert(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = RelayXConvert("1mr-z")
}
}