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 (backport #1276) #1282

Merged
merged 5 commits into from
Mar 19, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* (x/auth) [#1281](https://github.com/Finschia/finschia-sdk/pull/1281) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. (backport #1274)
* (x/foundation) [\#1283](https://github.com/Finschia/finschia-sdk/pull/1283) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic (backport #1277)
* (x/collection) [\#1282](https://github.com/Finschia/finschia-sdk/pull/1282) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis (backport #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 @@
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 {

Check warning on line 72 in x/collection/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/collection/genesis.go#L72

Added line #L72 was not covered by tests
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
Loading