@@ -5,58 +5,38 @@ import (
5
5
"testing"
6
6
7
7
"github.com/ethereum/go-ethereum/common"
8
- "github.com/ethereum/go-ethereum/common/hexutil"
9
- "github.com/ethereum/go-ethereum/ethclient"
10
8
"github.com/stackup-wallet/stackup-bundler/internal/testutils"
11
9
"github.com/stackup-wallet/stackup-bundler/pkg/userop"
12
10
)
13
11
14
12
// TestSuggestMeanGasTipCapForNormalLoad simulates a scenario of normal network load. In this case the average
15
- // tip from userOps is assumed to not be above the tip suggested by the underlying node . In which case the
16
- // node's suggested tip is the optimal choice.
13
+ // tip from userOps is assumed to not be above the suggested tip . In which case the suggested tip is the
14
+ // optimal choice.
17
15
func TestSuggestMeanGasTipCapForNormalLoad (t * testing.T ) {
18
- expected := big .NewInt (2 )
19
- be := testutils .EthMock (testutils.MethodMocks {
20
- "eth_maxPriorityFeePerGas" : hexutil .EncodeBig (expected ),
21
- })
22
- eth , err := ethclient .Dial (be .URL )
23
- if err != nil {
24
- panic (err )
25
- }
26
-
27
16
op1 := testutils .MockValidInitUserOp ()
28
17
op1 .MaxPriorityFeePerGas = big .NewInt (1 )
29
18
op2 := testutils .MockValidInitUserOp ()
30
19
op2 .MaxPriorityFeePerGas = big .NewInt (1 )
31
20
batch := []* userop.UserOperation {op1 , op2 }
32
- if tip , err := SuggestMeanGasTipCap ( eth , batch ); err != nil {
33
- t . Fatalf ( "got %v, want %d" , err , expected . Int64 () )
34
- } else if tip .Cmp (expected ) != 0 {
21
+
22
+ expected := big . NewInt ( 2 )
23
+ if tip := SuggestMeanGasTipCap ( expected , batch ); tip .Cmp (expected ) != 0 {
35
24
t .Fatalf ("got %d, want %d" , tip .Int64 (), expected .Int64 ())
36
25
}
37
26
}
38
27
39
28
// TestSuggestMeanGasTipCapForHighLoad simulates a scenario of high network load. In this case the average tip
40
- // from userOps is assumed to be above the tip suggested by the underlying node (i.e. userOps want to be
41
- // included quickly). In which case the average tip from userOps is the optimal choice.
29
+ // from userOps is assumed to be above the suggested tip (i.e. userOps want to be included quickly). In which
30
+ // case the average tip from userOps is the optimal choice.
42
31
func TestSuggestMeanGasTipCapForHighLoad (t * testing.T ) {
43
- be := testutils .EthMock (testutils.MethodMocks {
44
- "eth_maxPriorityFeePerGas" : hexutil .EncodeBig (big .NewInt (2 )),
45
- })
46
- eth , err := ethclient .Dial (be .URL )
47
- if err != nil {
48
- panic (err )
49
- }
50
-
51
32
op1 := testutils .MockValidInitUserOp ()
52
33
op1 .MaxPriorityFeePerGas = big .NewInt (5 )
53
34
op2 := testutils .MockValidInitUserOp ()
54
35
op2 .MaxPriorityFeePerGas = big .NewInt (10 )
55
- expected := big .NewInt (7 )
56
36
batch := []* userop.UserOperation {op1 , op2 }
57
- if tip , err := SuggestMeanGasTipCap ( eth , batch ); err != nil {
58
- t . Fatalf ( "got %v, want %d" , err , expected . Int64 () )
59
- } else if tip .Cmp (expected ) != 0 {
37
+
38
+ expected := big . NewInt ( 7 )
39
+ if tip := SuggestMeanGasTipCap ( big . NewInt ( 2 ), batch ); tip .Cmp (expected ) != 0 {
60
40
t .Fatalf ("got %d, want %d" , tip .Int64 (), expected .Int64 ())
61
41
}
62
42
}
@@ -72,8 +52,9 @@ func TestSuggestMeanGasFeeCapNormalLoad(t *testing.T) {
72
52
batch := []* userop.UserOperation {op1 , op2 }
73
53
74
54
bf := big .NewInt (1 )
55
+ tip := big .NewInt (0 )
75
56
expected := big .NewInt (0 ).Mul (bf , common .Big2 )
76
- mf := SuggestMeanGasFeeCap (bf , batch )
57
+ mf := SuggestMeanGasFeeCap (bf , tip , batch )
77
58
if mf .Cmp (expected ) != 0 {
78
59
t .Fatalf ("got %d, want %d" , mf .Int64 (), expected .Int64 ())
79
60
}
@@ -90,8 +71,9 @@ func TestSuggestMeanGasFeeCapHighLoad(t *testing.T) {
90
71
batch := []* userop.UserOperation {op1 , op2 }
91
72
92
73
bf := big .NewInt (1 )
74
+ tip := big .NewInt (0 )
93
75
expected := big .NewInt (7 )
94
- mf := SuggestMeanGasFeeCap (bf , batch )
76
+ mf := SuggestMeanGasFeeCap (bf , tip , batch )
95
77
if mf .Cmp (expected ) != 0 {
96
78
t .Fatalf ("got %d, want %d" , mf .Int64 (), expected .Int64 ())
97
79
}
0 commit comments