diff --git a/CHANGELOG.md b/CHANGELOG.md index 535c744cfb26..73235a201b9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -152,6 +152,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#10239](https://github.com/cosmos/cosmos-sdk/pull/10239) Fixed x/bank/044 migrateDenomMetadata. * (x/upgrade) [\#10189](https://github.com/cosmos/cosmos-sdk/issues/10189) Removed potential sources of non-determinism in upgrades * [\#10258](https://github.com/cosmos/cosmos-sdk/issues/10258) Fixes issue related to segmentaiton fault on mac m1 arm64 +* [\#10466](https://github.com/cosmos/cosmos-sdk/issues/10466) Fixes error with simulation tests when genesis start time is randomly created after the year 2262 ### State Machine Breaking diff --git a/types/simulation/rand_util.go b/types/simulation/rand_util.go index 84cd4492c8a7..10926f0a132d 100644 --- a/types/simulation/rand_util.go +++ b/types/simulation/rand_util.go @@ -86,9 +86,16 @@ func RandomDecAmount(r *rand.Rand, max sdk.Dec) sdk.Dec { // RandTimestamp generates a random timestamp func RandTimestamp(r *rand.Rand) time.Time { - // json.Marshal breaks for timestamps greater with year greater than 9999 - unixTime := r.Int63n(253373529600) - return time.Unix(unixTime, 0) + // json.Marshal breaks for timestamps with year greater than 9999 + // UnixNano breaks with year greater than 2262 + start := time.Date(2062, time.Month(1), 1, 1, 1, 1, 1, time.UTC).UnixMilli() + + // Calculate a random amount of time in seconds between 0 and 200 years + unixTime := r.Int63n(60*60*24*365*200) * 1000 // convert to milliseconds + + // Get milliseconds for a time between Jan 1, 2062 and Jan 1, 2262 + rtime := time.UnixMilli(start + unixTime).UnixMilli() / 1000 + return time.Unix(rtime, 0) } // RandIntBetween returns a random int between two numbers inclusively.