mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 23:16:54 +00:00
accounts: Move to instance methods, fix races and isolate tests (#1923)
* Bybit: Fix race in TestUpdateAccountInfo and TestWSHandleData * DriveBy rename TestWSHandleData * This doesn't address running with -race=2+ due to the singleton * Accounts: Add account.GetService() * exchange: Assertify TestSetupDefaults * Exchanges: Add account.Service override for testing * Exchanges: Remove duplicate IsWebsocketEnabled test from TestSetupDefaults * Dispatch: Replace nil checks with NilGuard * Engine: Remove deprecated printAccountHoldingsChangeSummary * Dispatcher: Add EnsureRunning method * Accounts: Move singleton accounts service to exchange Accounts * Move singleton accounts service to exchange Accounts This maintains the concept of a global store, whilst allowing exchanges to override it when needed, particularly for testing. APIServer: * Remove getAllActiveAccounts from apiserver Deprecated apiserver only thing using this, so remove it instead of updating it * Update comment for UpdateAccountBalances everywhere * Docs: Add punctuation to function comments * Bybit: Coverage for wsProcessWalletPushData Save
This commit is contained in:
@@ -121,13 +121,11 @@ func TestGetAccountByID(t *testing.T) {
|
||||
assert.ErrorIs(t, err, errAccountIDEmpty)
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
|
||||
longResp, err := e.ListAccounts(t.Context(), 49, 0)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
require.True(t, longResp != nil && len(longResp.Accounts) > 0, errExpectedNonEmpty)
|
||||
shortResp, err := e.GetAccountByID(t.Context(), longResp.Accounts[0].UUID)
|
||||
assert.NoError(t, err)
|
||||
if *shortResp != longResp.Accounts[0] {
|
||||
t.Errorf(errExpectMismatch, shortResp, longResp.Accounts[0])
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, shortResp, longResp.Accounts[0])
|
||||
}
|
||||
|
||||
func TestListAccounts(t *testing.T) {
|
||||
@@ -1136,10 +1134,10 @@ func TestUpdateTradablePairs(t *testing.T) {
|
||||
testexch.UpdatePairsOnce(t, e)
|
||||
}
|
||||
|
||||
func TestUpdateAccountInfo(t *testing.T) {
|
||||
func TestUpdateAccountBalances(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
|
||||
resp, err := e.UpdateAccountInfo(t.Context(), asset.Spot)
|
||||
resp, err := e.UpdateAccountBalances(t.Context(), asset.Spot)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, resp, errExpectedNonEmpty)
|
||||
}
|
||||
@@ -1916,10 +1914,10 @@ func convertTestHelper(t *testing.T) (fromAccID, toAccID string) {
|
||||
t.Fatal(errExpectedNonEmpty)
|
||||
}
|
||||
for x := range accIDs.Accounts {
|
||||
if accIDs.Accounts[x].Currency == testStable.String() {
|
||||
if accIDs.Accounts[x].Currency == testStable {
|
||||
fromAccID = accIDs.Accounts[x].UUID
|
||||
}
|
||||
if accIDs.Accounts[x].Currency == testFiat.String() {
|
||||
if accIDs.Accounts[x].Currency == testFiat {
|
||||
toAccID = accIDs.Accounts[x].UUID
|
||||
}
|
||||
if fromAccID != "" && toAccID != "" {
|
||||
|
||||
Reference in New Issue
Block a user