mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Remove pointer reference * Fix portfolio withdraw tests * Add nil protection in validator method to reduce prospective panics and for future outbound checking * Updated tests * ch order var to not ref package * rm comparison * Add order ID validation check * Add exchange name validation check * Add in test details * fix tests * fix linter issues * linter issues strikes again * linter rabbit hole * Addr nitterinos * Add validation variadic interface to define sets of functionality check POC * didn't want to add an amount other than 0, didn't want to add address to exchange withdraw, didn't want to whitlist, can change if need be * add coverage * Add validation method options for exchange wrappers and abstracted validation into its own package * Add validation code for structs in exchange template generation * remove extra validation call as this is done in wrapper * fix niterinos for examplerinos * Add template to documentation tool and regenerated documentation * Addr niticles * Fix tests due to validation update * Add more validation checks for modify/submit orders * update tests * fix more tests * Add asset type to submit variable in tests and rpc call. Regen funcs. * Add field to modify struct in tests * applied field asset to cancel struct across project * fix woopsy
188 lines
4.7 KiB
Go
188 lines
4.7 KiB
Go
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")
|
|
}
|
|
}
|