-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_eth_balance_test.go
123 lines (91 loc) · 2.96 KB
/
handler_eth_balance_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
// nolint: goconst
package main
import (
"net/http"
"testing"
"time"
"alluvial/test"
)
func TestHandler_EthBalance_WhenValidAddress(t *testing.T) {
tr := test.TransportRecorder(false, false, "handler_ethBalance_when_valid_address")
c := http.Client{
Transport: tr,
Timeout: 3 * time.Second,
}
ts, cleanup := newTestServer(t, &c)
defer cleanup()
resp := &responseEthBalance{}
test.GetJSON(t, ts.URL+"/eth/balance/0xfe3b557e8fb62b89f4916b721be55ceb828dbd73", http.StatusOK, resp)
wantBalance := "14058"
if wantBalance != resp.Balance {
t.Errorf("\nWant: %s\n Got: %s\n", wantBalance, resp.Balance)
}
}
func TestHandler_EthBalance_WhenInvalidAddress(t *testing.T) {
tr := test.TransportRecorder(false, false, "handler_ethBalance_when_invalid_address")
c := http.Client{
Transport: tr,
Timeout: 3 * time.Second,
}
ts, cleanup := newTestServer(t, &c)
defer cleanup()
resp := struct {
Message string `json:"message"`
}{}
test.GetJSON(t, ts.URL+"/eth/balance/0xfe3b557e8fb62b89f4916b721be55ceb828dbd73xx", http.StatusBadRequest, &resp)
wantMessage := "invalid ethereum address"
if wantMessage != resp.Message {
t.Errorf("\nWant: %s\n Got: %s\n", wantMessage, resp.Message)
}
}
func TestHandler_EthBalance_WhenContractAddress(t *testing.T) {
tr := test.TransportRecorder(false, false, "handler_ethBalance_when_contract_Address")
c := http.Client{
Transport: tr,
Timeout: 3 * time.Second,
}
ts, cleanup := newTestServer(t, &c)
defer cleanup()
resp := struct {
Message string `json:"message"`
}{}
test.GetJSON(t, ts.URL+"/eth/balance/0xe41d2489571d322189246dafa5ebde1f4699f498", http.StatusBadRequest, &resp)
wantMessage := "ethereum contract address is not supported"
if wantMessage != resp.Message {
t.Errorf("\nWant: %s\n Got: %s\n", wantMessage, resp.Message)
}
}
func TestHandler_EthBalance_WhenInternalError(t *testing.T) {
tr := test.TransportRecorder(false, false, "handler_ethBalance_when_internal_error")
c := http.Client{
Transport: tr,
Timeout: 3 * time.Second,
}
ts, cleanup := newTestServer(t, &c)
defer cleanup()
resp := struct {
Message string `json:"message"`
}{}
test.GetJSON(t, ts.URL+"/eth/balance/0xe41d2489571d322189246dafa5ebde1f4699f498", http.StatusInternalServerError, &resp)
wantMessage := "Internal Server Error"
if wantMessage != resp.Message {
t.Errorf("\nWant: %s\n Got: %s\n", wantMessage, resp.Message)
}
}
func TestHandler_EthBalance_WhenInvalidJSON(t *testing.T) {
tr := test.TransportRecorder(false, false, "handler_ethBalance_when_invalid_json")
c := http.Client{
Transport: tr,
Timeout: 3 * time.Second,
}
ts, cleanup := newTestServer(t, &c)
defer cleanup()
resp := struct {
Message string `json:"message"`
}{}
test.GetJSON(t, ts.URL+"/eth/balance/0xe41d2489571d322189246dafa5ebde1f4699f498", http.StatusInternalServerError, &resp)
wantMessage := "Internal Server Error"
if wantMessage != resp.Message {
t.Errorf("\nWant: %s\n Got: %s\n", wantMessage, resp.Message)
}
}