Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
fix incorrect gasstation price (#639)
Browse files Browse the repository at this point in the history
* fix incorrect gasstation price

* add helping comment

* make go tests run no parallel
  • Loading branch information
P1sar authored May 14, 2021
1 parent 2073039 commit 67ecc1c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
11 changes: 7 additions & 4 deletions connections/ethereum/egs/egs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
8 changes: 4 additions & 4 deletions connections/ethereum/egs/egs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
}

0 comments on commit 67ecc1c

Please sign in to comment.