From b793094bfa85e2a3380808d83bdf3fae7a532fc9 Mon Sep 17 00:00:00 2001 From: David Nix Date: Thu, 14 Sep 2023 08:43:39 -0600 Subject: [PATCH] Refactor to use sender hex not bech32 --- x/mailbox/keeper/msg_server.go | 2 +- x/mailbox/keeper/msg_server_test.go | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x/mailbox/keeper/msg_server.go b/x/mailbox/keeper/msg_server.go index 9ec773e..d220edd 100644 --- a/x/mailbox/keeper/msg_server.go +++ b/x/mailbox/keeper/msg_server.go @@ -115,7 +115,7 @@ func (k Keeper) Dispatch(goCtx context.Context, msg *types.MsgDispatch) (*types. sdk.NewAttribute(types.AttributeKeyNonce, strconv.FormatUint(uint64(nonce), 10)), sdk.NewAttribute(types.AttributeKeyOrigin, strconv.FormatUint(uint64(origin), 10)), sdk.NewAttribute(types.AttributeKeyRecipientAddress, msg.RecipientAddress), - sdk.NewAttribute(types.AttributeKeySender, msg.Sender), + sdk.NewAttribute(types.AttributeKeySender, hexutil.Encode(sender)), sdk.NewAttribute(types.AttributeKeyVersion, strconv.FormatUint(0, 10)), // TODO(nix): How to determine version? ), sdk.NewEvent( diff --git a/x/mailbox/keeper/msg_server_test.go b/x/mailbox/keeper/msg_server_test.go index bbb59bf..25702bf 100644 --- a/x/mailbox/keeper/msg_server_test.go +++ b/x/mailbox/keeper/msg_server_test.go @@ -88,7 +88,7 @@ func (suite *KeeperTestSuite) TestDispatch() { id = "0x806d81a5b017cc51297bb545bc037f39ceecefab8041766c9b733900c9a01242" sender := "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr" senderBytes := sdk.MustAccAddressFromBech32(sender).Bytes() - senderHex = hexutil.Encode(senderBytes) + senderHex = hexutil.Encode(senderBytes) // no padding recipientBech32 := "cosmos10qa7yajp3fp869mdegtpap5zg056exja3chkw5" recipientBytes := sdk.MustAccAddressFromBech32(recipientBech32).Bytes() @@ -104,9 +104,8 @@ func (suite *KeeperTestSuite) TestDispatch() { "success with account as sender", func() { id = "0x0c4024fb3262d8852b1fc5caa9f73f91b9375a1cbe51f6da52d192d272623fd1" - sender := "cosmos17lklk2z0gevmdx4tvjac7g7t9prqczg6p6nuw9" - senderBytes := sdk.MustAccAddressFromBech32(sender).Bytes() - senderHex = hexutil.Encode(senderBytes) + senderHex = "0x000000000000000000000000f7edfb284f4659b69aab64bb8f23cb28460c091a" + sender := sdk.MustBech32ifyAddressBytes("cosmos", hexutil.MustDecode(senderHex)) recipientBech32 := "cosmos10qa7yajp3fp869mdegtpap5zg056exja3chkw5" recipientBytes := sdk.MustAccAddressFromBech32(recipientBech32).Bytes() @@ -138,7 +137,7 @@ func (suite *KeeperTestSuite) TestDispatch() { "success with hyperlane explorer data w/o sender/recipient padding", func() { id = "0x82fbf348d68e34903627d1f57fa3227211e35134e2a613ce6b78ce2d42e17198" - senderHex = "0x2b0860e52244f03e59f12cfe413d6a29bc30b893" + senderHex = "0x0000000000000000000000002b0860e52244f03e59f12cfe413d6a29bc30b893" senderBytes := hexutil.MustDecode(senderHex) senderBech32 := sdk.MustBech32ifyAddressBytes("cosmos", senderBytes) recipient := "0x76a2f655352752af6ce9b03932b9090009dc5d0c" @@ -153,7 +152,7 @@ func (suite *KeeperTestSuite) TestDispatch() { "fails with wrong id match", func() { id = "0x82fbf348d68e34903627d1f57fa3227211e35134e2a613ce6b78ce2d42e17198" - senderHex = "0x2b0860e52244f03e59f12cfe413d6a29bc30b893" + senderHex = "0x0000000000000000000000002b0860e52244f03e59f12cfe413d6a29bc30b893" senderBytes := hexutil.MustDecode(senderHex) senderBech32 := sdk.MustBech32ifyAddressBytes("cosmos", senderBytes) recipient := "0x76a2f655352752af6ce9b03932b9090009dc5d0c" @@ -197,7 +196,7 @@ func (suite *KeeperTestSuite) TestDispatch() { sdk.NewAttribute(types.AttributeKeyNonce, "0"), // TODO: Nonce is always zero sdk.NewAttribute(types.AttributeKeyOrigin, strconv.FormatUint(testOriginDomain, 10)), sdk.NewAttribute(types.AttributeKeyRecipientAddress, msg.RecipientAddress), - sdk.NewAttribute(types.AttributeKeySender, msg.Sender), + sdk.NewAttribute(types.AttributeKeySender, senderHex), sdk.NewAttribute(types.AttributeKeyVersion, "0"), // TODO(nix): Figure out version ), sdk.NewEvent(