From 26455f5532d346f125e46cb2a634c2f1e791d469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Mon, 26 Feb 2024 13:21:01 +0100 Subject: [PATCH] aggregating error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jürgen Eckel --- app/ante/check_machine_decorator.go | 10 +++++----- app/ante/check_reissuance_decorator.go | 2 +- app/ante/check_validator_decorator.go | 2 +- app/ante/deduct_fee_decorator.go | 6 +++--- app/ante/error.go | 6 ++++++ app/ante/redeem_claim_decorator.go | 2 +- errormsg/error.go | 5 +++++ testutil/sample/error.go | 5 +++++ x/asset/types/message_notarize_asset.go | 3 ++- x/asset/types/message_notarize_asset_test.go | 2 +- x/dao/types/message_distribution_request.go | 3 ++- x/dao/types/message_distribution_result.go | 3 ++- x/dao/types/message_init_pop.go | 3 ++- x/dao/types/message_init_pop_test.go | 3 ++- x/dao/types/message_mint_token.go | 3 ++- x/dao/types/message_mint_token_test.go | 3 ++- x/dao/types/message_reissue_rddl_proposal.go | 3 ++- x/dao/types/message_reissue_rddl_result.go | 3 ++- x/dao/types/message_report_pop_result.go | 3 ++- x/dao/types/message_update_params.go | 3 ++- x/dao/types/message_update_params_test.go | 3 ++- x/dao/types/messages_redeem_claim.go | 7 ++++--- x/dao/types/messages_redeem_claim_test.go | 7 ++++--- x/machine/types/message_attest_machine.go | 3 ++- x/machine/types/message_attest_machine_test.go | 3 ++- x/machine/types/message_notarize_liquid_asset.go | 3 ++- x/machine/types/message_register_trust_anchor.go | 3 ++- x/machine/types/message_register_trust_anchor_test.go | 3 ++- x/machine/types/message_update_params_test.go | 3 ++- 29 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 app/ante/error.go create mode 100644 errormsg/error.go create mode 100644 testutil/sample/error.go diff --git a/app/ante/check_machine_decorator.go b/app/ante/check_machine_decorator.go index 7bd31e1..d5499a1 100644 --- a/app/ante/check_machine_decorator.go +++ b/app/ante/check_machine_decorator.go @@ -51,21 +51,21 @@ func (cm CheckMachineDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate func (cm CheckMachineDecorator) handleNotarizeAsset(ctx sdk.Context, notarizeMsg *assettypes.MsgNotarizeAsset) (sdk.Context, error) { _, found := cm.mk.GetMachineIndexByAddress(ctx, notarizeMsg.GetCreator()) if !found { - return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, ErrorAnteContext) } return ctx, nil } func (cm CheckMachineDecorator) handleAttestMachine(ctx sdk.Context, attestMsg *machinetypes.MsgAttestMachine) (sdk.Context, error) { if attestMsg.GetCreator() != attestMsg.Machine.GetAddress() { - return ctx, errorsmod.Wrapf(machinetypes.ErrMachineIsNotCreator, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(machinetypes.ErrMachineIsNotCreator, ErrorAnteContext) } _, activated, found := cm.mk.GetTrustAnchor(ctx, attestMsg.Machine.MachineId) if !found { - return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorNotFound, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorNotFound, ErrorAnteContext) } if activated { - return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorAlreadyInUse, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorAlreadyInUse, ErrorAnteContext) } return ctx, nil } @@ -73,7 +73,7 @@ func (cm CheckMachineDecorator) handleAttestMachine(ctx sdk.Context, attestMsg * func (cm CheckMachineDecorator) handlePopResult(ctx sdk.Context, popMsg *daotypes.MsgReportPopResult) (sdk.Context, error) { _, found := cm.mk.GetMachineIndexByAddress(ctx, popMsg.GetCreator()) if !found { - return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, ErrorAnteContext) } return ctx, nil } diff --git a/app/ante/check_reissuance_decorator.go b/app/ante/check_reissuance_decorator.go index abf9fe9..8ae97bb 100644 --- a/app/ante/check_reissuance_decorator.go +++ b/app/ante/check_reissuance_decorator.go @@ -30,7 +30,7 @@ func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu isValid := cmad.dk.IsValidReissuanceProposal(ctx, MsgProposal) if !isValid { util.GetAppLogger().Info(ctx, anteHandlerTag+"rejected reissuance proposal") - return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, ErrorAnteContext) } util.GetAppLogger().Debug(ctx, anteHandlerTag+"accepted reissuance proposal: "+MsgProposal.String()) } diff --git a/app/ante/check_validator_decorator.go b/app/ante/check_validator_decorator.go index 50ec8c8..db46075 100644 --- a/app/ante/check_validator_decorator.go +++ b/app/ante/check_validator_decorator.go @@ -53,7 +53,7 @@ func (cv CheckValidatorDecorator) handleMsg(ctx sdk.Context, msg sdk.Msg) (_ sdk signer := msg.GetSigners()[0] _, found := cv.sk.GetValidator(ctx, sdk.ValAddress(signer)) if !found { - return ctx, errorsmod.Wrapf(types.ErrRestrictedMsg, "error during CheckTx or ReCheckTx") + return ctx, errorsmod.Wrapf(types.ErrRestrictedMsg, ErrorAnteContext) } return ctx, nil } diff --git a/app/ante/deduct_fee_decorator.go b/app/ante/deduct_fee_decorator.go index 4757dff..4299e6b 100644 --- a/app/ante/deduct_fee_decorator.go +++ b/app/ante/deduct_fee_decorator.go @@ -40,7 +40,7 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk authtypes.BankKeeper, fk Feegran func checkTxFee(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, ErrorTxFeeTx) } feeCoins := feeTx.GetFee() @@ -74,7 +74,7 @@ func checkTxFee(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, error) { func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { - return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, ErrorTxFeeTx) } if !simulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { @@ -102,7 +102,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.Coins) error { feeTx, ok := sdkTx.(sdk.FeeTx) if !ok { - return errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") + return errorsmod.Wrap(sdkerrors.ErrTxDecode, ErrorTxFeeTx) } if addr := dfd.accountKeeper.GetModuleAddress(authtypes.FeeCollectorName); addr == nil { diff --git a/app/ante/error.go b/app/ante/error.go new file mode 100644 index 0000000..d855dab --- /dev/null +++ b/app/ante/error.go @@ -0,0 +1,6 @@ +package ante + +var ( + ErrorAnteContext = "error during CheckTx or ReCheckTx" + ErrorTxFeeTx = "Tx must be a FeeTx" +) diff --git a/app/ante/redeem_claim_decorator.go b/app/ante/redeem_claim_decorator.go index 48e335c..64eedfb 100644 --- a/app/ante/redeem_claim_decorator.go +++ b/app/ante/redeem_claim_decorator.go @@ -52,7 +52,7 @@ func (rcd RedeemClaimDecorator) handleCreateRedeemClaim(ctx sdk.Context, msg sdk balance := rcd.bk.GetBalance(ctx, addr, params.ClaimDenom) if !balance.Amount.GTE(sdk.NewIntFromUint64(createRedeemClaimMsg.Amount)) { - return ctx, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "error during checkTx or reCheckTx") + return ctx, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, ErrorAnteContext) } return ctx, nil diff --git a/errormsg/error.go b/errormsg/error.go new file mode 100644 index 0000000..e072c20 --- /dev/null +++ b/errormsg/error.go @@ -0,0 +1,5 @@ +package errormsg + +var ( + ErrorInvalidCreator = "invalid creator address (%s)" +) diff --git a/testutil/sample/error.go b/testutil/sample/error.go new file mode 100644 index 0000000..0ae8bf4 --- /dev/null +++ b/testutil/sample/error.go @@ -0,0 +1,5 @@ +package sample + +var ( + ErrorInvalidAddress = "invalid_address" +) diff --git a/x/asset/types/message_notarize_asset.go b/x/asset/types/message_notarize_asset.go index e8b97c1..6829482 100644 --- a/x/asset/types/message_notarize_asset.go +++ b/x/asset/types/message_notarize_asset.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgNotarizeAsset = "notarize_asset" @@ -41,7 +42,7 @@ func (msg *MsgNotarizeAsset) GetSignBytes() []byte { func (msg *MsgNotarizeAsset) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/asset/types/message_notarize_asset_test.go b/x/asset/types/message_notarize_asset_test.go index 54231bf..e27ae8e 100644 --- a/x/asset/types/message_notarize_asset_test.go +++ b/x/asset/types/message_notarize_asset_test.go @@ -19,7 +19,7 @@ func TestMsgNotarizeAssetValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgNotarizeAsset{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, { diff --git a/x/dao/types/message_distribution_request.go b/x/dao/types/message_distribution_request.go index 037befc..adca660 100644 --- a/x/dao/types/message_distribution_request.go +++ b/x/dao/types/message_distribution_request.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgDistributionRequest = "distribution_request" @@ -41,7 +42,7 @@ func (msg *MsgDistributionRequest) GetSignBytes() []byte { func (msg *MsgDistributionRequest) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_distribution_result.go b/x/dao/types/message_distribution_result.go index df551ef..6870613 100644 --- a/x/dao/types/message_distribution_result.go +++ b/x/dao/types/message_distribution_result.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgDistributionResult = "distribution_result" @@ -47,7 +48,7 @@ func (msg *MsgDistributionResult) GetSignBytes() []byte { func (msg *MsgDistributionResult) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_init_pop.go b/x/dao/types/message_init_pop.go index d77911b..13f0d6d 100644 --- a/x/dao/types/message_init_pop.go +++ b/x/dao/types/message_init_pop.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgInitPop = "init_pop" @@ -44,7 +45,7 @@ func (msg *MsgInitPop) GetSignBytes() []byte { func (msg *MsgInitPop) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_init_pop_test.go b/x/dao/types/message_init_pop_test.go index 0edfcf6..604d596 100644 --- a/x/dao/types/message_init_pop_test.go +++ b/x/dao/types/message_init_pop_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgInitPop_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgInitPop{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/dao/types/message_mint_token.go b/x/dao/types/message_mint_token.go index 27b56a0..fdbb0f6 100644 --- a/x/dao/types/message_mint_token.go +++ b/x/dao/types/message_mint_token.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgMintToken = "mint_token" @@ -41,7 +42,7 @@ func (msg *MsgMintToken) GetSignBytes() []byte { func (msg *MsgMintToken) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_mint_token_test.go b/x/dao/types/message_mint_token_test.go index 0471c38..68e927f 100644 --- a/x/dao/types/message_mint_token_test.go +++ b/x/dao/types/message_mint_token_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgMintToken_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgMintToken{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/dao/types/message_reissue_rddl_proposal.go b/x/dao/types/message_reissue_rddl_proposal.go index caec459..e3718a2 100644 --- a/x/dao/types/message_reissue_rddl_proposal.go +++ b/x/dao/types/message_reissue_rddl_proposal.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgReissueRDDLProposal = "reissue_rddl_proposal" @@ -46,7 +47,7 @@ func (msg *MsgReissueRDDLProposal) GetSignBytes() []byte { func (msg *MsgReissueRDDLProposal) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_reissue_rddl_result.go b/x/dao/types/message_reissue_rddl_result.go index e1a92f8..26373d7 100644 --- a/x/dao/types/message_reissue_rddl_result.go +++ b/x/dao/types/message_reissue_rddl_result.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgReissueRDDLResult = "reissue_rddl_result" @@ -43,7 +44,7 @@ func (msg *MsgReissueRDDLResult) GetSignBytes() []byte { func (msg *MsgReissueRDDLResult) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_report_pop_result.go b/x/dao/types/message_report_pop_result.go index 4835837..72430bb 100644 --- a/x/dao/types/message_report_pop_result.go +++ b/x/dao/types/message_report_pop_result.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgReportPopResult = "report_pop_result" @@ -41,7 +42,7 @@ func (msg *MsgReportPopResult) GetSignBytes() []byte { func (msg *MsgReportPopResult) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_update_params.go b/x/dao/types/message_update_params.go index f0ffdfc..d96655a 100644 --- a/x/dao/types/message_update_params.go +++ b/x/dao/types/message_update_params.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgUpdateParams = "update_params" @@ -41,7 +42,7 @@ func (msg *MsgUpdateParams) GetSignBytes() []byte { func (msg *MsgUpdateParams) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Authority) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/message_update_params_test.go b/x/dao/types/message_update_params_test.go index 49dc88a..5d12232 100644 --- a/x/dao/types/message_update_params_test.go +++ b/x/dao/types/message_update_params_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgUpdateParams{ - Authority: "invalid_address", + Authority: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/dao/types/messages_redeem_claim.go b/x/dao/types/messages_redeem_claim.go index 78e8527..7400902 100644 --- a/x/dao/types/messages_redeem_claim.go +++ b/x/dao/types/messages_redeem_claim.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const ( @@ -51,7 +52,7 @@ func (msg *MsgCreateRedeemClaim) GetSignBytes() []byte { func (msg *MsgCreateRedeemClaim) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } @@ -97,7 +98,7 @@ func (msg *MsgUpdateRedeemClaim) GetSignBytes() []byte { func (msg *MsgUpdateRedeemClaim) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } @@ -136,7 +137,7 @@ func (msg *MsgConfirmRedeemClaim) GetSignBytes() []byte { func (msg *MsgConfirmRedeemClaim) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/dao/types/messages_redeem_claim_test.go b/x/dao/types/messages_redeem_claim_test.go index fd3b5ca..baf789e 100644 --- a/x/dao/types/messages_redeem_claim_test.go +++ b/x/dao/types/messages_redeem_claim_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgCreateRedeemClaim_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgCreateRedeemClaim{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, @@ -46,7 +47,7 @@ func TestMsgUpdateRedeemClaim_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgUpdateRedeemClaim{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, @@ -75,7 +76,7 @@ func TestMsgConfirmRedeemClaim_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgConfirmRedeemClaim{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/machine/types/message_attest_machine.go b/x/machine/types/message_attest_machine.go index 1cb31cd..745fc7a 100644 --- a/x/machine/types/message_attest_machine.go +++ b/x/machine/types/message_attest_machine.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgAttestMachine = "attest_machine" @@ -41,7 +42,7 @@ func (msg *MsgAttestMachine) GetSignBytes() []byte { func (msg *MsgAttestMachine) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/machine/types/message_attest_machine_test.go b/x/machine/types/message_attest_machine_test.go index 138957f..b34a5f4 100644 --- a/x/machine/types/message_attest_machine_test.go +++ b/x/machine/types/message_attest_machine_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgAttestMachineValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgAttestMachine{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/machine/types/message_notarize_liquid_asset.go b/x/machine/types/message_notarize_liquid_asset.go index 782198b..5a11ed8 100644 --- a/x/machine/types/message_notarize_liquid_asset.go +++ b/x/machine/types/message_notarize_liquid_asset.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgNotarizeLiquidAsset = "notarize_liquid_asset" @@ -41,7 +42,7 @@ func (msg *MsgNotarizeLiquidAsset) GetSignBytes() []byte { func (msg *MsgNotarizeLiquidAsset) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/machine/types/message_register_trust_anchor.go b/x/machine/types/message_register_trust_anchor.go index 281bfe5..ad4cf01 100644 --- a/x/machine/types/message_register_trust_anchor.go +++ b/x/machine/types/message_register_trust_anchor.go @@ -4,6 +4,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/errormsg" ) const TypeMsgRegisterTrustAnchor = "register_trust_anchor" @@ -41,7 +42,7 @@ func (msg *MsgRegisterTrustAnchor) GetSignBytes() []byte { func (msg *MsgRegisterTrustAnchor) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errormsg.ErrorInvalidCreator, err) } return nil } diff --git a/x/machine/types/message_register_trust_anchor_test.go b/x/machine/types/message_register_trust_anchor_test.go index 1e52114..9f10207 100644 --- a/x/machine/types/message_register_trust_anchor_test.go +++ b/x/machine/types/message_register_trust_anchor_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgRegisterTrustAnchor{ - Creator: "invalid_address", + Creator: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, }, diff --git a/x/machine/types/message_update_params_test.go b/x/machine/types/message_update_params_test.go index 49dc88a..5d12232 100644 --- a/x/machine/types/message_update_params_test.go +++ b/x/machine/types/message_update_params_test.go @@ -4,6 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/planetmint/planetmint-go/testutil/sample" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgUpdateParams{ - Authority: "invalid_address", + Authority: sample.ErrorInvalidAddress, }, err: sdkerrors.ErrInvalidAddress, },