Skip to content

Commit

Permalink
fix(rollapp): make genesis info nullable (#1263)
Browse files Browse the repository at this point in the history
(cherry picked from commit 68f4a75)
  • Loading branch information
zale144 committed Sep 26, 2024
1 parent 678e567 commit dd9cddf
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 135 deletions.
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
InitialSequencer: "*",
Alias: strings.ToLower(rand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
InitialSupply: sdk.NewInt(1000),
Expand Down
2 changes: 1 addition & 1 deletion ibctesting/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *utilSuite) createRollapp(transfersEnabled bool, channelID *string) {
Telegram: "https://t.me/rolly",
X: "https://x.dymension.xyz",
},
rollapptypes.GenesisInfo{
&rollapptypes.GenesisInfo{
GenesisChecksum: "somechecksum",
Bech32Prefix: "eth",
NativeDenom: &rollapptypes.DenomMetadata{
Expand Down
4 changes: 2 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message MsgCreateRollapp {
// metadata is the rollapp metadata
RollappMetadata metadata = 13;
// genesis_info is the genesis information
GenesisInfo genesis_info = 14 [(gogoproto.nullable) = false ];
GenesisInfo genesis_info = 14 [(gogoproto.nullable) = true ];
// vm_type is the type of rollapp machine: EVM or WASM
Rollapp.VMType vm_type = 15;
}
Expand All @@ -59,7 +59,7 @@ message MsgUpdateRollappInformation {
// metadata is the rollapp metadata
RollappMetadata metadata = 5 [(gogoproto.nullable) = true ];
// genesis_info is the genesis information
GenesisInfo genesis_info = 6 [(gogoproto.nullable) = false ];
GenesisInfo genesis_info = 6 [(gogoproto.nullable) = true ];
}

message MsgUpdateRollappInformationResponse {
Expand Down
4 changes: 4 additions & 0 deletions x/denommetadata/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (im IBCModule) OnRecvPacket(
return uevent.NewErrorAcknowledgement(ctx, gerrc.ErrNotFound)
}

if im.keeper.HasDenomMetadata(ctx, ibcDenom) {
return im.IBCModule.OnRecvPacket(ctx, packet, relayer)
}

dm.Base = ibcDenom
dm.DenomUnits[0].Denom = dm.Base

Expand Down
8 changes: 6 additions & 2 deletions x/denommetadata/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,19 @@ func (m *mockIBCModule) OnRecvPacket(_ sdk.Context, p channeltypes.Packet, _ sdk
return emptyResult
}

func (m *mockIBCModule) OnAcknowledgementPacket(_ sdk.Context, _ channeltypes.Packet, ack []byte, _ sdk.AccAddress) error {
func (m *mockIBCModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) error {
return nil
}

type mockDenomMetadataKeeper struct {
hasDenomMetaData, created bool
}

func (m *mockDenomMetadataKeeper) CreateDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata) error {
func (m *mockDenomMetadataKeeper) HasDenomMetadata(sdk.Context, string) bool {
return true
}

func (m *mockDenomMetadataKeeper) CreateDenomMetadata(sdk.Context, banktypes.Metadata) error {
m.created = true
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions x/denommetadata/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"

rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

Expand All @@ -14,6 +15,7 @@ type BankKeeper interface {

type DenomMetadataKeeper interface {
CreateDenomMetadata(ctx sdk.Context, metadata types.Metadata) error
HasDenomMetadata(ctx sdk.Context, base string) bool
}

type RollappKeeper interface {
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (suite *QueryTestSuite) CreateDefaultRollapp() string {
RollappId: urand.RollappID(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (suite *KeeperTestSuite) CreateDefaultRollapp(addr sdk.AccAddress) string {
InitialSequencer: addr.String(),
Alias: strings.ToLower(tmrand.Str(7)),
VmType: rollapptypes.Rollapp_EVM,
GenesisInfo: rollapptypes.GenesisInfo{
GenesisInfo: &rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
GenesisChecksum: "checksum",
NativeDenom: &rollapptypes.DenomMetadata{
Expand Down
19 changes: 9 additions & 10 deletions x/rollapp/client/cli/tx_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,43 @@ func CmdCreateRollapp() *cobra.Command {
return cmd
}

func parseGenesisInfo(cmd *cobra.Command) (types.GenesisInfo, error) {
func parseGenesisInfo(cmd *cobra.Command) (*types.GenesisInfo, error) {
var (
genesisInfo types.GenesisInfo
genesisInfo = &types.GenesisInfo{}
err error
ok bool
)

genesisInfo.GenesisChecksum, err = cmd.Flags().GetString(FlagGenesisChecksum)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

genesisInfo.Bech32Prefix, err = cmd.Flags().GetString(FlagBech32Prefix)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

nativeDenomFlag, err := cmd.Flags().GetString(FlagNativeDenom)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

if nativeDenomFlag != "" {
genesisInfo.NativeDenom = new(types.DenomMetadata)
if err = utils.ParseJsonFromFile(nativeDenomFlag, genesisInfo.NativeDenom); err != nil {
return types.GenesisInfo{}, err
if err = utils.ParseJsonFromFile(nativeDenomFlag, &genesisInfo.NativeDenom); err != nil {
return nil, err
}
}

initialSupplyFlag, err := cmd.Flags().GetString(FlagInitialSupply)
if err != nil {
return types.GenesisInfo{}, err
return nil, err
}

if initialSupplyFlag != "" {
genesisInfo.InitialSupply, ok = sdk.NewIntFromString(initialSupplyFlag)
if !ok {
return types.GenesisInfo{}, fmt.Errorf("invalid initial supply: %s", initialSupplyFlag)
return nil, fmt.Errorf("invalid initial supply: %s", initialSupplyFlag)
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (suite *RollappTestSuite) createRollappWithCreatorAndVerify(
InitialSequencer: rollapp.GetInitialSequencer(),
VmType: types.Rollapp_EVM,
Metadata: rollapp.GetMetadata(),
GenesisInfo: rollapp.GetGenesisInfo(),
GenesisInfo: *rollapp.GetGenesisInfo(),
}
// create rollapp
createResponse, err := suite.msgServer.CreateRollapp(goCtx, &rollapp)
Expand Down Expand Up @@ -383,7 +383,7 @@ var mockRollappMetadata = types.RollappMetadata{
X: "https://x.dymension.xyz",
}

var mockGenesisInfo = types.GenesisInfo{
var mockGenesisInfo = &types.GenesisInfo{
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
NativeDenom: &types.DenomMetadata{
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/msg_server_transfer_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (suite *RollappTestSuite) TestTransferOwnership() {
expRollapp: types.Rollapp{
Owner: bob,
RollappId: rollappId,
GenesisInfo: mockGenesisInfo,
GenesisInfo: *mockGenesisInfo,
},
}, {
name: "Transfer rollapp ownership: failed, rollapp not found",
Expand Down
46 changes: 39 additions & 7 deletions x/rollapp/keeper/msg_server_update_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
InitialSequencer: initialSequencerAddress,
Metadata: &mockRollappMetadata,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "new",
GenesisChecksum: "new_checksum",
InitialSupply: sdk.NewInt(1000),
Expand Down Expand Up @@ -103,7 +103,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
RollappId: rollappId,
InitialSequencer: "",
Metadata: nil,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
GenesisChecksum: "new_checksum",
},
},
Expand All @@ -114,7 +114,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "new",
},
},
Expand All @@ -125,7 +125,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
NativeDenom: &types.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand All @@ -140,7 +140,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
InitialSupply: sdk.NewInt(1000),
},
},
Expand Down Expand Up @@ -176,6 +176,38 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
},
},
},
}, {
name: "Update rollapp: success - unsealed, update rollapp without genesis info",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
Metadata: &mockRollappMetadata,
},
rollappLaunched: false,
genInfoSealed: false,
expError: nil,
expRollapp: types.Rollapp{
RollappId: rollappId,
Owner: alice,
InitialSequencer: "",
ChannelId: "",
Frozen: false,
RegisteredDenoms: nil,
Launched: false,
VmType: types.Rollapp_EVM,
Metadata: &mockRollappMetadata,
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: sdk.NewInt(1000),
NativeDenom: types.DenomMetadata{
Display: "OLD",
Base: "aold",
Exponent: 18,
},
Sealed: false,
},
},
},
}

Expand Down Expand Up @@ -236,7 +268,7 @@ func (suite *RollappTestSuite) TestCreateAndUpdateRollapp() {
InitialSequencer: "",
Alias: "default",
VmType: types.Rollapp_EVM,
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
InitialSupply: sdk.NewInt(1000),
Expand All @@ -263,7 +295,7 @@ func (suite *RollappTestSuite) TestCreateAndUpdateRollapp() {
Owner: alice,
RollappId: rollappId,
InitialSequencer: addrInit,
GenesisInfo: types.GenesisInfo{GenesisChecksum: "checksum1"},
GenesisInfo: &types.GenesisInfo{GenesisChecksum: "checksum1"},
})
suite.Require().NoError(err)

Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/msg_server_update_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (suite *RollappTestSuite) TestUpdateStateErrLogicUnpermissioned() {
RollappId: rollappID,
Owner: alice,
InitialSequencer: sample.AccAddress(),
GenesisInfo: mockGenesisInfo,
GenesisInfo: *mockGenesisInfo,
}
suite.App.RollappKeeper.SetRollapp(suite.Ctx, rollapp)

Expand Down
24 changes: 13 additions & 11 deletions x/rollapp/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@ func (k Keeper) CheckAndUpdateRollappFields(ctx sdk.Context, update *types.MsgUp
current.InitialSequencer = update.InitialSequencer
}

if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
}
if update.GenesisInfo != nil {
if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
}

if update.GenesisInfo.Bech32Prefix != "" {
current.GenesisInfo.Bech32Prefix = update.GenesisInfo.Bech32Prefix
}
if update.GenesisInfo.Bech32Prefix != "" {
current.GenesisInfo.Bech32Prefix = update.GenesisInfo.Bech32Prefix
}

if update.GenesisInfo.NativeDenom != nil {
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}
if update.GenesisInfo.NativeDenom != nil {
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}

if !update.GenesisInfo.InitialSupply.IsNil() {
current.GenesisInfo.InitialSupply = update.GenesisInfo.InitialSupply
if !update.GenesisInfo.InitialSupply.IsNil() {
current.GenesisInfo.InitialSupply = update.GenesisInfo.InitialSupply
}
}

if update.Metadata != nil && !update.Metadata.IsEmpty() {
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/simulation/create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func SimulateMsgCreateRollapp(ak simulationtypes.AccountKeeper, bk simulationtyp
Telegram: "https://t.me/rolly",
X: "https://x.dymension.xyz",
},
GenesisInfo: types.GenesisInfo{
GenesisInfo: &types.GenesisInfo{
GenesisChecksum: "checksum",
Bech32Prefix: "bech",
NativeDenom: &types.DenomMetadata{
Expand Down
10 changes: 7 additions & 3 deletions x/rollapp/types/message_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewMsgCreateRollapp(
alias string,
vmType Rollapp_VMType,
metadata *RollappMetadata,
genesisInfo GenesisInfo,
genesisInfo *GenesisInfo,
) *MsgCreateRollapp {
return &MsgCreateRollapp{
Creator: creator,
Expand Down Expand Up @@ -50,14 +50,18 @@ func (msg *MsgCreateRollapp) GetSignBytes() []byte {
}

func (msg *MsgCreateRollapp) GetRollapp() Rollapp {
genInfo := GenesisInfo{}
if msg.GenesisInfo != nil {
genInfo = *msg.GenesisInfo
}
return NewRollapp(
msg.Creator,
msg.RollappId,
msg.InitialSequencer,
msg.VmType,
msg.Metadata,
msg.GenesisInfo,
false,
genInfo,
true,
)
}

Expand Down
Loading

0 comments on commit dd9cddf

Please sign in to comment.