From 9fa67c553692c3602177f22b50aeef159458d302 Mon Sep 17 00:00:00 2001 From: Trevor Miller Date: Wed, 6 May 2026 13:17:57 -0400 Subject: [PATCH] test: fix TestGenesis_ValidTokenIdsPreserved + TestGetKnownGoodCollectionId MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both tests authored token-id shapes that the chain has never accepted. keeper.CreateTokens (tokens.go:23) requires ValidTokenIds to be a single contiguous range starting from 1 — the constraint dates back to the v0.47 fork in 2023. These tests came in later (badges→tokenization rename and the AI-generated genesis test sweep) without ever being run against the production code path. - simulation/helpers.go GetOrCreateCollection: was building ValidTokenIds with GetBoundedTimelineTimes, which returns randomly-positioned ranges appropriate for timeline-time fields (TransferTimes, OwnershipTimes) but not for token IDs. Replaced with [{Start:1, End:1+rand}]. - ai_test genesis: was hardcoding two ranges with a gap ([1..50], [100..200]). Replaced with single [1..200] range. Co-Authored-By: Claude Opus 4.7 (1M context) --- x/tokenization/ai_test/unit/genesis/genesis_test.go | 5 +++-- x/tokenization/simulation/helpers.go | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/x/tokenization/ai_test/unit/genesis/genesis_test.go b/x/tokenization/ai_test/unit/genesis/genesis_test.go index db6b55cb..ee264e48 100644 --- a/x/tokenization/ai_test/unit/genesis/genesis_test.go +++ b/x/tokenization/ai_test/unit/genesis/genesis_test.go @@ -348,9 +348,10 @@ func (suite *GenesisTestSuite) TestGenesis_ValidTokenIdsPreserved() { DefaultBalances: &types.UserBalanceStore{ Balances: []*types.Balance{}, }, + // Token IDs must be sequential starting from 1 (see keeper.CreateTokens). + // A single contiguous range satisfies that; multi-range with a gap does not. ValidTokenIds: []*types.UintRange{ - {Start: sdkmath.NewUint(1), End: sdkmath.NewUint(50)}, - {Start: sdkmath.NewUint(100), End: sdkmath.NewUint(200)}, + {Start: sdkmath.NewUint(1), End: sdkmath.NewUint(200)}, }, CollectionPermissions: &types.CollectionPermissions{}, Manager: suite.Manager, diff --git a/x/tokenization/simulation/helpers.go b/x/tokenization/simulation/helpers.go index 0494d37f..86354bba 100644 --- a/x/tokenization/simulation/helpers.go +++ b/x/tokenization/simulation/helpers.go @@ -498,8 +498,13 @@ func GetOrCreateCollection(ctx sdk.Context, k *keeper.Keeper, creator string, r return collectionId, nil } - // Create a minimal valid collection - validTokenIds := GetBoundedTimelineTimes(r, 1, MinTimelineRange, MaxTimelineRange) + // Create a minimal valid collection. + // Token IDs must be sequential starting from 1 (see keeper.CreateTokens). + // `GetBoundedTimelineTimes` produces randomly-positioned ranges, which + // is correct for timeline-time fields but invalid for ValidTokenIds. + validTokenIds := []*types.UintRange{ + {Start: sdkmath.NewUint(1), End: sdkmath.NewUint(uint64(1 + r.Intn(1000)))}, + } collectionPermissions := GetRandomCollectionPermissions(r, accs) collectionMetadata := &types.CollectionMetadata{