forked from jon4hz/go-1inch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo1inch_test.go
217 lines (194 loc) · 4.94 KB
/
go1inch_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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package go1inch_test
import (
"context"
"testing"
go1inch "github.com/jon4hz/go-1inch"
)
func TestHealthCheckReponse(t *testing.T) {
client := go1inch.NewClient()
networks := []go1inch.Network{go1inch.Eth, go1inch.Bsc, go1inch.Matic, go1inch.Optimism, go1inch.Arbitrum}
for _, network := range networks {
res, _, err := client.Healthcheck(context.Background(), network)
if err != nil {
t.Error(err)
}
if res.Status != "OK" {
t.Errorf("healthcheck returned %s, expected OK", res.Status)
}
t.Logf("Network healthcheck %s: %v", network, res)
}
}
func TestQuoteWithoutOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.Quote(context.Background(), 1,
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"0x6b175474e89094c44da98b954eedeac495271d0f",
"100000000000000000000",
nil,
)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestQuoteWithOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.Quote(context.Background(), 1,
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0x111111111117dc0aa78b770fa6a738034120c302",
"100000000000000000000",
&go1inch.QuoteOpts{
Fee: "1",
GasPrice: "1",
ComplexityLevel: "2",
GasLimit: "10000000",
VirtualParts: "50",
Parts: "50",
MainRouteParts: "10",
},
)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestQuoteWithMissingParameter(t *testing.T) {
client := go1inch.NewClient()
_, _, err := client.Quote(context.Background(), 1,
"",
"0x6b175474e89094c44da98b954eedeac495271d0f",
"100000000000000000000",
nil,
)
if err == nil {
t.Error("getting swap should have failed. fromTokenAddress is missing.")
}
}
func TestSwapWithoutOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.Swap(context.Background(), 1,
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"0x6b175474e89094c44da98b954eedeac495271d0f",
"100000000000000",
"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
1,
nil,
)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestSwapWithOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.Swap(context.Background(), 1,
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0x111111111117dc0aa78b770fa6a738034120c302",
"100000000000000000000",
"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
1,
&go1inch.SwapOpts{
DestReceiver: "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
ReferrerAddress: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
Fee: "1",
GasPrice: "1",
BurnChi: false,
ComplexityLevel: "2",
AllowPartialFill: true,
DisableEstimate: true,
GasLimit: "10000000",
Parts: "50",
VirtualParts: "50",
MainRouteParts: "10",
})
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestSwapWithMissingParameter(t *testing.T) {
client := go1inch.NewClient()
_, _, err := client.Swap(context.Background(), 1,
"",
"0x6b175474e89094c44da98b954eedeac495271d0f",
"100000000000000000000",
"",
0,
nil,
)
if err == nil {
t.Error("getting swap should have failed. fromTokenAddress is missing.")
}
}
func TestGetLiquiditySouces(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.LiquiditySouces(context.Background(), 137)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestGetTokens(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.Tokens(context.Background(), 137)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestApproveSpender(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.ApproveSpender(context.Background(), 56)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestApproveAllowance(t *testing.T) {
const TOKEN_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" // WBNB
const WALLET_ADDRESS = "0xC49926C4124cEe1cbA0Ea94Ea31a6c12318df947" // Wallet that has Router V4 approved for WBNB
client := go1inch.NewClient()
res, _, err := client.ApproveAllowance(context.Background(), 56, TOKEN_ADDRESS, WALLET_ADDRESS)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestApproveTransactionWithoutOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.ApproveTransaction(
context.Background(),
1,
"0x6b175474e89094c44da98b954eedeac495271d0f",
nil,
)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestApproveTransactionWithOpts(t *testing.T) {
client := go1inch.NewClient()
res, _, err := client.ApproveTransaction(
context.Background(),
1,
"0x6b175474e89094c44da98b954eedeac495271d0f",
&go1inch.ApproveTransactionOpts{
Amount: "100000",
},
)
if err != nil {
t.Error(err)
}
t.Log(res)
}
func TestWBTC(t *testing.T) {
client := go1inch.NewClient()
_, code, err := client.Quote(context.Background(), 137, "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6", "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", "100000000", nil)
if err != nil {
t.Error(err)
}
if code != 200 {
t.Error("expected 200, got ", code)
}
}