@@ -5,58 +5,38 @@ import (
55 "testing"
66
77 "github.com/ethereum/go-ethereum/common"
8- "github.com/ethereum/go-ethereum/common/hexutil"
9- "github.com/ethereum/go-ethereum/ethclient"
108 "github.com/stackup-wallet/stackup-bundler/internal/testutils"
119 "github.com/stackup-wallet/stackup-bundler/pkg/userop"
1210)
1311
1412// 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.
1715func 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-
2716 op1 := testutils .MockValidInitUserOp ()
2817 op1 .MaxPriorityFeePerGas = big .NewInt (1 )
2918 op2 := testutils .MockValidInitUserOp ()
3019 op2 .MaxPriorityFeePerGas = big .NewInt (1 )
3120 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 {
3524 t .Fatalf ("got %d, want %d" , tip .Int64 (), expected .Int64 ())
3625 }
3726}
3827
3928// 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.
4231func 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-
5132 op1 := testutils .MockValidInitUserOp ()
5233 op1 .MaxPriorityFeePerGas = big .NewInt (5 )
5334 op2 := testutils .MockValidInitUserOp ()
5435 op2 .MaxPriorityFeePerGas = big .NewInt (10 )
55- expected := big .NewInt (7 )
5636 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 {
6040 t .Fatalf ("got %d, want %d" , tip .Int64 (), expected .Int64 ())
6141 }
6242}
@@ -72,8 +52,9 @@ func TestSuggestMeanGasFeeCapNormalLoad(t *testing.T) {
7252 batch := []* userop.UserOperation {op1 , op2 }
7353
7454 bf := big .NewInt (1 )
55+ tip := big .NewInt (0 )
7556 expected := big .NewInt (0 ).Mul (bf , common .Big2 )
76- mf := SuggestMeanGasFeeCap (bf , batch )
57+ mf := SuggestMeanGasFeeCap (bf , tip , batch )
7758 if mf .Cmp (expected ) != 0 {
7859 t .Fatalf ("got %d, want %d" , mf .Int64 (), expected .Int64 ())
7960 }
@@ -90,8 +71,9 @@ func TestSuggestMeanGasFeeCapHighLoad(t *testing.T) {
9071 batch := []* userop.UserOperation {op1 , op2 }
9172
9273 bf := big .NewInt (1 )
74+ tip := big .NewInt (0 )
9375 expected := big .NewInt (7 )
94- mf := SuggestMeanGasFeeCap (bf , batch )
76+ mf := SuggestMeanGasFeeCap (bf , tip , batch )
9577 if mf .Cmp (expected ) != 0 {
9678 t .Fatalf ("got %d, want %d" , mf .Int64 (), expected .Int64 ())
9779 }
0 commit comments