Warm tip: This article is reproduced from stackoverflow.com, please click
rust unit-testing substrate parity-io

Fast forward time when writing Substrate Runtime Test

发布于 2020-04-09 22:54:27

I am writing an auction type application with Substrate runtime. In writing test case, how can I fast forward the blockchain time (what's retrieved from <timestamp::Module<T>>::get()) so I can reach the auction closing time and test the closing logic?

Thanks.

Questioner
Jimmy Chu
Viewed
72
Bryan Chen 2019-07-19 11:27

You can just use Timestamp::set_timestamp to change the timestamp to whatever value you want. e.g. Timestamp::set_timestamp(42);

You can check the tests for srml-timestamp for examples

https://github.com/paritytech/substrate/blob/fe7f6aff197cd68e102539a42df1134d600b4584/srml/timestamp/src/lib.rs#L368