Skip to content

Commit

Permalink
fix(rollapp): fix validation of empty genesis info (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Sep 30, 2024
1 parent a028ec2 commit d85ca7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 10 additions & 0 deletions x/rollapp/types/message_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
18 changes: 13 additions & 5 deletions x/rollapp/types/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d85ca7d

Please sign in to comment.