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

Commit 67ecc1c

Browse files
authored
fix incorrect gasstation price (#639)
* fix incorrect gasstation price * add helping comment * make go tests run no parallel
1 parent 2073039 commit 67ecc1c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ install-subkey:
7777
## Runs go test for all packages except the solidity bindings
7878
test:
7979
@echo " > \033[32mRunning tests...\033[0m "
80-
go test -coverprofile=cover.out -v `go list ./... | grep -v bindings | grep -v e2e`
80+
go test -p 1 -coverprofile=cover.out -v `go list ./... | grep -v bindings | grep -v e2e`
8181

8282
test-e2e:
8383
@echo " > \033[32mRunning e2e tests...\033[0m "
84-
go test -v -timeout 0 ./e2e
84+
go test -p 1 -v -timeout 0 ./e2e
8585

8686
test-eth:
8787
@echo " > \033[32mRunning ethereum tests...\033[0m "

connections/ethereum/egs/egs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ func queryAPI(url string) (*gasPriceResponse, error) {
8989
}
9090

9191
func parsePrice(result *gasPriceResponse, speed string) *big.Int {
92+
var res *big.Int
9293
switch speed {
9394
case Fastest:
94-
return big.NewInt(result.Fastest)
95+
res = big.NewInt(result.Fastest)
9596
case Fast:
96-
return big.NewInt(result.Fast)
97+
res = big.NewInt(result.Fast)
9798
case Average:
98-
return big.NewInt(result.Average)
99+
res = big.NewInt(result.Average)
99100
default:
100-
return big.NewInt(result.Fast)
101+
res = big.NewInt(result.Fast)
101102
}
103+
base := big.NewInt(8) // we are using 8 here but not 9 bcs ethgas station returns values in Gwei * 10
104+
return res.Mul(res, big.NewInt(0).Exp(big.NewInt(10), base, nil))
102105
}

connections/ethereum/egs/egs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var exampleResponse = &gasPriceResponse{
2323
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}}"
2424

2525
func TestParsePrice(t *testing.T) {
26-
assert.Equal(t, parsePrice(exampleResponse, Fastest), big.NewInt(exampleResponse.Fastest))
27-
assert.Equal(t, parsePrice(exampleResponse, Fast), big.NewInt(exampleResponse.Fast))
28-
assert.Equal(t, parsePrice(exampleResponse, Average), big.NewInt(exampleResponse.Average))
26+
assert.Equal(t, parsePrice(exampleResponse, Fastest), big.NewInt(200000000))
27+
assert.Equal(t, parsePrice(exampleResponse, Fast), big.NewInt(100000000))
28+
assert.Equal(t, parsePrice(exampleResponse, Average), big.NewInt(400000000))
2929
}
3030

3131
func TestFetchPrice(t *testing.T) {
@@ -48,5 +48,5 @@ func TestFetchPrice(t *testing.T) {
4848
}
4949

5050
assert.Equal(t, *res, expected)
51-
assert.Equal(t, parsePrice(res, Fastest), big.NewInt(700))
51+
assert.Equal(t, parsePrice(res, Fastest), big.NewInt(70000000000))
5252
}

0 commit comments

Comments
 (0)