From 67ecc1c1335012263e5d37b958c9e7d8e75fb818 Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 14 May 2021 13:31:09 +0300 Subject: [PATCH] fix incorrect gasstation price (#639) * fix incorrect gasstation price * add helping comment * make go tests run no parallel --- Makefile | 4 ++-- connections/ethereum/egs/egs.go | 11 +++++++---- connections/ethereum/egs/egs_test.go | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index aa14faf30..0e52f3713 100644 --- a/Makefile +++ b/Makefile @@ -77,11 +77,11 @@ install-subkey: ## Runs go test for all packages except the solidity bindings test: @echo " > \033[32mRunning tests...\033[0m " - go test -coverprofile=cover.out -v `go list ./... | grep -v bindings | grep -v e2e` + go test -p 1 -coverprofile=cover.out -v `go list ./... | grep -v bindings | grep -v e2e` test-e2e: @echo " > \033[32mRunning e2e tests...\033[0m " - go test -v -timeout 0 ./e2e + go test -p 1 -v -timeout 0 ./e2e test-eth: @echo " > \033[32mRunning ethereum tests...\033[0m " diff --git a/connections/ethereum/egs/egs.go b/connections/ethereum/egs/egs.go index 4f70e504c..4cbebcf08 100644 --- a/connections/ethereum/egs/egs.go +++ b/connections/ethereum/egs/egs.go @@ -89,14 +89,17 @@ func queryAPI(url string) (*gasPriceResponse, error) { } func parsePrice(result *gasPriceResponse, speed string) *big.Int { + var res *big.Int switch speed { case Fastest: - return big.NewInt(result.Fastest) + res = big.NewInt(result.Fastest) case Fast: - return big.NewInt(result.Fast) + res = big.NewInt(result.Fast) case Average: - return big.NewInt(result.Average) + res = big.NewInt(result.Average) default: - return big.NewInt(result.Fast) + res = big.NewInt(result.Fast) } + base := big.NewInt(8) // we are using 8 here but not 9 bcs ethgas station returns values in Gwei * 10 + return res.Mul(res, big.NewInt(0).Exp(big.NewInt(10), base, nil)) } diff --git a/connections/ethereum/egs/egs_test.go b/connections/ethereum/egs/egs_test.go index db281efe5..4771d9827 100644 --- a/connections/ethereum/egs/egs_test.go +++ b/connections/ethereum/egs/egs_test.go @@ -23,9 +23,9 @@ var exampleResponse = &gasPriceResponse{ var rawResponse = "{\"fast\":590,\"fastest\":700,\"safeLow\":490,\"average\":500,\"block_time\":15.9,\"blockNum\":12389059,\"speed\":0.995538884040233,\"safeLowWait\":13.6,\"avgWait\":2.1,\"fastWait\":0.9,\"fastestWait\":0.6,\"gasPriceRange\":{\"4\":265,\"6\":265,\"8\":265,\"10\":265,\"20\":265,\"30\":265,\"40\":265,\"50\":265,\"60\":265,\"70\":265,\"80\":265,\"90\":265,\"100\":265,\"110\":265,\"120\":265,\"130\":265,\"140\":265,\"150\":265,\"160\":265,\"170\":265,\"180\":265,\"190\":265,\"200\":265,\"220\":265,\"240\":265,\"260\":265,\"280\":265,\"300\":265,\"320\":265,\"340\":265,\"360\":265,\"380\":265,\"400\":265,\"420\":265,\"440\":265,\"460\":265,\"480\":15,\"490\":13.6,\"500\":2.1,\"520\":1.7,\"540\":1.2,\"560\":1,\"580\":0.9,\"590\":0.9,\"600\":0.8,\"620\":0.7,\"640\":0.7,\"660\":0.7,\"680\":0.7,\"700\":0.6}}" func TestParsePrice(t *testing.T) { - assert.Equal(t, parsePrice(exampleResponse, Fastest), big.NewInt(exampleResponse.Fastest)) - assert.Equal(t, parsePrice(exampleResponse, Fast), big.NewInt(exampleResponse.Fast)) - assert.Equal(t, parsePrice(exampleResponse, Average), big.NewInt(exampleResponse.Average)) + assert.Equal(t, parsePrice(exampleResponse, Fastest), big.NewInt(200000000)) + assert.Equal(t, parsePrice(exampleResponse, Fast), big.NewInt(100000000)) + assert.Equal(t, parsePrice(exampleResponse, Average), big.NewInt(400000000)) } func TestFetchPrice(t *testing.T) { @@ -48,5 +48,5 @@ func TestFetchPrice(t *testing.T) { } assert.Equal(t, *res, expected) - assert.Equal(t, parsePrice(res, Fastest), big.NewInt(700)) + assert.Equal(t, parsePrice(res, Fastest), big.NewInt(70000000000)) }