diff --git a/x/opchild/client/cli/tx.go b/x/opchild/client/cli/tx.go index 02a7e002..0df45b23 100644 --- a/x/opchild/client/cli/tx.go +++ b/x/opchild/client/cli/tx.go @@ -174,7 +174,12 @@ Where proposal.json contains: return err } - msg, err := types.NewMsgExecuteMessages(clientCtx.GetFromAddress(), msgs) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg, err := types.NewMsgExecuteMessages(fromAddr, msgs) if err != nil { return fmt.Errorf("invalid message: %w", err) } @@ -194,8 +199,17 @@ Where proposal.json contains: func newBuildWithdrawMsg(clientCtx client.Context, ac address.Codec, txf tx.Factory, fs *flag.FlagSet, to sdk.AccAddress, amount sdk.Coin) (tx.Factory, *types.MsgInitiateTokenWithdrawal, error) { sender := clientCtx.GetFromAddress() + senderAddr, err := ac.BytesToString(sender) + if err != nil { + return txf, nil, err + } + + toAddr, err := ac.BytesToString(to) + if err != nil { + return txf, nil, err + } - msg := types.NewMsgInitiateTokenWithdrawal(sender, to, amount) + msg := types.NewMsgInitiateTokenWithdrawal(senderAddr, toAddr, amount) if err := msg.Validate(ac); err != nil { return txf, nil, err } @@ -207,8 +221,22 @@ func newBuildDepositMsg(clientCtx client.Context, ac address.Codec, txf tx.Facto sequence uint64, from, to sdk.AccAddress, amount sdk.Coin, hookMsg []byte, ) (tx.Factory, *types.MsgFinalizeTokenDeposit, error) { sender := clientCtx.GetFromAddress() + senderAddr, err := ac.BytesToString(sender) + if err != nil { + return txf, nil, err + } + + fromAddr, err := ac.BytesToString(from) + if err != nil { + return txf, nil, err + } + + toAddr, err := ac.BytesToString(to) + if err != nil { + return txf, nil, err + } - msg := types.NewMsgFinalizeTokenDeposit(sender, from, to, amount, sequence, hookMsg) + msg := types.NewMsgFinalizeTokenDeposit(senderAddr, fromAddr, toAddr, amount, sequence, hookMsg) if err := msg.Validate(ac); err != nil { return txf, nil, err } diff --git a/x/opchild/keeper/common_test.go b/x/opchild/keeper/common_test.go index e2064c47..83a69847 100644 --- a/x/opchild/keeper/common_test.go +++ b/x/opchild/keeper/common_test.go @@ -72,6 +72,14 @@ var ( sdk.AccAddress(pubKeys[4].Address()), } + addrsStr = []string{ + addrs[0].String(), + addrs[1].String(), + addrs[2].String(), + addrs[3].String(), + addrs[4].String(), + } + valAddrs = []sdk.ValAddress{ sdk.ValAddress(pubKeys[0].Address()), sdk.ValAddress(pubKeys[1].Address()), @@ -80,6 +88,14 @@ var ( sdk.ValAddress(pubKeys[4].Address()), } + valAddrsStr = []string{ + valAddrs[0].String(), + valAddrs[1].String(), + valAddrs[2].String(), + valAddrs[3].String(), + valAddrs[4].String(), + } + testDenoms = []string{ "test1", "test2", diff --git a/x/opchild/keeper/msg_server_test.go b/x/opchild/keeper/msg_server_test.go index dd265e87..5d3b75cf 100644 --- a/x/opchild/keeper/msg_server_test.go +++ b/x/opchild/keeper/msg_server_test.go @@ -36,13 +36,16 @@ func Test_MsgServer_ExecuteMessages(t *testing.T) { // apply validator updates input.OPChildKeeper.BlockValidatorUpdates(ctx) - addMsg, err := types.NewMsgAddValidator("val2", authtypes.NewModuleAddress(types.ModuleName), valAddrs[1], valPubKeys[1]) + moduleAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) require.NoError(t, err) - removeMsg, err := types.NewMsgRemoveValidator(authtypes.NewModuleAddress(types.ModuleName), valAddrs[0]) + addMsg, err := types.NewMsgAddValidator("val2", moduleAddr, valAddrsStr[1], valPubKeys[1]) require.NoError(t, err) - msg, err := types.NewMsgExecuteMessages(addrs[0], []sdk.Msg{addMsg, removeMsg}) + removeMsg, err := types.NewMsgRemoveValidator(moduleAddr, valAddrsStr[0]) + require.NoError(t, err) + + msg, err := types.NewMsgExecuteMessages(addrsStr[0], []sdk.Msg{addMsg, removeMsg}) require.NoError(t, err) _, err = ms.ExecuteMessages(ctx, msg) @@ -66,28 +69,31 @@ func Test_MsgServer_AddValidator(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPChildKeeper) valPubKeys := testutilsims.CreateTestPubKeys(2) - msg, err := types.NewMsgAddValidator("val1", authtypes.NewModuleAddress(types.ModuleName), valAddrs[0], valPubKeys[0]) + moduleAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + + msg, err := types.NewMsgAddValidator("val1", moduleAddr, valAddrsStr[0], valPubKeys[0]) require.NoError(t, err) _, err = ms.AddValidator(ctx, msg) require.NoError(t, err) // invalid signer - msg, err = types.NewMsgAddValidator("val1", addrs[0], valAddrs[0], valPubKeys[0]) + msg, err = types.NewMsgAddValidator("val1", addrsStr[0], valAddrsStr[0], valPubKeys[0]) require.NoError(t, err) _, err = ms.AddValidator(ctx, msg) require.Error(t, err) // duplicate add validator - msg, err = types.NewMsgAddValidator("val1", authtypes.NewModuleAddress(types.ModuleName), valAddrs[0], valPubKeys[1]) + msg, err = types.NewMsgAddValidator("val1", moduleAddr, valAddrsStr[0], valPubKeys[1]) require.NoError(t, err) _, err = ms.AddValidator(ctx, msg) require.Error(t, err) // duplicate cons pubkey - msg, err = types.NewMsgAddValidator("val1", authtypes.NewModuleAddress(types.ModuleName), valAddrs[1], valPubKeys[0]) + msg, err = types.NewMsgAddValidator("val1", moduleAddr, valAddrsStr[1], valPubKeys[0]) require.NoError(t, err) _, err = ms.AddValidator(ctx, msg) @@ -107,7 +113,7 @@ func Test_MsgServer_RemoveValidator(t *testing.T) { input.OPChildKeeper.SetValidator(ctx, val) // invalid signer - msg, err := types.NewMsgRemoveValidator(addrs[0], valAddrs[0]) + msg, err := types.NewMsgRemoveValidator(addrsStr[0], valAddrsStr[0]) require.NoError(t, err) _, err = ms.RemoveValidator( @@ -116,8 +122,11 @@ func Test_MsgServer_RemoveValidator(t *testing.T) { ) require.Error(t, err) + moduleAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + // remove not existing validator - msg, err = types.NewMsgRemoveValidator(authtypes.NewModuleAddress(types.ModuleName), valAddrs[1]) + msg, err = types.NewMsgRemoveValidator(moduleAddr, valAddrsStr[1]) require.NoError(t, err) _, err = ms.RemoveValidator( @@ -127,7 +136,7 @@ func Test_MsgServer_RemoveValidator(t *testing.T) { require.Error(t, err) // valid remove validator - msg, err = types.NewMsgRemoveValidator(authtypes.NewModuleAddress(types.ModuleName), valAddrs[0]) + msg, err = types.NewMsgRemoveValidator(moduleAddr, valAddrsStr[0]) require.NoError(t, err) _, err = ms.RemoveValidator( @@ -147,7 +156,10 @@ func Test_MsgServer_UpdateParams(t *testing.T) { params.HistoricalEntries = 1 params.BridgeExecutor = addrs[1].String() - msg := types.NewMsgUpdateParams(authtypes.NewModuleAddress(types.ModuleName), ¶ms) + moduleAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + + msg := types.NewMsgUpdateParams(moduleAddr, ¶ms) _, err = ms.UpdateParams(ctx, msg) require.NoError(t, err) _params, err := ms.GetParams(ctx) @@ -155,7 +167,10 @@ func Test_MsgServer_UpdateParams(t *testing.T) { require.Equal(t, params, _params) // invalid signer - msg = types.NewMsgUpdateParams(authtypes.NewModuleAddress("gov"), ¶ms) + govAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(t, err) + + msg = types.NewMsgUpdateParams(govAddr, ¶ms) require.NoError(t, err) _, err = ms.UpdateParams( @@ -199,10 +214,12 @@ func Test_MsgServer_Withdraw(t *testing.T) { // fund asset account := input.Faucet.NewFundedAccount(ctx, sdk.NewCoin(denom, math.NewInt(1_000_000_000))) + accountAddr, err := input.AccountKeeper.AddressCodec().BytesToString(account) + require.NoError(t, err) // valid - msg := types.NewMsgInitiateTokenWithdrawal(account, addrs[1], sdk.NewCoin(denom, math.NewInt(100))) - _, err := ms.InitiateTokenWithdrawal(ctx, msg) + msg := types.NewMsgInitiateTokenWithdrawal(accountAddr, addrsStr[1], sdk.NewCoin(denom, math.NewInt(100))) + _, err = ms.InitiateTokenWithdrawal(ctx, msg) require.NoError(t, err) } @@ -218,7 +235,7 @@ func Test_MsgServer_Deposit_NoHook(t *testing.T) { denom := "l2/" + hex.EncodeToString(bz[:]) // unauthorized deposit - msg := types.NewMsgFinalizeTokenDeposit(addrs[1], addrs[1], addrs[1], sdk.NewCoin(denom, math.NewInt(100)), 1, nil) + msg := types.NewMsgFinalizeTokenDeposit(addrsStr[1], addrsStr[1], addrsStr[1], sdk.NewCoin(denom, math.NewInt(100)), 1, nil) _, err := ms.FinalizeTokenDeposit(ctx, msg) require.Error(t, err) @@ -226,7 +243,7 @@ func Test_MsgServer_Deposit_NoHook(t *testing.T) { require.Equal(t, math.ZeroInt(), beforeBalance.Amount) // valid deposit - msg = types.NewMsgFinalizeTokenDeposit(addrs[0], addrs[1], addrs[1], sdk.NewCoin(denom, math.NewInt(100)), 1, nil) + msg = types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addrsStr[1], sdk.NewCoin(denom, math.NewInt(100)), 1, nil) _, err = ms.FinalizeTokenDeposit(ctx, msg) require.NoError(t, err) @@ -250,7 +267,7 @@ func Test_MsgServer_Deposit_HookSuccess(t *testing.T) { input.BridgeHook.err = nil // valid deposit - msg := types.NewMsgFinalizeTokenDeposit(addrs[0], addrs[1], addrs[1], sdk.NewCoin(denom, math.NewInt(100)), 1, hookMsgBytes) + msg := types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addrsStr[1], sdk.NewCoin(denom, math.NewInt(100)), 1, hookMsgBytes) _, err = ms.FinalizeTokenDeposit(ctx, msg) require.NoError(t, err) require.Equal(t, hookMsgBytes, input.BridgeHook.msgBytes) @@ -276,7 +293,7 @@ func Test_MsgServer_Deposit_HookFail(t *testing.T) { input.BridgeHook.err = errors.New("should be failed") // valid deposit - msg := types.NewMsgFinalizeTokenDeposit(addrs[0], addrs[1], addrs[1], sdk.NewCoin(denom, math.NewInt(100)), 1, []byte("invalid_message")) + msg := types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addrsStr[1], sdk.NewCoin(denom, math.NewInt(100)), 1, []byte("invalid_message")) _, err := ms.FinalizeTokenDeposit(ctx, msg) require.NoError(t, err) require.Empty(t, input.BridgeHook.msgBytes) diff --git a/x/opchild/types/tx.go b/x/opchild/types/tx.go index 2e56b712..510e0ead 100644 --- a/x/opchild/types/tx.go +++ b/x/opchild/types/tx.go @@ -45,11 +45,11 @@ const MAX_TOKEN_SYMBOL_LENGTH = 128 // NewMsgExecuteMessages creates a new MsgExecuteMessages instance. func NewMsgExecuteMessages( - sender sdk.AccAddress, //nolint:interfacer + sender string, messages []sdk.Msg, ) (*MsgExecuteMessages, error) { msg := &MsgExecuteMessages{ - Sender: sender.String(), + Sender: sender, } anys, err := sdktx.SetMsgs(messages) @@ -90,8 +90,8 @@ func (m MsgExecuteMessages) UnpackInterfaces(unpacker codectypes.AnyUnpacker) er // NewMsgAddValidator creates a new MsgAddValidator instance. // Delegator address and validator address are the same. func NewMsgAddValidator( - moniker string, authority sdk.AccAddress, - valAddr sdk.ValAddress, pubKey cryptotypes.PubKey, //nolint:interfacer + moniker string, authority string, + valAddr string, pubKey cryptotypes.PubKey, ) (*MsgAddValidator, error) { var pkAny *codectypes.Any if pubKey != nil { @@ -102,8 +102,8 @@ func NewMsgAddValidator( } return &MsgAddValidator{ Moniker: moniker, - Authority: authority.String(), - ValidatorAddress: valAddr.String(), + Authority: authority, + ValidatorAddress: valAddr, Pubkey: pkAny, }, nil } @@ -137,12 +137,12 @@ func (msg MsgAddValidator) UnpackInterfaces(unpacker codectypes.AnyUnpacker) err // NewMsgRemoveValidator creates a new MsgRemoveValidator instance. func NewMsgRemoveValidator( - authority sdk.AccAddress, - valAddr sdk.ValAddress, //nolint:interfacer + authority string, + valAddr string, ) (*MsgRemoveValidator, error) { return &MsgRemoveValidator{ - Authority: authority.String(), - ValidatorAddress: valAddr.String(), + Authority: authority, + ValidatorAddress: valAddr, }, nil } @@ -163,13 +163,13 @@ func (msg MsgRemoveValidator) Validate(ac, vc address.Codec) error { // NewMsgInitiateTokenWithdrawal creates a new MsgInitiateTokenWithdrawal instance. func NewMsgInitiateTokenWithdrawal( - sender sdk.AccAddress, - to sdk.AccAddress, + sender string, + to string, amount sdk.Coin, ) *MsgInitiateTokenWithdrawal { return &MsgInitiateTokenWithdrawal{ - Sender: sender.String(), - To: to.String(), + Sender: sender, + To: to, Amount: amount, } } @@ -195,15 +195,15 @@ func (msg MsgInitiateTokenWithdrawal) Validate(ac address.Codec) error { // NewMsgFinalizeTokenDeposit creates a new MsgFinalizeTokenDeposit instance. func NewMsgFinalizeTokenDeposit( - sender, from, to sdk.AccAddress, + sender, from, to string, amount sdk.Coin, sequence uint64, data []byte, ) *MsgFinalizeTokenDeposit { return &MsgFinalizeTokenDeposit{ - Sender: sender.String(), - From: from.String(), - To: to.String(), + Sender: sender, + From: from, + To: to, Amount: amount, Sequence: sequence, Data: data, @@ -238,9 +238,9 @@ func (msg MsgFinalizeTokenDeposit) Validate(ac address.Codec) error { /* MsgUpdateParams */ // NewMsgUpdateParams returns a new MsgUpdateParams instance -func NewMsgUpdateParams(authority sdk.AccAddress, params *Params) *MsgUpdateParams { +func NewMsgUpdateParams(authority string, params *Params) *MsgUpdateParams { return &MsgUpdateParams{ - Authority: authority.String(), + Authority: authority, Params: params, } } diff --git a/x/ophost/client/cli/tx.go b/x/ophost/client/cli/tx.go index 0ea9f452..6c51d022 100644 --- a/x/ophost/client/cli/tx.go +++ b/x/ophost/client/cli/tx.go @@ -65,7 +65,12 @@ func NewRecordBatchCmd(ac address.Codec) *cobra.Command { return err } - msg := types.NewMsgRecordBatch(clientCtx.GetFromAddress(), bridgeId, batchBytes) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg := types.NewMsgRecordBatch(fromAddr, bridgeId, batchBytes) if err = msg.Validate(ac); err != nil { return err } @@ -147,7 +152,12 @@ func NewCreateBridge(ac address.Codec) *cobra.Command { return err } - msg := types.NewMsgCreateBridge(clientCtx.GetFromAddress(), config) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg := types.NewMsgCreateBridge(fromAddr, config) if err = msg.Validate(ac); err != nil { return err } @@ -188,7 +198,12 @@ func NewProposeOutput(ac address.Codec) *cobra.Command { return err } - msg := types.NewMsgProposeOutput(clientCtx.GetFromAddress(), bridgeId, l2BlockNumber, outputBytes) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg := types.NewMsgProposeOutput(fromAddr, bridgeId, l2BlockNumber, outputBytes) if err = msg.Validate(ac); err != nil { return err } @@ -224,7 +239,12 @@ func NewDeleteOutput(ac address.Codec) *cobra.Command { return err } - msg := types.NewMsgDeleteOutput(clientCtx.GetFromAddress(), bridgeId, outputIndex) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg := types.NewMsgDeleteOutput(fromAddr, bridgeId, outputIndex) if err = msg.Validate(ac); err != nil { return err } @@ -255,7 +275,8 @@ func NewInitiateTokenDeposit(ac address.Codec) *cobra.Command { return err } - to, err := ac.StringToBytes(args[1]) + toAddr := args[1] + _, err = ac.StringToBytes(toAddr) if err != nil { return err } @@ -270,7 +291,12 @@ func NewInitiateTokenDeposit(ac address.Codec) *cobra.Command { return err } - msg := types.NewMsgInitiateTokenDeposit(clientCtx.GetFromAddress(), bridgeId, to, amount, data) + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + + msg := types.NewMsgInitiateTokenDeposit(fromAddr, bridgeId, toAddr, amount, data) if err = msg.Validate(ac); err != nil { return err } @@ -335,7 +361,8 @@ func NewFinalizeTokenWithdrawal(ac address.Codec) *cobra.Command { } } - receiver, err := ac.StringToBytes(withdrawalInfo.Receiver) + receiver := withdrawalInfo.Receiver + _, err = ac.StringToBytes(receiver) if err != nil { return err } @@ -365,12 +392,17 @@ func NewFinalizeTokenWithdrawal(ac address.Codec) *cobra.Command { return err } + fromAddr, err := ac.BytesToString(clientCtx.GetFromAddress()) + if err != nil { + return err + } + msg := types.NewMsgFinalizeTokenWithdrawal( withdrawalInfo.BridgeId, withdrawalInfo.OutputIndex, withdrawalInfo.Sequence, withdrawalProofs, - clientCtx.GetFromAddress(), + fromAddr, receiver, amount, version, diff --git a/x/ophost/keeper/common_test.go b/x/ophost/keeper/common_test.go index 936fd0f3..8ec9143e 100644 --- a/x/ophost/keeper/common_test.go +++ b/x/ophost/keeper/common_test.go @@ -73,6 +73,14 @@ var ( sdk.AccAddress(pubKeys[4].Address()), } + addrsStr = []string{ + addrs[0].String(), + addrs[1].String(), + addrs[2].String(), + addrs[3].String(), + addrs[4].String(), + } + testDenoms = []string{ "test1", "test2", diff --git a/x/ophost/keeper/msg_server_test.go b/x/ophost/keeper/msg_server_test.go index 8e389ae7..7c0d6477 100644 --- a/x/ophost/keeper/msg_server_test.go +++ b/x/ophost/keeper/msg_server_test.go @@ -18,7 +18,7 @@ func Test_RecordBatch(t *testing.T) { ctx, input := createDefaultTestInput(t) ms := keeper.NewMsgServerImpl(input.OPHostKeeper) - _, err := ms.RecordBatch(ctx, types.NewMsgRecordBatch(addrs[0], 1, []byte{1, 2, 3})) + _, err := ms.RecordBatch(ctx, types.NewMsgRecordBatch(addrsStr[0], 1, []byte{1, 2, 3})) require.NoError(t, err) } @@ -27,14 +27,14 @@ func Test_CreateBridge(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Challenger: addrs[0].String(), - Proposer: addrs[0].String(), + Challenger: addrsStr[0], + Proposer: addrsStr[0], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - res, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + res, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) require.Equal(t, uint64(1), res.BridgeId) @@ -48,14 +48,14 @@ func Test_ProposeOutput(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Challenger: addrs[0].String(), - Proposer: addrs[0].String(), + Challenger: addrsStr[0], + Proposer: addrsStr[0], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - createRes, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + createRes, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) require.Equal(t, uint64(1), createRes.BridgeId) @@ -63,11 +63,11 @@ func Test_ProposeOutput(t *testing.T) { ctx = ctx.WithBlockTime(blockTime) // unauthorized - _, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrs[1], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) + _, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[1], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) require.Error(t, err) // valid - proposeRes, err := ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrs[0], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) + proposeRes, err := ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) require.NoError(t, err) require.Equal(t, uint64(1), proposeRes.OutputIndex) @@ -85,14 +85,14 @@ func Test_DeleteOutput(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Proposer: addrs[0].String(), - Challenger: addrs[1].String(), + Proposer: addrsStr[0], + Challenger: addrsStr[1], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - createReq := types.NewMsgCreateBridge(addrs[0], config) + createReq := types.NewMsgCreateBridge(addrsStr[0], config) createRes, err := ms.CreateBridge(ctx, createReq) require.NoError(t, err) require.Equal(t, uint64(1), createRes.BridgeId) @@ -100,16 +100,16 @@ func Test_DeleteOutput(t *testing.T) { blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) - proposeRes, err := ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrs[0], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) + proposeRes, err := ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) require.NoError(t, err) require.Equal(t, uint64(1), proposeRes.OutputIndex) // unauthorized - _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrs[0], 1, 1)) + _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1)) require.Error(t, err) // valid - _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrs[1], 1, 1)) + _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 1)) require.NoError(t, err) // should return error; deleted @@ -122,14 +122,14 @@ func Test_InitiateTokenDeposit(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Proposer: addrs[0].String(), - Challenger: addrs[1].String(), + Proposer: addrsStr[0], + Challenger: addrsStr[1], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - createRes, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + createRes, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) require.Equal(t, uint64(1), createRes.BridgeId) @@ -137,7 +137,7 @@ func Test_InitiateTokenDeposit(t *testing.T) { input.Faucet.Fund(ctx, addrs[1], amount) _, err = ms.InitiateTokenDeposit( ctx, - types.NewMsgInitiateTokenDeposit(addrs[1], 1, addrs[2], amount, []byte("messages")), + types.NewMsgInitiateTokenDeposit(addrsStr[1], 1, addrsStr[2], amount, []byte("messages")), ) require.NoError(t, err) require.True(t, input.BankKeeper.GetBalance(ctx, addrs[1], baseDenom).IsZero()) @@ -149,14 +149,14 @@ func Test_FinalizeTokenWithdrawal(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Proposer: addrs[0].String(), - Challenger: addrs[1].String(), + Proposer: addrsStr[0], + Challenger: addrsStr[1], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) // fund amount @@ -176,14 +176,18 @@ func Test_FinalizeTokenWithdrawal(t *testing.T) { now := time.Now().UTC() ctx = ctx.WithBlockTime(now) - _, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrs[0], 1, 100, outputRoot)) + _, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 100, outputRoot)) require.NoError(t, err) ctx = ctx.WithBlockTime(now.Add(time.Second * 60)) + addr04, err := input.AccountKeeper.AddressCodec().BytesToString(decodeHex(t, "0000000000000000000000000000000000000004")) + require.NoError(t, err) + addr01, err := input.AccountKeeper.AddressCodec().BytesToString(decodeHex(t, "0000000000000000000000000000000000000001")) + require.NoError(t, err) _, err = ms.FinalizeTokenWithdrawal(ctx, types.NewMsgFinalizeTokenWithdrawal( 1, 1, 4, proofs, - decodeHex(t, "0000000000000000000000000000000000000004"), - decodeHex(t, "0000000000000000000000000000000000000001"), + addr04, + addr01, amount, version, stateRoot, storageRoot, blockHash, )) @@ -203,28 +207,30 @@ func Test_UpdateProposal(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Proposer: addrs[0].String(), - Challenger: addrs[1].String(), + Proposer: addrsStr[0], + Challenger: addrsStr[1], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) // gov signer - msg := types.NewMsgUpdateProposer(authtypes.NewModuleAddress("gov"), 1, addrs[1]) + govAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(t, err) + msg := types.NewMsgUpdateProposer(govAddr, 1, addrsStr[1]) _, err = ms.UpdateProposer(ctx, msg) require.NoError(t, err) _config, err := ms.GetBridgeConfig(ctx, 1) require.NoError(t, err) - require.Equal(t, addrs[1].String(), _config.Proposer) - require.Equal(t, addrs[1].String(), input.BridgeHook.proposer) + require.Equal(t, addrsStr[1], _config.Proposer) + require.Equal(t, addrsStr[1], input.BridgeHook.proposer) // current proposer signer - msg = types.NewMsgUpdateProposer(addrs[1], 1, addrs[2]) + msg = types.NewMsgUpdateProposer(addrsStr[1], 1, addrsStr[2]) _, err = ms.UpdateProposer(ctx, msg) require.NoError(t, err) _config, err = ms.GetBridgeConfig(ctx, 1) @@ -233,7 +239,9 @@ func Test_UpdateProposal(t *testing.T) { require.Equal(t, addrs[2].String(), input.BridgeHook.proposer) // invalid signer - msg = types.NewMsgUpdateProposer(authtypes.NewModuleAddress(types.ModuleName), 1, addrs[1]) + invalidAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + msg = types.NewMsgUpdateProposer(invalidAddr, 1, addrsStr[1]) require.NoError(t, err) _, err = ms.UpdateProposer( @@ -248,19 +256,21 @@ func Test_UpdateChallenger(t *testing.T) { ms := keeper.NewMsgServerImpl(input.OPHostKeeper) config := types.BridgeConfig{ - Proposer: addrs[0].String(), - Challenger: addrs[1].String(), + Proposer: addrsStr[0], + Challenger: addrsStr[1], SubmissionInterval: time.Second * 10, FinalizationPeriod: time.Second * 60, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } - _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrs[0], config)) + _, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config)) require.NoError(t, err) // gov signer - msg := types.NewMsgUpdateChallenger(authtypes.NewModuleAddress("gov"), 1, addrs[2]) + govAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(t, err) + msg := types.NewMsgUpdateChallenger(govAddr, 1, addrsStr[2]) _, err = ms.UpdateChallenger(ctx, msg) require.NoError(t, err) _config, err := ms.GetBridgeConfig(ctx, 1) @@ -269,7 +279,7 @@ func Test_UpdateChallenger(t *testing.T) { require.Equal(t, addrs[2].String(), input.BridgeHook.challenger) // current challenger - msg = types.NewMsgUpdateChallenger(addrs[2], 1, addrs[3]) + msg = types.NewMsgUpdateChallenger(addrsStr[2], 1, addrsStr[3]) _, err = ms.UpdateChallenger(ctx, msg) require.NoError(t, err) _config, err = ms.GetBridgeConfig(ctx, 1) @@ -278,7 +288,9 @@ func Test_UpdateChallenger(t *testing.T) { require.Equal(t, addrs[3].String(), input.BridgeHook.challenger) // invalid signer - msg = types.NewMsgUpdateChallenger(authtypes.NewModuleAddress(types.ModuleName), 1, addrs[1]) + invalidAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + msg = types.NewMsgUpdateChallenger(invalidAddr, 1, addrsStr[1]) require.NoError(t, err) _, err = ms.UpdateChallenger( @@ -295,13 +307,17 @@ func Test_MsgServer_UpdateParams(t *testing.T) { params := ms.GetParams(ctx) params.RegistrationFee = sdk.NewCoins(sdk.NewCoin("foo", math.NewInt(100))) - msg := types.NewMsgUpdateParams(authtypes.NewModuleAddress("gov"), ¶ms) - _, err := ms.UpdateParams(ctx, msg) + govAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(t, err) + msg := types.NewMsgUpdateParams(govAddr, ¶ms) + _, err = ms.UpdateParams(ctx, msg) require.NoError(t, err) require.Equal(t, params, ms.GetParams(ctx)) // invalid signer - msg = types.NewMsgUpdateParams(authtypes.NewModuleAddress(types.ModuleName), ¶ms) + invalidAddr, err := input.AccountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(types.ModuleName)) + require.NoError(t, err) + msg = types.NewMsgUpdateParams(invalidAddr, ¶ms) require.NoError(t, err) _, err = ms.UpdateParams( diff --git a/x/ophost/types/tx.go b/x/ophost/types/tx.go index 2d369225..52d155fd 100644 --- a/x/ophost/types/tx.go +++ b/x/ophost/types/tx.go @@ -34,12 +34,12 @@ var ( // NewMsgRecordBatch creates a new MsgRecordBatch instance. func NewMsgRecordBatch( - submitter sdk.AccAddress, + submitter string, bridgeId uint64, batchBytes []byte, ) *MsgRecordBatch { return &MsgRecordBatch{ - Submitter: submitter.String(), + Submitter: submitter, BridgeId: bridgeId, BatchBytes: batchBytes, } @@ -62,11 +62,11 @@ func (msg MsgRecordBatch) Validate(accAddressCodec address.Codec) error { // NewMsgCreateBridge creates a new MsgCreateBridge instance. func NewMsgCreateBridge( - creator sdk.AccAddress, + creator string, config BridgeConfig, ) *MsgCreateBridge { return &MsgCreateBridge{ - Creator: creator.String(), + Creator: creator, Config: config, } } @@ -89,13 +89,13 @@ func (msg MsgCreateBridge) Validate(ac address.Codec) error { // NewMsgProposeOutput creates a new MsgProposeOutput instance. // Delegator address and validator address are the same. func NewMsgProposeOutput( - proposer sdk.AccAddress, + proposer string, bridgeId uint64, l2BlockNumber uint64, outputRoot []byte, ) *MsgProposeOutput { return &MsgProposeOutput{ - Proposer: proposer.String(), + Proposer: proposer, BridgeId: bridgeId, L2BlockNumber: l2BlockNumber, OutputRoot: outputRoot, @@ -124,12 +124,12 @@ func (msg MsgProposeOutput) Validate(accAddressCodec address.Codec) error { // NewMsgDeleteOutput creates a new MsgDeleteOutput instance. func NewMsgDeleteOutput( - challenger sdk.AccAddress, + challenger string, bridgeId uint64, outputIndex uint64, ) *MsgDeleteOutput { return &MsgDeleteOutput{ - Challenger: challenger.String(), + Challenger: challenger, BridgeId: bridgeId, OutputIndex: outputIndex, } @@ -156,15 +156,15 @@ func (msg MsgDeleteOutput) Validate(accAddressCodec address.Codec) error { // NewMsgInitiateTokenDeposit creates a new MsgInitiateTokenDeposit instance. func NewMsgInitiateTokenDeposit( - sender sdk.AccAddress, + sender string, bridgeId uint64, - to sdk.AccAddress, + to string, amount sdk.Coin, data []byte, ) *MsgInitiateTokenDeposit { return &MsgInitiateTokenDeposit{ - Sender: sender.String(), - To: to.String(), + Sender: sender, + To: to, Amount: amount, BridgeId: bridgeId, Data: data, @@ -200,8 +200,8 @@ func NewMsgFinalizeTokenWithdrawal( outputIndex uint64, sequence uint64, withdrawalProofs [][]byte, - sender sdk.AccAddress, - receiver sdk.AccAddress, + sender string, + receiver string, amount sdk.Coin, version []byte, stateRoot []byte, @@ -212,8 +212,8 @@ func NewMsgFinalizeTokenWithdrawal( BridgeId: bridgeId, OutputIndex: outputIndex, WithdrawalProofs: withdrawalProofs, - Sender: sender.String(), - Receiver: receiver.String(), + Sender: sender, + Receiver: receiver, Sequence: sequence, Amount: amount, Version: version, @@ -278,14 +278,14 @@ func (msg MsgFinalizeTokenWithdrawal) Validate(accAddressCodec address.Codec) er // NewMsgUpdateProposer creates a new MsgUpdateProposer instance. func NewMsgUpdateProposer( - authority sdk.AccAddress, + authority string, bridgeId uint64, - newProposer sdk.AccAddress, + newProposer string, ) *MsgUpdateProposer { return &MsgUpdateProposer{ - Authority: authority.String(), + Authority: authority, BridgeId: bridgeId, - NewProposer: newProposer.String(), + NewProposer: newProposer, } } @@ -310,14 +310,14 @@ func (msg MsgUpdateProposer) Validate(accAddressCodec address.Codec) error { // NewMsgUpdateChallenger creates a new MsgUpdateChallenger instance. func NewMsgUpdateChallenger( - authority sdk.AccAddress, + authority string, bridgeId uint64, - newChallenger sdk.AccAddress, + newChallenger string, ) *MsgUpdateChallenger { return &MsgUpdateChallenger{ - Authority: authority.String(), + Authority: authority, BridgeId: bridgeId, - NewChallenger: newChallenger.String(), + NewChallenger: newChallenger, } } @@ -341,9 +341,9 @@ func (msg MsgUpdateChallenger) Validate(accAddressCodec address.Codec) error { /* MsgUpdateParams */ // NewMsgUpdateParams returns a new MsgUpdateParams instance -func NewMsgUpdateParams(authority sdk.AccAddress, params *Params) *MsgUpdateParams { +func NewMsgUpdateParams(authority string, params *Params) *MsgUpdateParams { return &MsgUpdateParams{ - Authority: authority.String(), + Authority: authority, Params: params, } }