github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/etherman/ethgasstation/ethgasstation_test.go (about) 1 package ethgasstation 2 3 import ( 4 "context" 5 "fmt" 6 "math/big" 7 "net/http" 8 "net/http/httptest" 9 "testing" 10 11 "github.com/0xPolygon/supernets2-node/log" 12 "github.com/stretchr/testify/assert" 13 "github.com/stretchr/testify/require" 14 ) 15 16 func init() { 17 log.Init(log.Config{ 18 Level: "debug", 19 Outputs: []string{"stderr"}, 20 }) 21 } 22 23 func TestGetGasPrice(t *testing.T) { 24 ctx := context.Background() 25 data := `{"baseFee":10,"blockNumber":15817089,"blockTime":11.88,"gasPrice":{"fast":11,"instant":66,"standard":10},"nextBaseFee":10,"priorityFee":{"fast":2,"instant":2,"standard":1}}` 26 svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 27 fmt.Fprint(w, data) 28 })) 29 defer svr.Close() 30 c := NewEthGasStationService() 31 c.Url = svr.URL 32 33 gp, err := c.SuggestGasPrice(ctx) 34 require.NoError(t, err) 35 log.Debug("EthGasStation GasPrice: ", gp) 36 assert.Equal(t, big.NewInt(66000000000), gp) 37 }