diff --git a/Makefile b/Makefile index aa22248..8febe6f 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ clean: ci: clean fmt vet testall # testall: test all -testall: testpgdb testinfluxdb testapp +testall: testapp # testinfluxdb: test influxdb testinfluxdb: @@ -59,7 +59,7 @@ testpgdb: # testapp: test application layer testapp: - @echo "Testing influxdb..." + @echo "Testing app layer..." go test -v -count=1 -race ./test/application/... ## pg: starts postgres db inside docker container diff --git a/internal/core/application/market_price_service.go b/internal/core/application/market_price_service.go index bd1ad62..2e1d5ff 100644 --- a/internal/core/application/market_price_service.go +++ b/internal/core/application/market_price_service.go @@ -198,12 +198,12 @@ func (m *marketPriceService) getPricesInReferenceCurrency( baseAssetTickerFound, quoteAssetTickerFound, isBaseAssetStable, isQuoteAssetStable := false, false, false, false - baseAssetTicker, err := m.raterSvc.GetAssetCurrency(mktPrice.BaseAsset) - if err == nil { + baseAssetTicker, ok := m.raterSvc.GetAssetCurrency(mktPrice.BaseAsset) + if ok { baseAssetTickerFound = true } - quoteAssetTicker, err := m.raterSvc.GetAssetCurrency(mktPrice.QuoteAsset) - if err == nil { + quoteAssetTicker, ok := m.raterSvc.GetAssetCurrency(mktPrice.QuoteAsset) + if ok { quoteAssetTickerFound = true } diff --git a/internal/core/application/market_price_service_test.go b/internal/core/application/market_price_service_test.go index 0badfb5..ccc4c90 100644 --- a/internal/core/application/market_price_service_test.go +++ b/internal/core/application/market_price_service_test.go @@ -149,8 +149,8 @@ func mockRater( raterMock := new(port.MockRateService) raterMock.On("ConvertCurrency", mock.Anything, baseCurrency, mock.Anything).Return(baseResult, err) raterMock.On("ConvertCurrency", mock.Anything, quoteCurrency, mock.Anything).Return(quoteResult, err) - raterMock.On("GetAssetCurrency", baseAssetID).Return(baseCurrency, err) - raterMock.On("GetAssetCurrency", quoteAssetID).Return(quoteCurrency, err) + raterMock.On("GetAssetCurrency", baseAssetID).Return(baseCurrency, true) + raterMock.On("GetAssetCurrency", quoteAssetID).Return(quoteCurrency, true) raterMock.On("IsFiatSymbolSupported", baseAssetID).Return(isBaseAssetStable, nil) raterMock.On("IsFiatSymbolSupported", quoteAssetID).Return(isQuoteAssetStable, nil) diff --git a/internal/core/port/rater.go b/internal/core/port/rater.go index 1349b4e..b07e18f 100644 --- a/internal/core/port/rater.go +++ b/internal/core/port/rater.go @@ -19,5 +19,5 @@ type RateService interface { IsFiatSymbolSupported(symbol string) (bool, error) // GetAssetCurrency returns the currency of the asset - GetAssetCurrency(assetId string) (string, error) + GetAssetCurrency(assetId string) (string, bool) } diff --git a/internal/core/port/rater_mock.go b/internal/core/port/rater_mock.go index d61a63a..a6c5175 100644 --- a/internal/core/port/rater_mock.go +++ b/internal/core/port/rater_mock.go @@ -36,7 +36,7 @@ func (_m *MockRateService) ConvertCurrency(ctx context.Context, source string, t } // GetAssetCurrency provides a mock function with given fields: assetId -func (_m *MockRateService) GetAssetCurrency(assetId string) (string, error) { +func (_m *MockRateService) GetAssetCurrency(assetId string) (string, bool) { ret := _m.Called(assetId) var r0 string @@ -46,11 +46,11 @@ func (_m *MockRateService) GetAssetCurrency(assetId string) (string, error) { r0 = ret.Get(0).(string) } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { + var r1 bool + if rf, ok := ret.Get(1).(func(string) bool); ok { r1 = rf(assetId) } else { - r1 = ret.Error(1) + r1 = ret.Get(1).(bool) } return r0, r1 diff --git a/pkg/rater/exchange_rates_wrapper.go b/pkg/rater/exchange_rates_wrapper.go index 3f38a80..e690ca8 100644 --- a/pkg/rater/exchange_rates_wrapper.go +++ b/pkg/rater/exchange_rates_wrapper.go @@ -191,13 +191,10 @@ func (e *exchangeRateWrapper) IsFiatSymbolSupported(symbol string) (bool, error) func (e *exchangeRateWrapper) GetAssetCurrency( assetId string, -) (string, error) { +) (string, bool) { currency, ok := e.assetCurrencySymbolPair[assetId] - if !ok { - return "", fmt.Errorf("asset %s not found", assetId) - } - return currency, nil + return currency, ok } type CryptoCoin struct { @@ -233,8 +230,8 @@ func (e *exchangeRateWrapper) isCryptoSymbol( } // getCryptoToFiatRate returns the rate of one source crypt coin to the target fiat -//data are fetched from coin gecko and in order to prevent rate limit errors, the -//rates are cached and reloaded every coinGeckoRefreshInterval +// data are fetched from coin gecko and in order to prevent rate limit errors, the +// rates are cached and reloaded every coinGeckoRefreshInterval func (e *exchangeRateWrapper) getCryptoToFiatRate( ctx context.Context, source string, diff --git a/test/application/market_balance_test.go b/test/application/market_balance_test.go index 9854aee..b28c89a 100644 --- a/test/application/market_balance_test.go +++ b/test/application/market_balance_test.go @@ -9,7 +9,6 @@ import ( ) func (a *AppSvcTestSuit) TestGetMarketBalance() { - type args struct { ctx context.Context timeRange application.TimeRange @@ -181,8 +180,8 @@ func (a *AppSvcTestSuit) TestGetMarketBalance() { ctx: ctx, timeRange: application.TimeRange{ CustomPeriod: &application.CustomPeriod{ - StartDate: "2022-11-08T09:11:35.600Z", - EndDate: "2022-11-08T09:16:35.600Z", + StartDate: fourHoursAgo, + EndDate: now, }, }, marketIDs: []string{"1"}, @@ -216,6 +215,14 @@ func (a *AppSvcTestSuit) TestGetMarketBalance() { if got != nil { if err := tt.validateResponse(got); err != nil { + a.T().Logf("debug got %v", got) + a.T().Logf("debug got length %v", len(got.MarketsBalances)) + for k, v := range got.MarketsBalances { + a.T().Logf("market %s", k) + for _, p := range v { + a.T().Logf("balance %v", p) + } + } a.T().Error(err) } } diff --git a/test/application/market_price_test.go b/test/application/market_price_test.go index c4e6872..2d50e60 100644 --- a/test/application/market_price_test.go +++ b/test/application/market_price_test.go @@ -8,6 +8,11 @@ import ( "time" ) +var ( + now = time.Now().Format(time.RFC3339) + fourHoursAgo = time.Now().Add(-4 * time.Hour).Format(time.RFC3339) +) + func (a *AppSvcTestSuit) TestGetMarketPrice() { type args struct { ctx context.Context @@ -203,8 +208,8 @@ func (a *AppSvcTestSuit) TestGetMarketPrice() { ctx: ctx, timeRange: application.TimeRange{ CustomPeriod: &application.CustomPeriod{ - StartDate: "2022-11-08T09:11:35.600Z", - EndDate: "2022-11-08T09:16:35.600Z", + StartDate: fourHoursAgo, + EndDate: now, }, }, referenceCurrency: "EUR", @@ -240,6 +245,14 @@ func (a *AppSvcTestSuit) TestGetMarketPrice() { if got != nil { if err := tt.validateResponse(got); err != nil { + a.T().Logf("debug got %v", got) + a.T().Logf("debug got length %v", len(got.MarketsPrices)) + for k, v := range got.MarketsPrices { + a.T().Logf("market %s", k) + for _, p := range v { + a.T().Logf("price %v", p) + } + } a.T().Error(err) } }