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: added new constructor for genesis supply that matches upstream #312

Merged
merged 2 commits into from
Aug 16, 2022
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
4 changes: 2 additions & 2 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.GenesisSupplyOffset{})
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down Expand Up @@ -180,7 +180,7 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
totalSupply = totalSupply.Add(b.Coins...)
}

bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.GenesisSupplyOffset{})
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand Down
3 changes: 1 addition & 2 deletions x/bank/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
k.GetAccountsBalances(ctx),
totalSupply,
k.GetAllDenomMetaData(ctx),
k.getGenesisSupplyOffsets(ctx),
)
).WithSupplyOffsets(k.getGenesisSupplyOffsets(ctx))
}
6 changes: 3 additions & 3 deletions x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ func (suite *IntegrationTestSuite) TestTotalSupply() {
}{
{
"calculation NOT matching genesis Supply field",
types.NewGenesisState(defaultGenesis.Params, balances, sdk.NewCoins(sdk.NewCoin("wrongcoin", sdk.NewInt(1))), defaultGenesis.DenomMetadata, defaultGenesis.SupplyOffsets),
types.NewGenesisState(defaultGenesis.Params, balances, sdk.NewCoins(sdk.NewCoin("wrongcoin", sdk.NewInt(1))), defaultGenesis.DenomMetadata).WithSupplyOffsets(defaultGenesis.SupplyOffsets),
nil, true, "genesis supply is incorrect, expected 1wrongcoin, got 21barcoin,11foocoin",
},
{
"calculation matches genesis Supply field",
types.NewGenesisState(defaultGenesis.Params, balances, totalSupply, defaultGenesis.DenomMetadata, defaultGenesis.SupplyOffsets),
types.NewGenesisState(defaultGenesis.Params, balances, totalSupply, defaultGenesis.DenomMetadata).WithSupplyOffsets(defaultGenesis.SupplyOffsets),
totalSupply, false, "",
},
{
"calculation is correct, empty genesis Supply field",
types.NewGenesisState(defaultGenesis.Params, balances, nil, defaultGenesis.DenomMetadata, defaultGenesis.SupplyOffsets),
types.NewGenesisState(defaultGenesis.Params, balances, nil, defaultGenesis.DenomMetadata).WithSupplyOffsets(defaultGenesis.SupplyOffsets),
totalSupply, false, "",
},
}
Expand Down
12 changes: 9 additions & 3 deletions x/bank/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,25 @@ func (gs GenesisState) Validate() error {

// NewGenesisState creates a new genesis state.
func NewGenesisState(params Params, balances []Balance, supply sdk.Coins,
denomMetaData []Metadata, supplyOffsets []GenesisSupplyOffset) *GenesisState {
denomMetaData []Metadata) *GenesisState {
return &GenesisState{
Params: params,
Balances: balances,
Supply: supply,
DenomMetadata: denomMetaData,
SupplyOffsets: supplyOffsets,
SupplyOffsets: []GenesisSupplyOffset{},
}
}

// WithSupplyOffsets adds supply offsets to a genesis state
func (gs *GenesisState) WithSupplyOffsets(supplyOffsets []GenesisSupplyOffset) *GenesisState {
gs.SupplyOffsets = supplyOffsets
return gs
}

// DefaultGenesisState returns a default bank module genesis state.
func DefaultGenesisState() *GenesisState {
return NewGenesisState(DefaultParams(), []Balance{}, sdk.Coins{}, []Metadata{}, []GenesisSupplyOffset{})
return NewGenesisState(DefaultParams(), []Balance{}, sdk.Coins{}, []Metadata{})
}

// GetGenesisStateFromAppState returns x/bank GenesisState given raw application
Expand Down