@@ -6,12 +6,14 @@ import (
6
6
7
7
"github.com/ethereum/go-ethereum/common"
8
8
"github.com/stackup-wallet/stackup-bundler/internal/testutils"
9
+ "github.com/stackup-wallet/stackup-bundler/pkg/userop"
9
10
)
10
11
11
12
// TestAddDepositInfoToCtx verifies that stake info can be added to a context and later retrieved.
12
13
func TestAddDepositInfoToCtx (t * testing.T ) {
13
14
op := testutils .MockValidInitUserOp ()
14
- ctx := NewUserOpHandlerContext (op , common .HexToAddress ("0x" ), big .NewInt (1 ))
15
+ penOps := []* userop.UserOperation {}
16
+ ctx := NewUserOpHandlerContext (op , penOps , testutils .ValidAddress , testutils .ChainID )
15
17
16
18
entity := op .GetFactory ()
17
19
dep := testutils .StakedDepositInfo
@@ -26,9 +28,34 @@ func TestAddDepositInfoToCtx(t *testing.T) {
26
28
// set. Expects nil.
27
29
func TestGetNilDepositInfoFromCtx (t * testing.T ) {
28
30
op := testutils .MockValidInitUserOp ()
29
- ctx := NewUserOpHandlerContext (op , common .HexToAddress ("0x" ), big .NewInt (1 ))
31
+ penOps := []* userop.UserOperation {}
32
+ ctx := NewUserOpHandlerContext (op , penOps , testutils .ValidAddress , testutils .ChainID )
30
33
31
34
if dep := ctx .GetDepositInfo (op .GetFactory ()); dep != nil {
32
35
t .Fatalf ("got %+v, want nil" , dep )
33
36
}
34
37
}
38
+
39
+ // TestGetPendingOps calls (c *UserOpHandlerCtx).GetPendingOps and verifies that it returns the same array of
40
+ // UserOperations the context was initialized with.
41
+ func TestGetPendingOps (t * testing.T ) {
42
+ op := testutils .MockValidInitUserOp ()
43
+ penOp1 := testutils .MockValidInitUserOp ()
44
+ penOp2 := testutils .MockValidInitUserOp ()
45
+ penOp2 .Nonce = big .NewInt (0 ).Add (penOp1 .Nonce , common .Big1 )
46
+ penOp3 := testutils .MockValidInitUserOp ()
47
+ penOp3 .Nonce = big .NewInt (0 ).Add (penOp2 .Nonce , common .Big1 )
48
+ initPenOps := []* userop.UserOperation {penOp1 , penOp2 , penOp3 }
49
+ ctx := NewUserOpHandlerContext (op , initPenOps , testutils .ValidAddress , testutils .ChainID )
50
+
51
+ penOps := ctx .GetPendingOps ()
52
+ if len (penOps ) != len (initPenOps ) {
53
+ t .Fatalf ("got length %d, want %d" , len (penOps ), len (initPenOps ))
54
+ }
55
+
56
+ for i , penOp := range penOps {
57
+ if ! testutils .IsOpsEqual (penOp , initPenOps [i ]) {
58
+ t .Fatalf ("ops not equal: %s" , testutils .GetOpsDiff (penOp , initPenOps [i ]))
59
+ }
60
+ }
61
+ }
0 commit comments