mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* GHA, tests: Add additional checks for common issues These checks include: - Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`). - Replacing `%s` with %q - Enforcing consistent usage of should/must wording for testify assert/require messages * Add support for checking backticked string format specifiers and fix issues * tests: Fix error comparisons * tests: Replace errors.Is(err, nil) usage with testify and automate check * refactor: Rename ExtractPort to ExtractPortOrDefault * tests: Replace assert with require for error handling in multiple test files * tests: Replace assert with require for error handling and improve assertions in data tests * tests: Fix typo in assertion message for StreamVol test * OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions * OKX: Revert intentional error check * Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
189 lines
4.6 KiB
Go
189 lines
4.6 KiB
Go
package engine
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
|
)
|
|
|
|
const (
|
|
address = "1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX"
|
|
bitStamp = "BITSTAMP"
|
|
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")
|
|
}
|
|
}
|
|
|
|
func TestSync(t *testing.T) {
|
|
t.Parallel()
|
|
m := SetupDepositAddressManager()
|
|
err := m.Sync(map[string]map[string][]deposit.Address{
|
|
bitStamp: {
|
|
btc: []deposit.Address{
|
|
{
|
|
Address: address,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
r, err := m.GetDepositAddressByExchangeAndCurrency(bitStamp, "", currency.BTC)
|
|
if err != nil {
|
|
t.Error("unexpected result")
|
|
}
|
|
if r.Address != address {
|
|
t.Error("unexpected result")
|
|
}
|
|
|
|
m.store = nil
|
|
err = m.Sync(map[string]map[string][]deposit.Address{
|
|
bitStamp: {
|
|
btc: []deposit.Address{
|
|
{
|
|
Address: address,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if !errors.Is(err, ErrDepositAddressStoreIsNil) {
|
|
t.Errorf("received %v, expected %v", err, ErrDepositAddressStoreIsNil)
|
|
}
|
|
|
|
m = nil
|
|
err = m.Sync(map[string]map[string][]deposit.Address{
|
|
bitStamp: {
|
|
btc: []deposit.Address{
|
|
{
|
|
Address: address,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if !errors.Is(err, ErrNilSubsystem) {
|
|
t.Errorf("received %v, expected %v", err, ErrNilSubsystem)
|
|
}
|
|
}
|
|
|
|
func TestGetDepositAddressByExchangeAndCurrency(t *testing.T) {
|
|
t.Parallel()
|
|
m := SetupDepositAddressManager()
|
|
_, err := m.GetDepositAddressByExchangeAndCurrency("", "", currency.BTC)
|
|
if !errors.Is(err, ErrDepositAddressStoreIsNil) {
|
|
t.Errorf("received %v, expected %v", err, ErrDepositAddressStoreIsNil)
|
|
}
|
|
|
|
m.store = map[string]map[string][]deposit.Address{
|
|
bitStamp: {
|
|
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("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)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
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][]deposit.Address{
|
|
bitStamp: {
|
|
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)
|
|
assert.NoError(t, err)
|
|
}
|