Skip to content

Commit

Permalink
fix packOp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Mar 20, 2024
1 parent 8624b27 commit ee3bb14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions service/operator/try_pay_user_op_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func UserOpHash(userOp *model.UserOperation, strategy *model.Strategy, validStar
if err != nil {
fmt.Println(err)
}
uint48Ty, err := abi.NewType("uint48", "", nil)

addressTy, _ := abi.NewType("address", "", nil)
arguments := abi.Arguments{
Expand All @@ -263,10 +264,10 @@ func UserOpHash(userOp *model.UserOperation, strategy *model.Strategy, validStar
Type: uint256Ty,
},
{
Type: uint256Ty,
Type: uint48Ty,
},
{
Type: uint256Ty,
Type: uint48Ty,
},
}
chainId, err := chain_service.GetChainId(strategy.NetWork)
Expand Down
13 changes: 9 additions & 4 deletions service/operator/try_pay_user_op_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestGenerateTestData(t *testing.T) {
fmt.Println(len(signature))
}
func TestPackUserOp(t *testing.T) {
// give same len signuature and paymasteranddata
userOp, _ := model.NewUserOp(utils.GenerateMockUserOperation())
res, byteres, err := packUserOp(userOp)
shouldEqualStr := "000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Expand All @@ -52,12 +53,16 @@ func TestPackUserOp(t *testing.T) {
func TestUserOpHash(t *testing.T) {
strategy := dashboard_service.GetStrategyById("1")
userOp, _ := model.NewUserOp(utils.GenerateMockUserOperation())
userOpHash, userOpHashStr, err := UserOpHash(userOp, strategy, big.NewInt(1710044496), big.NewInt(1741580496))
userOpHash, userOpabiEncodeStr, err := UserOpHash(userOp, strategy, big.NewInt(1710044496), big.NewInt(1741580496))
assert.NoError(t, err)
shouldEqualStr := "00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000aa36a7000000000000000000000000e99c4db5e360b8c84bf3660393cb2a85c3029b440000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000ffffffffff00000000000000000000000000000000000000000000000000000000000000aa0000000000000000000000000000000000000000000000000000000000000300000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
fmt.Println(userOpHashStr)
shouldEqualStr := "00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000aa36a7000000000000000000000000d93349ee959d295b115ee223af10ef432a8e852300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065ed35500000000000000000000000000000000000000000000000000000000067ce68d00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
fmt.Println(userOpabiEncodeStr)
fmt.Println(shouldEqualStr)
fmt.Println(hex.EncodeToString(userOpHash))
assert.EqualValues(t, userOpabiEncodeStr, shouldEqualStr)
userOpHashStr := hex.EncodeToString(userOpHash)
fmt.Println(userOpHashStr)
shouldEqualHashStr := "a1e2c52ad5779f4eb7a87c570149d7d33614fbc1d1ac30fa6cfe80107909e0fa"
assert.EqualValues(t, userOpHashStr, shouldEqualHashStr)
}

func TestUserOP(t *testing.T) {
Expand Down

0 comments on commit ee3bb14

Please sign in to comment.