Fast forward time when writing Substrate Runtime Test

拥有回忆 提交于 2021-02-10 18:44:53

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/57104802/fast-forward-time-when-writing-substrate-runtime-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!