This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgas_test.go
37 lines (31 loc) · 2.34 KB
/
gas_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package seth_test
import (
"context"
"testing"
"github.com/smartcontractkit/seth"
"github.com/stretchr/testify/require"
)
func TestGasEstimator(t *testing.T) {
c := newClient(t)
bn, err := c.Client.BlockNumber(context.Background())
require.NoError(t, err, "BlockNumber should not error")
for i := 0; i < 10; i++ {
_, err := c.DeployContractFromContractStore(c.NewTXOpts(), "NetworkDebugSubContract")
require.NoError(t, err, "Deploying contract should not error")
}
estimator := seth.NewGasEstimator(c)
suggestions, err := estimator.Stats(bn, 25)
require.NoError(t, err, "Gas esimator should not err")
require.NotNil(t, suggestions.GasPrice, "Suggested gas price should not be nil")
require.NotNil(t, suggestions.TipCap, "Suggested tip cap should not be nil")
require.Greater(t, suggestions.GasPrice.Perc25, float64(0), "Suggested 25th percentile gas price should be greater than 0")
require.GreaterOrEqual(t, suggestions.GasPrice.Perc50, suggestions.GasPrice.Perc25, "Suggested 50th percentile gas price should be greater than or equal to 25th percentile")
require.GreaterOrEqual(t, suggestions.GasPrice.Perc75, suggestions.GasPrice.Perc50, "Suggested 75th percentile gas price should be greater than or equal to 50th percentile")
require.GreaterOrEqual(t, suggestions.GasPrice.Perc99, suggestions.GasPrice.Perc75, "Suggested 99th percentile gas price should be greater than or equal to 75th percentile")
require.GreaterOrEqual(t, suggestions.GasPrice.Max, suggestions.GasPrice.Perc99, "Suggested max gas price should be greater than or equal to 99th percentile")
require.GreaterOrEqual(t, suggestions.TipCap.Perc25, float64(0), "Suggested 25th percentile tip cap should be greater than or equal to 0")
require.GreaterOrEqual(t, suggestions.TipCap.Perc50, suggestions.TipCap.Perc25, "Suggested 50th percentile tip cap should be greater than or equal to 25th percentile")
require.GreaterOrEqual(t, suggestions.TipCap.Perc75, suggestions.TipCap.Perc50, "Suggested 75th percentile tip cap should be greater than or equal to 50th percentile")
require.GreaterOrEqual(t, suggestions.TipCap.Perc99, suggestions.TipCap.Perc75, "Suggested 99th percentile tip cap should be greater than or equal to 75th percentile")
require.GreaterOrEqual(t, suggestions.TipCap.Max, suggestions.TipCap.Perc99, "Suggested max tip cap should be greater than or equal to 99th percentile")
}