Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rollapp): fix validation of empty genesis info #1273

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading