Skip to content

Commit

Permalink
Merge branch 'main' into release/price-feeder/v0.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Feb 7, 2022
2 parents 51c5202 + c7ff2fd commit ae6294e
Show file tree
Hide file tree
Showing 28 changed files with 624 additions and 1,208 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/price-feeder-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,15 @@ jobs:
run: |-
git tag -d ${{ env.RELEASE_VERSION }} || echo "No such a tag exists before"
git tag ${{ env.RELEASE_VERSION }} HEAD
- name: Build
uses: goreleaser/goreleaser-action@v2
with:
version: latest
# Skip validate skips initial sanity checks in order to be able to
# fully run.
args: build --rm-dist --skip-validate
workdir: price-feeder
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: price-feeder/${{ env.RELEASE_VERSION }}
- name: Release
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --release-notes ./RELEASE_NOTES.md
# Note, we have to pin to v0.179.0 due to newer releases enforcing
# correct semantic versioning even when '--skip-validate' is provided.
#
# Ref: https://github.com/goreleaser/goreleaser/pull/2503
version: v0.179.0
args: release --rm-dist --skip-validate --release-notes ./RELEASE_NOTES.md
workdir: price-feeder
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
14 changes: 6 additions & 8 deletions price-feeder/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ builds:
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X github.com/umee-network/umee/price-feeder/cmd.Version={{ .Version }} -X github.com/umee-network/umee/price-feeder/cmd.Commit={{ .Commit }}
- -s -w -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X github.com/umee-network/umee/price-feeder/cmd.Version={{ replace .Version "price-feeder/" "price-feeder-" }} -X github.com/umee-network/umee/price-feeder/cmd.Commit={{ .Commit }}
goos:
- darwin
- linux
Expand All @@ -28,22 +28,20 @@ builds:

archives:
- format: tar.gz
wrap_in_directory: true
wrap_in_directory: "true"
format_overrides:
- goos: windows
format: zip
name_template: "{{ .Binary }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
name_template: '{{ .Binary }}-{{ replace .Version "price-feeder/" "price-feeder-" }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
files:
- README.md

release:
github:
owner: umee-network
name: umee
name_template: "v{{.Version}}"
disable: false
name_template: "price-feeder/v{{ .Tag }}"

checksum:
name_template: SHA256SUMS-v{{.Version}}.txt
name_template: 'SHA256SUMS-{{ replace .Version "price-feeder/" "price-feeder-" }}.txt'
algorithm: sha256

snapshot:
Expand Down
945 changes: 0 additions & 945 deletions price-feeder/go.sum

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions price-feeder/oracle/provider/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ type (
func NewBinanceProvider() *BinanceProvider {
return &BinanceProvider{
baseURL: binanceBaseURL,
client: &http.Client{
Timeout: defaultTimeout,
},
client: newDefaultHTTPClient(),
}
}

func NewBinanceProviderWithTimeout(timeout time.Duration) *BinanceProvider {
return &BinanceProvider{
baseURL: binanceBaseURL,
client: &http.Client{
Timeout: timeout,
},
client: newHTTPClientWithTimeout(timeout),
}
}

Expand Down Expand Up @@ -101,7 +97,7 @@ func (p BinanceProvider) getTickerPrice(ticker string) (TickerPrice, error) {
)
}

if strings.ToUpper(tickerResp.Symbol) != strings.ToUpper(ticker) {
if !strings.EqualFold(tickerResp.Symbol, ticker) {
return TickerPrice{}, fmt.Errorf(
"received unexpected symbol from Binance response; expected: %s, got: %s",
ticker, tickerResp.Symbol,
Expand Down
23 changes: 19 additions & 4 deletions price-feeder/oracle/provider/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
"symbol": "ATOMUSDT",
"lastPrice": "34.69000000",
"volume": "2396974.02000000"
}
}
`
rw.Write([]byte(resp))
}))
Expand All @@ -45,7 +45,7 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
"symbol": "ATOMUSDT",
"lastPrice": "34.69000000",
"volume": "2396974.02000000"
}
}
`
rw.Write([]byte(resp))
} else {
Expand All @@ -54,7 +54,7 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
"symbol": "LUNAUSDT",
"lastPrice": "41.35000000",
"volume": "2396974.02000000"
}
}
`
rw.Write([]byte(resp))
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
resp := `{
"code": -1121,
"msg": "Invalid symbol."
}
}
`
rw.Write([]byte(resp))
}))
Expand All @@ -112,4 +112,19 @@ func TestBinanceProvider_GetTickerPrices(t *testing.T) {
require.Error(t, err)
require.Nil(t, prices)
})

t.Run("check_redirect", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
http.Redirect(rw, r, p.baseURL, http.StatusTemporaryRedirect)
}))
defer server.Close()

server.Client().CheckRedirect = preventRedirect
p.client = server.Client()
p.baseURL = server.URL

prices, err := p.GetTickerPrices(types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.Error(t, err)
require.Nil(t, prices)
})
}
8 changes: 2 additions & 6 deletions price-feeder/oracle/provider/huobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,14 @@ type (
func NewHuobiProvider() *HuobiProvider {
return &HuobiProvider{
baseURL: huobiBaseURL,
client: &http.Client{
Timeout: defaultTimeout,
},
client: newDefaultHTTPClient(),
}
}

func NewHuobiProviderWithTimeout(timeout time.Duration) *HuobiProvider {
return &HuobiProvider{
baseURL: huobiBaseURL,
client: &http.Client{
Timeout: timeout,
},
client: newHTTPClientWithTimeout(timeout),
}
}

Expand Down
27 changes: 21 additions & 6 deletions price-feeder/oracle/provider/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
}
]
}
}
}
`
rw.Write([]byte(resp))
} else {
Expand All @@ -37,7 +37,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
"tick": {
"vol": 16511168.890881622
}
}
}
`
rw.Write([]byte(resp))
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
}
]
}
}
}
`
rw.Write([]byte(resp))

