Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ clean:
ci: clean fmt vet testall

# testall: test all
testall: testpgdb testinfluxdb testapp
testall: testapp

# testinfluxdb: test influxdb
testinfluxdb:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/core/application/market_price_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/application/market_price_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/core/port/rater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions internal/core/port/rater_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions pkg/rater/exchange_rates_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions test/application/market_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func (a *AppSvcTestSuit) TestGetMarketBalance() {

type args struct {
ctx context.Context
timeRange application.TimeRange
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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)
}
}
Expand Down
17 changes: 15 additions & 2 deletions test/application/market_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
}
Expand Down