From ba3f19ce4bb24cf201faca055b7b5285dd367cf2 Mon Sep 17 00:00:00 2001 From: Michael Tsitrin Date: Mon, 30 Sep 2024 16:07:47 +0300 Subject: [PATCH] fix validation of empty genesis info --- x/rollapp/types/message_create_rollapp_test.go | 10 ++++++++++ x/rollapp/types/rollapp.go | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/x/rollapp/types/message_create_rollapp_test.go b/x/rollapp/types/message_create_rollapp_test.go index ce9fdd803..0d8f786e9 100644 --- a/x/rollapp/types/message_create_rollapp_test.go +++ b/x/rollapp/types/message_create_rollapp_test.go @@ -243,6 +243,16 @@ func TestMsgCreateRollapp_ValidateBasic(t *testing.T) { }, err: ErrInvalidURL, }, + { + name: "no genesisInfo", + msg: MsgCreateRollapp{ + Creator: sample.AccAddress(), + InitialSequencer: sample.AccAddress(), + RollappId: "dym_100-1", + Alias: "alias", + VmType: Rollapp_EVM, + }, + }, { name: "invalid initial supply", msg: MsgCreateRollapp{ diff --git a/x/rollapp/types/rollapp.go b/x/rollapp/types/rollapp.go index e26efb188..c720bc288 100644 --- a/x/rollapp/types/rollapp.go +++ b/x/rollapp/types/rollapp.go @@ -101,7 +101,7 @@ func (r Rollapp) AllImmutableFieldsAreSet() bool { func (r Rollapp) GenesisInfoFieldsAreSet() bool { return r.GenesisInfo.GenesisChecksum != "" && - r.GenesisInfo.NativeDenom.Validate() == nil && + r.GenesisInfo.NativeDenom.IsSet() && r.GenesisInfo.Bech32Prefix != "" && !r.GenesisInfo.InitialSupply.IsNil() } @@ -121,12 +121,16 @@ func (r GenesisInfo) Validate() error { return ErrInvalidGenesisChecksum } - if err := r.NativeDenom.Validate(); err != nil { - return errors.Join(ErrInvalidNativeDenom, err) + if r.NativeDenom.IsSet() { + if err := r.NativeDenom.Validate(); err != nil { + return errorsmod.Wrap(ErrInvalidNativeDenom, err.Error()) + } } - if r.InitialSupply.IsNil() || !r.InitialSupply.IsPositive() { - return ErrInvalidInitialSupply + if !r.InitialSupply.IsNil() { + if !r.InitialSupply.IsPositive() { + return ErrInvalidInitialSupply + } } return nil @@ -171,6 +175,10 @@ func validateBech32Prefix(prefix string) error { return nil } +func (dm DenomMetadata) IsSet() bool { + return dm != DenomMetadata{} +} + func (dm DenomMetadata) Validate() error { if err := sdk.ValidateDenom(dm.Base); err != nil { return fmt.Errorf("invalid metadata base denom: %w", err)