forked from pegnet/pegnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the new polling sources to the new interface
- Loading branch information
Showing
14 changed files
with
304 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package polling_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/pegnet/pegnet/common" | ||
"github.com/pegnet/pegnet/polling" | ||
"github.com/pegnet/pegnet/testutils" | ||
"github.com/zpatrick/go-config" | ||
) | ||
|
||
// FixedDataSourceTest will test the parsing of the data source using the fixed response | ||
func FixedDataSourceTest(t *testing.T, source string, fixed []byte) { | ||
defer func() { http.DefaultClient = &http.Client{} }() // Don't leave http broken | ||
|
||
c := config.NewConfig([]config.Provider{common.NewUnitTestConfigProvider()}) | ||
|
||
// Set default http client to return what we expect from apilayer | ||
cl := testutils.GetClientWithFixedResp(fixed) | ||
http.DefaultClient = cl | ||
|
||
s, err := polling.NewDataSource(source, c) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
pegs, err := s.FetchPegPrices() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
for _, asset := range s.SupportedPegs() { | ||
_, ok := pegs[asset] | ||
if !ok { | ||
t.Errorf("Missing %s", asset) | ||
} | ||
} | ||
} | ||
|
||
// ActualDataSourceTest actually fetches the resp over the internet | ||
func ActualDataSourceTest(t *testing.T, source string) { | ||
defer func() { http.DefaultClient = &http.Client{} }() // Don't leave http broken | ||
|
||
c := config.NewConfig([]config.Provider{common.NewUnitTestConfigProvider()}) | ||
http.DefaultClient = &http.Client{} | ||
|
||
s, err := polling.NewDataSource(source, c) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
pegs, err := s.FetchPegPrices() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
for _, asset := range s.SupportedPegs() { | ||
_, ok := pegs[asset] | ||
if !ok { | ||
t.Errorf("Missing %s", asset) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,16 @@ | ||
package polling_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/pegnet/pegnet/common" | ||
. "github.com/pegnet/pegnet/polling" | ||
"github.com/pegnet/pegnet/testutils" | ||
"github.com/zpatrick/go-config" | ||
) | ||
|
||
// TestActualExchangeRatesPeggedAssets tests all the crypto assets are found on exchangerates over the net | ||
func TestActualExchangeRatesPeggedAssets(t *testing.T) { | ||
c := config.NewConfig([]config.Provider{common.NewUnitTestConfigProvider()}) | ||
peg := make(PegAssets) | ||
|
||
http.DefaultClient = &http.Client{} | ||
|
||
ExchangeRatesAPIInterface(c, peg) | ||
for _, asset := range common.CurrencyAssets { | ||
_, ok := peg[asset] | ||
if !ok { | ||
t.Errorf("Missing %s", asset) | ||
} | ||
} | ||
ActualDataSourceTest(t, "ExchangeRates") | ||
} | ||
|
||
// TestFixedExchangeRatesPeggedAssets tests all the crypto assets are found on exchangerates from fixed | ||
func TestFixedExchangeRatesPeggedAssets(t *testing.T) { | ||
defer func() { http.DefaultClient = &http.Client{} }() // Don't leave http broken | ||
|
||
c := config.NewConfig([]config.Provider{common.NewUnitTestConfigProvider()}) | ||
|
||
// Set default http client to return what we expect from apilayer | ||
cl := testutils.GetClientWithFixedResp([]byte(exchangeRateResponse)) | ||
http.DefaultClient = cl | ||
|
||
peg := make(PegAssets) | ||
ExchangeRatesAPIInterface(c, peg) | ||
for _, asset := range common.CurrencyAssets { | ||
_, ok := peg[asset] | ||
if !ok { | ||
t.Errorf("Missing %s", asset) | ||
} | ||
} | ||
FixedDataSourceTest(t, "ExchangeRates", []byte(exchangeRateResponse)) | ||
} | ||
|
||
var exchangeRateResponse = `{"rates":{"CAD":1.3076237182,"HKD":7.8096299599,"ISK":124.7436469015,"PHP":51.1110120374,"DKK":6.6571555952,"HUF":289.7458760588,"CZK":22.7677218012,"GBP":0.8022113241,"RON":4.210878288,"SEK":9.4016941596,"IDR":13945.0022291574,"INR":68.9331252786,"BRL":3.7434685689,"RUB":62.9982166741,"HRK":6.5871600535,"JPY":107.9179670085,"THB":30.8452964779,"CHF":0.9814534106,"EUR":0.8916629514,"MYR":4.1129736959,"BGN":1.7439144004,"TRY":5.6818546589,"CNY":6.8807846634,"NOK":8.5844850646,"NZD":1.4750780205,"ZAR":13.8922871155,"USD":1.0,"MXN":19.0295140437,"SGD":1.3606776638,"AUD":1.4188140883,"ILS":3.5329469461,"KRW":1177.2982612572,"PLN":3.7877842176},"base":"USD","date":"2019-07-22"}` |
Oops, something went wrong.