From 98aa88be27e6c4a75f7d168b7f82da04a33cd485 Mon Sep 17 00:00:00 2001 From: ryanbajollari <54822716+rbajollari@users.noreply.github.com> Date: Tue, 16 Jan 2024 22:35:10 -0500 Subject: [PATCH] fix: Handle astroport asset response returning inconsistent data type (#332) * fix: Handle astroport asset response returning inconsistent data type for quote symbol field * increase sleep time * increase sleep time again * lint * lint * type switch with assignment * fix checkprovidermin test --------- Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> --- config/currency_provider_tracker.go | 2 +- oracle/provider/astroport.go | 32 +++++++++++++++++++---------- oracle/provider/astroport_test.go | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/config/currency_provider_tracker.go b/config/currency_provider_tracker.go index dd3dc1ea..221f4ba7 100644 --- a/config/currency_provider_tracker.go +++ b/config/currency_provider_tracker.go @@ -120,7 +120,7 @@ func (t *CurrencyProviderTracker) setCoinIDSymbolMap() error { } defer resp.Body.Close() - var listResponse []coinList + listResponse := []coinList{} if err := json.NewDecoder(resp.Body).Decode(&listResponse); err != nil { return err } diff --git a/oracle/provider/astroport.go b/oracle/provider/astroport.go index c70138ea..9eb514d4 100644 --- a/oracle/provider/astroport.go +++ b/oracle/provider/astroport.go @@ -38,16 +38,16 @@ type ( // AstroportAssetResponse is the response from the Astroport assets endpoint. AstroportAssetResponse struct { - BaseID string `json:"base_id"` - BaseName string `json:"base_name"` - BaseSymbol string `json:"base_symbol"` - QuoteID string `json:"quote_id"` - QuoteName string `json:"quote_name"` - QuoteSymbol string `json:"quote_symbol"` - LastPrice float64 `json:"last_price"` - BaseVolume float64 `json:"base_volume"` - QuoteVolume float64 `json:"quote_volume"` - USDVolume float64 `json:"USD_volume"` + BaseID string `json:"base_id"` + BaseName string `json:"base_name"` + BaseSymbol string `json:"base_symbol"` + QuoteID string `json:"quote_id"` + QuoteName string `json:"quote_name"` + QuoteSymbol interface{} `json:"quote_symbol"` + LastPrice float64 `json:"last_price"` + BaseVolume float64 `json:"base_volume"` + QuoteVolume float64 `json:"quote_volume"` + USDVolume float64 `json:"USD_volume"` } // AstroportTickersResponse is the response from the Astroport tickers endpoint. AstroportTickersResponse struct { @@ -215,9 +215,19 @@ func (p *AstroportProvider) getAvailableAssets() (map[string]types.CurrencyPair, availablePairs := map[string]types.CurrencyPair{} for _, assetMap := range astroportAssets { for tickerID, asset := range assetMap { + // Some responses can return a 0 number value for Quote Symbol which + // needs to be handled here. + var quoteSymbol string + switch v := asset.QuoteSymbol.(type) { + case string: + quoteSymbol = strings.ToUpper(v) + default: + quoteSymbol = "" + } + availablePairs[tickerID] = types.CurrencyPair{ Base: strings.ToUpper(asset.BaseSymbol), - Quote: strings.ToUpper(asset.QuoteSymbol), + Quote: quoteSymbol, } } } diff --git a/oracle/provider/astroport_test.go b/oracle/provider/astroport_test.go index 27010067..9101fffc 100644 --- a/oracle/provider/astroport_test.go +++ b/oracle/provider/astroport_test.go @@ -33,7 +33,7 @@ func TestAstroportProvider_GetTickers(t *testing.T) { require.NotEmpty(t, availPairs) p.StartConnections() - time.Sleep(2 * time.Second) + time.Sleep(10 * time.Second) res, err := p.GetTickerPrices(pairs...) require.NoError(t, err)