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): make initial supply nullable #1242

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/dymensionxyz/sdk-utils/utils/uptr"

"github.com/dymensionxyz/dymension/v3/app/params"
dymnstypes "github.com/dymensionxyz/dymension/v3/x/dymns/types"
Expand Down Expand Up @@ -59,7 +60,7 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
GenesisInfo: rollapptypes.GenesisInfo{
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &rollapptypes.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand Down
3 changes: 2 additions & 1 deletion app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v4
import (
"github.com/cometbft/cometbft/crypto"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/dymensionxyz/sdk-utils/utils/uptr"
epochskeeper "github.com/osmosis-labs/osmosis/v15/x/epochs/keeper"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -231,7 +232,7 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
Base: "aden", // placeholder data
Exponent: 6, // placeholder data
},
InitialSupply: sdk.NewInt(100000), // placeholder data
InitialSupply: uptr.To(sdk.NewInt(100000)), // placeholder data
Sealed: true,
},
InitialSequencer: "*",
Expand Down
2 changes: 1 addition & 1 deletion proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ message GenesisInfo {
// initial_supply is the initial supply of the native token
string initial_supply = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
(gogoproto.nullable) = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this field mandatory? not sure why u made it nullable

];
// sealed indicates if the fields in this object are no longer updatable
bool sealed = 5;
Expand Down
4 changes: 2 additions & 2 deletions x/rollapp/client/cli/tx_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func parseGenesisInfo(cmd *cobra.Command) (types.GenesisInfo, error) {
var (
genesisInfo types.GenesisInfo
err error
ok bool
)

genesisInfo.GenesisChecksum, err = cmd.Flags().GetString(FlagGenesisChecksum)
Expand Down Expand Up @@ -104,10 +103,11 @@ func parseGenesisInfo(cmd *cobra.Command) (types.GenesisInfo, error) {
}

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

return genesisInfo, nil
Expand Down
5 changes: 3 additions & 2 deletions x/rollapp/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uptr"
"github.com/stretchr/testify/require"

keepertest "github.com/dymensionxyz/dymension/v3/testutil/keeper"
Expand All @@ -27,13 +28,13 @@ func TestInitExportGenesis(t *testing.T) {
{
RollappId: rollappID1,
GenesisInfo: types.GenesisInfo{
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
},
},
{
RollappId: rollappID2,
GenesisInfo: types.GenesisInfo{
InitialSupply: sdk.NewInt(1001),
InitialSupply: uptr.To(sdk.NewInt(1001)),
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/dymensionxyz/sdk-utils/utils/uptr"

"github.com/cometbft/cometbft/libs/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -391,5 +392,5 @@ var mockGenesisInfo = types.GenesisInfo{
Base: "aden",
Exponent: 18,
},
InitialSupply: sdk.NewInt(100000000),
InitialSupply: uptr.To(sdk.NewInt(100000000)),
}
71 changes: 65 additions & 6 deletions x/rollapp/keeper/msg_server_update_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "new",
GenesisChecksum: "new_checksum",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand All @@ -54,7 +54,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "new",
GenesisChecksum: "new_checksum",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand Down Expand Up @@ -141,11 +141,70 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
},
},
genInfoSealed: true,
expError: types.ErrGenesisInfoSealed,
}, {
name: "Update rollapp: success - no genesis info, genesis info sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
},
genInfoSealed: true,
expError: nil,
expRollapp: types.Rollapp{
RollappId: rollappId,
Owner: alice,
VmType: types.Rollapp_EVM,
Metadata: &types.RollappMetadata{},
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "OLD",
Base: "aold",
Exponent: 18,
},
Sealed: true,
},
},
}, {
name: "Update rollapp: success - no initial supply, genesis info not sealed",
update: &types.MsgUpdateRollappInformation{
Owner: alice,
RollappId: rollappId,
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: nil,
NativeDenom: &types.DenomMetadata{
Display: "OLD",
Base: "aold",
Exponent: 18,
},
},
},
genInfoSealed: false,
expError: nil,
expRollapp: types.Rollapp{
RollappId: rollappId,
Owner: alice,
VmType: types.Rollapp_EVM,
Metadata: &types.RollappMetadata{},
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "OLD",
Base: "aold",
Exponent: 18,
},
},
},
}, {
name: "Update rollapp: success - update metadata when sealed",
update: &types.MsgUpdateRollappInformation{
Expand All @@ -168,7 +227,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "OLD",
Base: "aold",
Expand Down Expand Up @@ -201,7 +260,7 @@ func (suite *RollappTestSuite) TestUpdateRollapp() {
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "old",
GenesisChecksum: "old",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "OLD",
Base: "aold",
Expand Down Expand Up @@ -239,7 +298,7 @@ func (suite *RollappTestSuite) TestCreateAndUpdateRollapp() {
GenesisInfo: types.GenesisInfo{
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
InitialSupply: sdk.NewInt(1000),
InitialSupply: uptr.To(sdk.NewInt(1000)),
NativeDenom: &types.DenomMetadata{
Display: "DEN",
Base: "aden",
Expand Down
2 changes: 1 addition & 1 deletion x/rollapp/keeper/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) CheckAndUpdateRollappFields(ctx sdk.Context, update *types.MsgUp
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}

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

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/simulation/create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/dymensionxyz/sdk-utils/utils/uptr"

"github.com/dymensionxyz/dymension/v3/simulation"
simulationtypes "github.com/dymensionxyz/dymension/v3/simulation/types"
Expand Down Expand Up @@ -49,7 +50,7 @@ func SimulateMsgCreateRollapp(ak simulationtypes.AccountKeeper, bk simulationtyp
Base: "udym",
Exponent: 6,
},
InitialSupply: sdk.NewInt(1000000000),
InitialSupply: uptr.To(sdk.NewInt(1000000000)),
},
}

Expand Down
Loading
Loading