@@ -97,3 +97,103 @@ func TestConnection_SafeEstimateGasMax(t *testing.T) {
97
97
t .Fatalf ("Gas price should equal max. Suggested: %s Max: %s" , price .String (), maxPrice .String ())
98
98
}
99
99
}
100
+
101
+ func TestConnection_EstimateGasLondon (t * testing.T ) {
102
+ // Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
103
+ // Goerli commonly has a base fee of 7 gwei with maxPriorityFeePerGas of 4.999999993 gwei
104
+ maxGasPrice := big .NewInt (100000000000 )
105
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
106
+ err := conn .Connect ()
107
+ if err != nil {
108
+ t .Fatal (err )
109
+ }
110
+ defer conn .Close ()
111
+
112
+ head , err := conn .conn .HeaderByNumber (context .Background (), nil )
113
+ if err != nil {
114
+ t .Fatal (err )
115
+ }
116
+
117
+ // This is here as the current dev network is an old version of geth and will keep the test failing on the CI
118
+ if head .BaseFee != nil {
119
+ _ , suggestedGasFeeCap , err := conn .EstimateGasLondon (context .Background (), head .BaseFee )
120
+ if err != nil {
121
+ t .Fatal (err )
122
+ }
123
+
124
+ if suggestedGasFeeCap .Cmp (maxGasPrice ) >= 0 {
125
+ t .Fatalf ("Gas fee cap should be less than max gas price. Suggested: %s Max: %s" , suggestedGasFeeCap .String (), maxGasPrice .String ())
126
+ }
127
+ }
128
+ }
129
+
130
+ func TestConnection_EstimateGasLondonMax (t * testing.T ) {
131
+ // Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
132
+ // Goerli commonly has a base fee of 7 gwei with maxPriorityFeePerGas of 4.999999993 gwei
133
+ maxGasPrice := big .NewInt (100 )
134
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
135
+ err := conn .Connect ()
136
+ if err != nil {
137
+ t .Fatal (err )
138
+ }
139
+ defer conn .Close ()
140
+
141
+ head , err := conn .conn .HeaderByNumber (context .Background (), nil )
142
+ if err != nil {
143
+ t .Fatal (err )
144
+ }
145
+
146
+ // This is here as the current dev network is an old version of geth and will keep the test failing on the CI
147
+ if head .BaseFee != nil {
148
+ suggestedGasTip , suggestedGasFeeCap , err := conn .EstimateGasLondon (context .Background (), head .BaseFee )
149
+ if err != nil {
150
+ t .Fatal (err )
151
+ }
152
+
153
+ maxPriorityFeePerGas := new (big.Int ).Sub (maxGasPrice , head .BaseFee )
154
+ if suggestedGasTip .Cmp (maxPriorityFeePerGas ) != 0 {
155
+ t .Fatalf ("Gas tip cap should equal max - baseFee. Suggested: %s Max Tip: %s" , suggestedGasTip .String (), maxPriorityFeePerGas .String ())
156
+ }
157
+
158
+ if suggestedGasFeeCap .Cmp (maxGasPrice ) != 0 {
159
+ t .Fatalf ("Gas fee cap should equal max gas price. Suggested: %s Max: %s" , suggestedGasFeeCap .String (), maxGasPrice .String ())
160
+ }
161
+
162
+ }
163
+ }
164
+
165
+ func TestConnection_EstimateGasLondonMin (t * testing.T ) {
166
+ // Set TestEndpoint to Goerli endpoint when testing as the current Github CI doesn't use the London version of geth
167
+ // Goerli commonly has a base fee of 7 gwei with maxPriorityFeePerGas of 4.999999993 gwei
168
+ maxGasPrice := big .NewInt (1 )
169
+ conn := NewConnection (TestEndpoint , false , AliceKp , log15 .Root (), GasLimit , maxGasPrice , GasMultipler , "" , "" )
170
+ err := conn .Connect ()
171
+ if err != nil {
172
+ t .Fatal (err )
173
+ }
174
+ defer conn .Close ()
175
+
176
+ head , err := conn .conn .HeaderByNumber (context .Background (), nil )
177
+ if err != nil {
178
+ t .Fatal (err )
179
+ }
180
+
181
+ // This is here as the current dev network is an old version of geth and will keep the test failing on the CI
182
+ if head .BaseFee != nil {
183
+ suggestedGasTip , suggestedGasFeeCap , err := conn .EstimateGasLondon (context .Background (), head .BaseFee )
184
+ if err != nil {
185
+ t .Fatal (err )
186
+ }
187
+
188
+ maxPriorityFeePerGas := big .NewInt (1 )
189
+ maxFeePerGas := new (big.Int ).Add (head .BaseFee , maxPriorityFeePerGas )
190
+
191
+ if suggestedGasTip .Cmp (maxPriorityFeePerGas ) != 0 {
192
+ t .Fatalf ("Gas tip cap should be equal to 1. Suggested: %s Max Tip: %s" , suggestedGasTip .String (), maxPriorityFeePerGas )
193
+ }
194
+
195
+ if suggestedGasFeeCap .Cmp (maxFeePerGas ) != 0 {
196
+ t .Fatalf ("Gas fee cap should be 1 greater than the base fee. Suggested: %s Max: %s" , suggestedGasFeeCap .String (), maxFeePerGas .String ())
197
+ }
198
+ }
199
+ }
0 commit comments