mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
exchanges/engine: Add multichain deposit/withdrawal support (#794)
* Add exchange multichain support * Start tidying up * Add multichain transfer support for Bitfinex and fix poloniex bug * Add Coinbene multichain support * Start adjusting the deposit address manager * Fix deposit tests and further enhancements * Cleanup * Add bypass flag, expand tests plus error coverage for Huobi Adjust helpers * Address nitterinos * BFX wd changes * Address nitterinos * Minor fixes rebasing on master * Fix BFX acceptableMethods test * Add some TO-DOs for 2 tests WRT races * Fix acceptableMethods test round 2 * Address nitterinos
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,7 +14,32 @@ const (
|
||||
btc = "BTC"
|
||||
)
|
||||
|
||||
func TestIsSynced(t *testing.T) {
|
||||
t.Parallel()
|
||||
var d DepositAddressManager
|
||||
if d.IsSynced() {
|
||||
t.Error("should be false")
|
||||
}
|
||||
m := SetupDepositAddressManager()
|
||||
err := m.Sync(map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !m.IsSynced() {
|
||||
t.Error("should be synced")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupDepositAddressManager(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := SetupDepositAddressManager()
|
||||
if m.store == nil {
|
||||
t.Fatal("expected store")
|
||||
@@ -21,27 +47,36 @@ func TestSetupDepositAddressManager(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSync(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := SetupDepositAddressManager()
|
||||
err := m.Sync(map[string]map[string]string{
|
||||
err := m.Sync(map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: address,
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
r, err := m.GetDepositAddressByExchangeAndCurrency(bitStamp, currency.BTC)
|
||||
r, err := m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.BTC)
|
||||
if err != nil {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
if r != address {
|
||||
if r.Address != address {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
m.store = nil
|
||||
err = m.Sync(map[string]map[string]string{
|
||||
err = m.Sync(map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: address,
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, ErrDepositAddressStoreIsNil) {
|
||||
@@ -49,9 +84,13 @@ func TestSync(t *testing.T) {
|
||||
}
|
||||
|
||||
m = nil
|
||||
err = m.Sync(map[string]map[string]string{
|
||||
err = m.Sync(map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: address,
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, ErrNilSubsystem) {
|
||||
@@ -60,35 +99,91 @@ func TestSync(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDepositAddressByExchangeAndCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := SetupDepositAddressManager()
|
||||
_, err := m.GetDepositAddressByExchangeAndCurrency("", currency.BTC)
|
||||
_, err := m.GetDepositAddressByExchangeAndCurrency("", "", currency.BTC)
|
||||
if !errors.Is(err, ErrDepositAddressStoreIsNil) {
|
||||
t.Errorf("received %v, expected %v", err, ErrDepositAddressStoreIsNil)
|
||||
}
|
||||
|
||||
m.store = map[string]map[string]string{
|
||||
m.store = map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: address,
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
"USDT": []deposit.Address{
|
||||
{
|
||||
Address: "ABsdZ",
|
||||
Chain: "SOL",
|
||||
},
|
||||
{
|
||||
Address: "0x1b",
|
||||
Chain: "ERC20",
|
||||
},
|
||||
{
|
||||
Address: "1asdad",
|
||||
Chain: "USDT",
|
||||
},
|
||||
},
|
||||
"BNB": nil,
|
||||
},
|
||||
}
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency(bitStamp, currency.BTC)
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency("asdf", "", currency.BTC)
|
||||
if !errors.Is(err, ErrExchangeNotFound) {
|
||||
t.Errorf("received %v, expected %v", err, ErrExchangeNotFound)
|
||||
}
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.LTC)
|
||||
if !errors.Is(err, ErrDepositAddressNotFound) {
|
||||
t.Errorf("received %v, expected %v", err, ErrDepositAddressNotFound)
|
||||
}
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.BNB)
|
||||
if !errors.Is(err, errNoDepositAddressesRetrieved) {
|
||||
t.Errorf("received %v, expected %v", err, errNoDepositAddressesRetrieved)
|
||||
}
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency(bitStamp, "NON-EXISTENT-CHAIN", currency.USDT)
|
||||
if !errors.Is(err, errDepositAddressChainNotFound) {
|
||||
t.Errorf("received %v, expected %v", err, errDepositAddressChainNotFound)
|
||||
}
|
||||
|
||||
if r, _ := m.GetDepositAddressByExchangeAndCurrency(bitStamp, "ErC20", currency.USDT); r.Address != "0x1b" && r.Chain != "ERC20" {
|
||||
t.Error("unexpected values")
|
||||
}
|
||||
if r, _ := m.GetDepositAddressByExchangeAndCurrency(bitStamp, "sOl", currency.USDT); r.Address != "ABsdZ" && r.Chain != "SOL" {
|
||||
t.Error("unexpected values")
|
||||
}
|
||||
if r, _ := m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.USDT); r.Address != "1asdad" && r.Chain != "USDT" {
|
||||
t.Error("unexpected values")
|
||||
}
|
||||
_, err = m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.BTC)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v, expected %v", err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDepositAddressesByExchange(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := SetupDepositAddressManager()
|
||||
_, err := m.GetDepositAddressesByExchange("")
|
||||
if !errors.Is(err, ErrDepositAddressStoreIsNil) {
|
||||
t.Errorf("received %v, expected %v", err, ErrDepositAddressStoreIsNil)
|
||||
}
|
||||
|
||||
m.store = map[string]map[string]string{
|
||||
m.store = map[string]map[string][]deposit.Address{
|
||||
bitStamp: {
|
||||
btc: address,
|
||||
btc: []deposit.Address{
|
||||
{
|
||||
Address: address,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = m.GetDepositAddressesByExchange("non-existent")
|
||||
if !errors.Is(err, ErrDepositAddressNotFound) {
|
||||
t.Errorf("received %v, expected %v", err, ErrDepositAddressNotFound)
|
||||
}
|
||||
|
||||
_, err = m.GetDepositAddressesByExchange(bitStamp)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v, expected %v", err, nil)
|
||||
|
||||
Reference in New Issue
Block a user