@@ -19,11 +19,12 @@ var TestEndpoint = "ws://localhost:8545"
19
19
var AliceKp = keystore .TestKeyRing .EthereumKeys [keystore .AliceKey ]
20
20
var GasLimit = big .NewInt (ethutils .DefaultGasLimit )
21
21
var MaxGasPrice = big .NewInt (ethutils .DefaultMaxGasPrice )
22
+ var MinGasPrice = big .NewInt (ethutils .DefaultMinGasPrice )
22
23
23
24
var GasMultipler = big .NewFloat (ethutils .DefaultGasMultiplier )
24
25
25
26
func TestConnect (t * testing.T ) {
26
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice , GasMultipler , "" , "" )
27
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice , MinGasPrice , GasMultipler , "" , "" )
27
28
err := conn .Connect ()
28
29
if err != nil {
29
30
t .Fatal (err )
@@ -40,7 +41,7 @@ func TestContractCode(t *testing.T) {
40
41
t .Fatal (err )
41
42
}
42
43
43
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice , GasMultipler , "" , "" )
44
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice , MinGasPrice , GasMultipler , "" , "" )
44
45
err = conn .Connect ()
45
46
if err != nil {
46
47
t .Fatal (err )
@@ -61,8 +62,12 @@ func TestContractCode(t *testing.T) {
61
62
}
62
63
63
64
func TestConnection_SafeEstimateGas (t * testing.T ) {
65
+ // In the case of d := c.Add(a, b), since c==d, there is a risk that MaxGasPrice itself will be changed,
66
+ // so the local variable maxGasPrice is defined by big.NewInt(0).
67
+ maxGasPrice := big .NewInt (0 )
64
68
// MaxGasPrice is the constant price on the dev network, so we increase it here by 1 to ensure it adjusts
65
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice .Add (MaxGasPrice , big .NewInt (1 )), GasMultipler , "" , "" )
69
+ maxGasPrice .Add (MaxGasPrice , big .NewInt (1 ))
70
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , MinGasPrice , GasMultipler , "" , "" )
66
71
err := conn .Connect ()
67
72
if err != nil {
68
73
t .Fatal (err )
@@ -74,14 +79,14 @@ func TestConnection_SafeEstimateGas(t *testing.T) {
74
79
t .Fatal (err )
75
80
}
76
81
77
- if price .Cmp (MaxGasPrice ) == 0 {
82
+ if price .Cmp (maxGasPrice ) == 0 {
78
83
t .Fatalf ("Gas price should be less than max. Suggested: %s Max: %s" , price .String (), MaxGasPrice .String ())
79
84
}
80
85
}
81
86
82
87
func TestConnection_SafeEstimateGasMax (t * testing.T ) {
83
88
maxPrice := big .NewInt (1 )
84
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxPrice , GasMultipler , "" , "" )
89
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxPrice , MinGasPrice , GasMultipler , "" , "" )
85
90
err := conn .Connect ()
86
91
if err != nil {
87
92
t .Fatal (err )
@@ -98,11 +103,55 @@ func TestConnection_SafeEstimateGasMax(t *testing.T) {
98
103
}
99
104
}
100
105
106
+ func TestConnection_SafeEstimateGasMin (t * testing.T ) {
107
+ minPrice := big .NewInt (1 )
108
+ // When gasMultipler is zero, the gasPrice is zero if the effect of the minPrice is removed.
109
+ gasMultipler := big .NewFloat (0 )
110
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , MaxGasPrice , minPrice , gasMultipler , "" , "" )
111
+ err := conn .Connect ()
112
+ if err != nil {
113
+ t .Fatal (err )
114
+ }
115
+ defer conn .Close ()
116
+
117
+ price , err := conn .SafeEstimateGas (context .Background ())
118
+ if err != nil {
119
+ t .Fatal (err )
120
+ }
121
+
122
+ if price .Cmp (minPrice ) != 0 {
123
+ t .Fatalf ("Gas price should equal min. Suggested: %s Min: %s" , price .String (), minPrice .String ())
124
+ }
125
+ }
126
+
127
+ func TestConnection_SafeEstimateGasSameMin (t * testing.T ) {
128
+ // When GasMultipler is set to 1, the gas price is set to 2000000000, so the minPrice is set to the same price
129
+ // and maxPrice is made larger than the minPrice by adding one.
130
+ minPrice := MaxGasPrice
131
+ maxGasPrice := big .NewInt (0 )
132
+ maxGasPrice .Add (MaxGasPrice , big .NewInt (1 ))
133
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , minPrice , GasMultipler , "" , "" )
134
+ err := conn .Connect ()
135
+ if err != nil {
136
+ t .Fatal (err )
137
+ }
138
+ defer conn .Close ()
139
+
140
+ price , err := conn .SafeEstimateGas (context .Background ())
141
+ if err != nil {
142
+ t .Fatal (err )
143
+ }
144
+
145
+ if price .Cmp (minPrice ) != 0 {
146
+ t .Fatalf ("Gas price should equal min. Suggested: %s Min: %s" , price .String (), minPrice .String ())
147
+ }
148
+ }
149
+
101
150
func TestConnection_EstimateGasLondon (t * testing.T ) {
102
151
// Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
103
152
// Goerli commonly has a base fee of 7 wei with maxPriorityFeePerGas of 4.999999993 gwei
104
153
maxGasPrice := big .NewInt (100000000000 )
105
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
154
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , MinGasPrice , GasMultipler , "" , "" )
106
155
err := conn .Connect ()
107
156
if err != nil {
108
157
t .Fatal (err )
@@ -131,7 +180,7 @@ func TestConnection_EstimateGasLondonMax(t *testing.T) {
131
180
// Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
132
181
// Goerli commonly has a base fee of 7 wei with maxPriorityFeePerGas of 4.999999993 gwei
133
182
maxGasPrice := big .NewInt (100 )
134
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
183
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , MinGasPrice , GasMultipler , "" , "" )
135
184
err := conn .Connect ()
136
185
if err != nil {
137
186
t .Fatal (err )
@@ -166,7 +215,7 @@ func TestConnection_EstimateGasLondonMin(t *testing.T) {
166
215
// Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
167
216
// Goerli commonly has a base fee of 7 wei with maxPriorityFeePerGas of 4.999999993 gwei
168
217
maxGasPrice := big .NewInt (1 )
169
- conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
218
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , MinGasPrice , GasMultipler , "" , "" )
170
219
err := conn .Connect ()
171
220
if err != nil {
172
221
t .Fatal (err )
0 commit comments