Expand All @@ -82,7 +82,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
"tick": {
"vol": 16511168.890881622
}
}
}
`
rw.Write([]byte(resp))

Expand All @@ -97,7 +97,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
}
]
}
}
}
`
rw.Write([]byte(resp))

Expand All @@ -108,7 +108,7 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
"tick": {
"vol": 162129738.74087432
}
}
}
`
rw.Write([]byte(resp))
}
Expand Down Expand Up @@ -167,4 +167,19 @@ func TestHuobiProvider_GetTickerPrices(t *testing.T) {
require.Error(t, err)
require.Nil(t, prices)
})

t.Run("check_redirect", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
http.Redirect(rw, r, p.baseURL, http.StatusTemporaryRedirect)
}))
defer server.Close()

server.Client().CheckRedirect = preventRedirect
p.client = server.Client()
p.baseURL = server.URL

prices, err := p.GetTickerPrices(types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.Error(t, err)
require.Nil(t, prices)
})
}
8 changes: 2 additions & 6 deletions price-feeder/oracle/provider/kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ type (
func NewKrakenProvider() *KrakenProvider {
return &KrakenProvider{
baseURL: krakenBaseURL,
client: &http.Client{
Timeout: defaultTimeout,
},
client: newDefaultHTTPClient(),
}
}

func NewKrakenProviderWithTimeout(timeout time.Duration) *KrakenProvider {
return &KrakenProvider{
baseURL: krakenBaseURL,
client: &http.Client{
Timeout: timeout,
},
client: newHTTPClientWithTimeout(timeout),
}
}

Expand Down
15 changes: 15 additions & 0 deletions price-feeder/oracle/provider/kraken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,19 @@ func TestKrakenProvider_GetTickerPrices(t *testing.T) {
require.Error(t, err)
require.Nil(t, prices)
})

t.Run("check_redirect", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
http.Redirect(rw, r, p.baseURL, http.StatusTemporaryRedirect)
}))
defer server.Close()

server.Client().CheckRedirect = preventRedirect
p.client = server.Client()
p.baseURL = server.URL

prices, err := p.GetTickerPrices(types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.Error(t, err)
require.Nil(t, prices)
})
}
2 changes: 2 additions & 0 deletions price-feeder/oracle/provider/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func NewMockProvider() *MockProvider {
baseURL: mockBaseURL,
client: &http.Client{
Timeout: defaultTimeout,
// the mock provider is the only one which allows redirects
// because it gets prices from a google spreadsheet, which redirects
},
}
}
Expand Down
8 changes: 2 additions & 6 deletions price-feeder/oracle/provider/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ type (
func NewOsmosisProvider() *OsmosisProvider {
return &OsmosisProvider{
baseURL: osmosisBaseURL,
client: &http.Client{
Timeout: defaultTimeout,
},
client: newDefaultHTTPClient(),
}
}

func NewOsmosisProviderWithTimeout(timeout time.Duration) *OsmosisProvider {
return &OsmosisProvider{
baseURL: osmosisBaseURL,
client: &http.Client{
Timeout: timeout,
},
client: newHTTPClientWithTimeout(timeout),
}
}

Expand Down
15 changes: 15 additions & 0 deletions price-feeder/oracle/provider/osmosis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,19 @@ func TestOsmosisProvider_GetTickerPrices(t *testing.T) {
require.Error(t, err)
require.Nil(t, prices)
})

t.Run("check_redirect", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
http.Redirect(rw, r, p.baseURL, http.StatusTemporaryRedirect)
}))
defer server.Close()

server.Client().CheckRedirect = preventRedirect
p.client = server.Client()
p.baseURL = server.URL

prices, err := p.GetTickerPrices(types.CurrencyPair{Base: "ATOM", Quote: "USDT"})
require.Error(t, err)
require.Nil(t, prices)
})
}
18 changes: 18 additions & 0 deletions price-feeder/oracle/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"net/http"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,3 +23,20 @@ type TickerPrice struct {
Price sdk.Dec // last trade price
Volume sdk.Dec // 24h volume
}

// preventRedirect avoid any redirect in the http.Client the request call
// will not return an error, but a valid response with redirect response code.
func preventRedirect(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}

func newDefaultHTTPClient() *http.Client {
return newHTTPClientWithTimeout(defaultTimeout)
}

func newHTTPClientWithTimeout(timeout time.Duration) *http.Client {
return &http.Client{
Timeout: timeout,
CheckRedirect: preventRedirect,
}
}
Loading

0 comments on commit ae6294e

Please sign in to comment.