github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/etherman/etherscan/etherscan_test.go (about) 1 package etherscan 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 := `{"status":"1","message":"OK","result":{"LastBlock":"15816910","SafeGasPrice":"10","ProposeGasPrice":"11","FastGasPrice":"55","suggestBaseFee":"9.849758735","gasUsedRatio":"0.779364333333333,0.2434028,0.610012833333333,0.1246597,0.995500566666667"}}` 26 svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 27 fmt.Fprint(w, data) 28 })) 29 defer svr.Close() 30 31 apiKey := "" 32 c := NewEtherscanService(apiKey) 33 c.config.Url = svr.URL 34 35 gp, err := c.SuggestGasPrice(ctx) 36 require.NoError(t, err) 37 log.Debug("Etherscan GasPrice: ", gp) 38 assert.Equal(t, big.NewInt(55000000000), gp) 39 }