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: add non-zero check of nextTokenID.Id for genesis #1276

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue
* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint
* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis

### Removed

Expand Down
3 changes: 3 additions & 0 deletions x/collection/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *collection.GenesisState) {
contractID := contractNextTokenIDs.ContractId

for _, nextTokenID := range contractNextTokenIDs.TokenIds {
if nextTokenID.Id.IsZero() {
panic("nextTokenID.Id is not supposed to be zero")
}
k.setNextTokenID(ctx, contractID, nextTokenID.ClassId, nextTokenID.Id)
}

Expand Down
15 changes: 15 additions & 0 deletions x/collection/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/collection"
)

Expand Down Expand Up @@ -28,3 +29,17 @@ func (s *KeeperTestSuite) TestImportExportGenesis() {
newGenesis := s.keeper.ExportGenesis(s.ctx)
s.Require().Equal(genesis, newGenesis)
}

func (s *KeeperTestSuite) TestShouldPanicWhenZeroNextTokenIdInGenesis() {
dontCare := "12345678"
state := &collection.GenesisState{
Params: collection.Params{},
NextTokenIds: []collection.ContractNextTokenIDs{
{ContractId: dontCare, TokenIds: []collection.NextTokenID{
{ClassId: dontCare, Id: types.NewUint(0)},
}},
},
}

s.Require().Panics(func() { s.keeper.InitGenesis(s.ctx, state) })
}
Loading