Skip to content

Commit

Permalink
fix: Update ctx BlockTime for simulations (cosmos#10467)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkneeland-figure committed Feb 1, 2022
1 parent d7c2138 commit 8d111fb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions types/simulation/rand_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8d111fb

Please sign in to comment.