From c3ef81ab30daf20e924a7bb1e0d8f5eeb147eaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 24 Feb 2021 21:07:03 +0100 Subject: [PATCH] Make sure we generate a valid slot in tests (#2520) Currently the first last timestamp is `0` and that leads to the first slot being `0` which is reserved for genesis. There is some debug assert in BABE that complains about this in Cumulus :D --- polkadot/node/test/client/src/block_builder.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/polkadot/node/test/client/src/block_builder.rs b/polkadot/node/test/client/src/block_builder.rs index fbca34d45a..85a1873934 100644 --- a/polkadot/node/test/client/src/block_builder.rs +++ b/polkadot/node/test/client/src/block_builder.rs @@ -62,7 +62,13 @@ impl InitPolkadotBlockBuilder for Client { let minimum_period = BasicExternalities::new_empty() .execute_with(|| polkadot_test_runtime::MinimumPeriod::get()); - let timestamp = last_timestamp + minimum_period; + let timestamp = if last_timestamp == 0 { + std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH) + .expect("Time is always after UNIX_EPOCH; qed") + .as_millis() as u64 + } else { + last_timestamp + minimum_period + }; // `SlotDuration` is a storage parameter type that requires externalities to access the value. let slot_duration = BasicExternalities::new_empty()