Skip to content

Commit

Permalink
fix: add non-zero check of nextTokenID.Id for genesis (#1276)
Browse files Browse the repository at this point in the history
* fix: add non-zero check of nextTokenID.Id for genesis

* chore: add testcase

* chore: update changelog

* chore: move validation logic to validate function

* chore: add testcase

(cherry picked from commit 47a5e9f)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jaeseung-bae authored and mergify[bot] committed Mar 15, 2024
1 parent cb6669c commit 00ecc87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

### Bug Fixes
<<<<<<< HEAD
=======
* 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/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis
>>>>>>> 47a5e9fec (fix: add non-zero check of nextTokenID.Id for genesis (#1276))
### Removed

Expand Down
7 changes: 5 additions & 2 deletions x/collection/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func ValidateGenesis(data GenesisState) error {
if len(contractNextTokenIDs.TokenIds) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("next token ids cannot be empty")
}
for _, nextTokenIDs := range contractNextTokenIDs.TokenIds {
if err := ValidateClassID(nextTokenIDs.ClassId); err != nil {
for _, nextTokenID := range contractNextTokenIDs.TokenIds {
if nextTokenID.Id.IsZero() {
return sdkerrors.ErrInvalidRequest.Wrap("nextTokenID.Id is not supposed to be zero")
}
if err := ValidateClassID(nextTokenID.ClassId); err != nil {
return err
}
}
Expand Down
11 changes: 11 additions & 0 deletions x/collection/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,17 @@ func TestValidateGenesis(t *testing.T) {
},
false,
},
"should throw error when next token id is zero in genesis": {
&collection.GenesisState{
Params: collection.Params{},
NextTokenIds: []collection.ContractNextTokenIDs{
{ContractId: "deadbeef", TokenIds: []collection.NextTokenID{
{ClassId: "deadbeef", Id: sdk.NewUint(0)},
}},
},
},
false,
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit 00ecc87

Please sign in to comment.