forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdraw_test.go
187 lines (171 loc) · 4.7 KB
/
withdraw_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
package engine
import (
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
const (
bankAccountID = "test-bank-01"
)
var (
settings = Settings{
ConfigFile: filepath.Join("..", "testdata", "configtest.json"),
EnableDryRun: true,
DataDir: filepath.Join("..", "testdata", "gocryptotrader"),
Verbose: false,
EnableGRPC: false,
EnableDeprecatedRPC: false,
EnableWebsocketRPC: false,
}
)
func cleanup() {
err := os.RemoveAll(settings.DataDir)
if err != nil {
fmt.Printf("Clean up failed to remove file: %v manual removal may be required", err)
}
}
func TestSubmitWithdrawal(t *testing.T) {
SetupTestHelpers(t)
banking.Accounts = append(banking.Accounts,
banking.Account{
Enabled: true,
ID: "test-bank-01",
BankName: "Test Bank",
BankAddress: "42 Bank Street",
BankPostalCode: "13337",
BankPostalCity: "Satoshiville",
BankCountry: "Japan",
AccountName: "Satoshi Nakamoto",
AccountNumber: "0234",
BSBNumber: "123456",
SWIFTCode: "91272837",
IBAN: "98218738671897",
SupportedCurrencies: "AUD,USD",
SupportedExchanges: testExchange,
},
)
bank, err := banking.GetBankAccountByID(bankAccountID)
if err != nil {
t.Fatal(err)
}
req := &withdraw.Request{
Exchange: testExchange,
Currency: currency.AUD,
Description: testExchange,
Amount: 1.0,
Type: 1,
Fiat: withdraw.FiatRequest{
Bank: *bank,
},
}
_, err = SubmitWithdrawal(req)
if err != nil {
t.Fatal(err)
}
_, err = SubmitWithdrawal(nil)
if err != nil {
if err.Error() != withdraw.ErrRequestCannotBeNil.Error() {
t.Fatal(err)
}
}
cleanup()
}
func TestWithdrawEventByID(t *testing.T) {
tempResp := &withdraw.Response{
ID: withdraw.DryRunID,
}
_, err := WithdrawalEventByID(withdraw.DryRunID.String())
if err != nil {
if err.Error() != fmt.Errorf(ErrWithdrawRequestNotFound, withdraw.DryRunID.String()).Error() {
t.Fatal(err)
}
}
withdraw.Cache.Add(withdraw.DryRunID.String(), tempResp)
v, err := WithdrawalEventByID(withdraw.DryRunID.String())
if err != nil {
if err != fmt.Errorf(ErrWithdrawRequestNotFound, withdraw.DryRunID.String()) {
t.Fatal(err)
}
}
if v == nil {
t.Fatal("expected WithdrawalEventByID() to return data from cache")
}
}
func TestWithdrawalEventByExchange(t *testing.T) {
_, err := WithdrawalEventByExchange(testExchange, 1)
if err == nil {
t.Fatal(err)
}
}
func TestWithdrawEventByDate(t *testing.T) {
_, err := WithdrawEventByDate(testExchange, time.Now(), time.Now(), 1)
if err == nil {
t.Fatal(err)
}
}
func TestWithdrawalEventByExchangeID(t *testing.T) {
_, err := WithdrawalEventByExchangeID(testExchange, testExchange)
if err == nil {
t.Fatal(err)
}
}
func TestParseEvents(t *testing.T) {
var testData []*withdraw.Response
for x := 0; x < 5; x++ {
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
ID: withdraw.DryRunID,
Exchange: withdraw.ExchangeResponse{
Name: test,
ID: test,
Status: test,
},
RequestDetails: withdraw.Request{
Exchange: test,
Description: test,
Amount: 1.0,
},
}
if x%2 == 0 {
resp.RequestDetails.Currency = currency.AUD
resp.RequestDetails.Type = 1
resp.RequestDetails.Fiat = withdraw.FiatRequest{
Bank: banking.Account{
Enabled: false,
ID: fmt.Sprintf("test-%v", x),
BankName: fmt.Sprintf("test-%v-bank", x),
AccountName: "hello",
AccountNumber: fmt.Sprintf("test-%v", x),
BSBNumber: "123456",
SupportedCurrencies: "BTC-AUD",
SupportedExchanges: testExchange,
},
}
} else {
resp.RequestDetails.Currency = currency.BTC
resp.RequestDetails.Type = 0
resp.RequestDetails.Crypto.Address = test
resp.RequestDetails.Crypto.FeeAmount = 0
resp.RequestDetails.Crypto.AddressTag = test
}
testData = append(testData, resp)
}
v := parseMultipleEvents(testData)
if reflect.TypeOf(v).String() != "*gctrpc.WithdrawalEventsByExchangeResponse" {
t.Fatal("expected type to be *gctrpc.WithdrawalEventsByExchangeResponse")
}
v = parseSingleEvents(testData[0])
if reflect.TypeOf(v).String() != "*gctrpc.WithdrawalEventsByExchangeResponse" {
t.Fatal("expected type to be *gctrpc.WithdrawalEventsByExchangeResponse")
}
v = parseSingleEvents(testData[1])
if v.Event[0].Request.Type != 0 {
t.Fatal("Expected second entry in slice to return a Request.Type of Crypto")
}
}