Skip to content

Commit

Permalink
fix(rollapp): genesisState of rollapp is non-nullable struct (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Mar 27, 2024
1 parent f7c6870 commit 13b381d
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 154 deletions.
34 changes: 17 additions & 17 deletions ibctesting/rollapp_genesis_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {

cases := []struct {
name string
gensisState *types.RollappGenesisState
gensisState types.RollappGenesisState
msg *types.MsgRollappGenesisEvent
deployerParams []types.DeployerParams
malleate func()
Expand All @@ -59,8 +59,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
}{
{
name: "successful rollapp genesis event",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -76,8 +76,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "invalid rollapp genesis event - genesis event already triggered",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -93,8 +93,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "invalid rollapp genesis event - unauthorized address",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -110,8 +110,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "invalid rollapp genesis event - rollapp doesn't exist",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -127,8 +127,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "invalid rollapp genesis event - channel doesn't exist",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -144,8 +144,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "invalid rollapp genesis event - channel id doesn't match chain id",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand All @@ -161,8 +161,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "failed rollapp genesis event - error minting coins",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: ""},
},
IsGenesisEvent: false,
Expand All @@ -178,8 +178,8 @@ func (suite *RollappGenesisTokenTestSuite) TestTriggerGenesisEvent() {
},
{
name: "failed rollapp genesis event - error registering denom metadata",
gensisState: &types.RollappGenesisState{
GenesisAccounts: []types.GenesisAccount{
gensisState: types.RollappGenesisState{
GenesisAccounts: []*types.GenesisAccount{
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(350))},
{Address: apptesting.CreateRandomAccounts(1)[0].String(), Amount: sdk.NewCoin(rollappDenom, sdk.NewInt(140))},
},
Expand Down
2 changes: 1 addition & 1 deletion ibctesting/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (suite *IBCTestUtilSuite) GenesisEvent(chainID, channelID string) {
// add genesis state to rollapp
rollapp, found := app.RollappKeeper.GetRollapp(suite.hubChain.GetContext(), chainID)
suite.Require().True(found)
rollapp.GenesisState = &rollapptypes.RollappGenesisState{}
rollapp.GenesisState = rollapptypes.RollappGenesisState{}
app.RollappKeeper.SetRollapp(suite.hubChain.GetContext(), rollapp)

msgGenesisEvent := rollapptypes.NewMsgRollappGenesisEvent(
Expand Down
4 changes: 2 additions & 2 deletions proto/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ message GenesisAccount {
// RollappGenesisState is a partial repr of the state the hub can expect the rollapp to be in upon genesis
message RollappGenesisState {
// genesis_accounts is a list of token allocations
repeated GenesisAccount genesis_accounts = 1 [(gogoproto.nullable) = false];
repeated GenesisAccount genesis_accounts = 1;
// is_genesis_event is a boolean that indicates if the genesis event has occured
bool is_genesis_event = 2;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ message Rollapp {
// tokenMetadata is a list of TokenMetadata that are registered on this rollapp
repeated TokenMetadata tokenMetadata = 9;
// genesis_state is a partial repr of the state the hub can expect the rollapp to be in upon genesis
RollappGenesisState genesis_state = 10;
RollappGenesisState genesis_state = 10 [(gogoproto.nullable) = false];
// channel_id will be set to the canonical IBC channel of the rollapp.
string channel_id = 11;
// frozen is a boolean that indicates if the rollapp is frozen.
Expand Down
5 changes: 1 addition & 4 deletions proto/dymension/rollapp/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ message MsgCreateRollapp {
// metadata provides the client information for all the registered tokens.
repeated TokenMetadata metadatas = 8 [(gogoproto.nullable) = false];
// genesis_accounts for the rollapp on the hub
repeated GenesisAccount genesis_accounts = 10 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "genesis_accounts"
];
repeated GenesisAccount genesis_accounts = 9 [(gogoproto.nullable) = false];
}

message MsgCreateRollappResponse {
Expand Down
7 changes: 2 additions & 5 deletions x/rollapp/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {

// TriggerRollappGenesisEvent triggers the genesis event for the rollapp.
func (k Keeper) TriggerRollappGenesisEvent(ctx sdk.Context, rollapp types.Rollapp) error {
// Validate it hasn't been triggered yet and the gensis event exist
switch {
case rollapp.GenesisState == nil:
return types.ErrGenesisEventNotDefined
case rollapp.GenesisState.IsGenesisEvent:
// Validate it hasn't been triggered yet
if rollapp.GenesisState.IsGenesisEvent {
return types.ErrGenesisEventAlreadyTriggered
}

Expand Down
16 changes: 6 additions & 10 deletions x/rollapp/types/message_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ func (msg *MsgCreateRollapp) GetSignBytes() []byte {

func (msg *MsgCreateRollapp) GetRollapp() Rollapp {
// Build the genesis state from the genesis accounts
var rollappGenesisState *RollappGenesisState
if len(msg.GenesisAccounts) > 0 {
rollappGenesisState = &RollappGenesisState{
GenesisAccounts: msg.GenesisAccounts,
IsGenesisEvent: false,
}
rollappGenesisState := RollappGenesisState{
IsGenesisEvent: false,
}
rollappGenesisState.GenesisAccounts = make([]*GenesisAccount, len(msg.GenesisAccounts))
for i := range msg.GenesisAccounts {
rollappGenesisState.GenesisAccounts[i] = &msg.GenesisAccounts[i]
}

// copy TokenMetadata
metadata := make([]*TokenMetadata, len(msg.Metadatas))
for i := range msg.Metadatas {
metadata[i] = &msg.Metadatas[i]
Expand All @@ -65,8 +63,6 @@ func (msg *MsgCreateRollapp) GetRollapp() Rollapp {

func (msg *MsgCreateRollapp) ValidateBasic() error {
rollapp := msg.GetRollapp()

// validate the basics fields
if err := rollapp.ValidateBasic(); err != nil {
return err
}
Expand Down
12 changes: 5 additions & 7 deletions x/rollapp/types/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func NewRollapp(creator string, rollappId string, maxSequencers uint64, permissionedAddresses []string,
metadatas []*TokenMetadata, genesisAccounts *RollappGenesisState,
metadatas []*TokenMetadata, genesisAccounts RollappGenesisState,
) Rollapp {
return Rollapp{
RollappId: rollappId,
Expand Down Expand Up @@ -67,12 +67,10 @@ func (r Rollapp) ValidateBasic() error {
}

// genesisAccounts address validation
if r.GenesisState != nil {
for _, acc := range r.GenesisState.GenesisAccounts {
_, err := sdk.AccAddressFromBech32(acc.Address)
if err != nil {
return errorsmod.Wrapf(err, "invalid genesis account address (%s)", acc.Address)
}
for _, acc := range r.GenesisState.GenesisAccounts {
_, err := sdk.AccAddressFromBech32(acc.Address)
if err != nil {
return errorsmod.Wrapf(err, "invalid genesis account address (%s)", acc.Address)
}
}

Expand Down
Loading

0 comments on commit 13b381d

Please sign in to comment.