Commit 8aa77ecd authored by asynchronous rob's avatar asynchronous rob Committed by Gav Wood
Browse files

More testnet fixes (#145)

* initialise dummy block before API calls

* test for random-seed

* revert polkadot-runtime changes
parent 49cef2ea
......@@ -153,17 +153,30 @@ impl CheckedBlockId for CheckedId {
}
}
// set up the necessary scaffolding to execute the runtime.
// set up the necessary scaffolding to execute a set of calls to the runtime.
// this creates a new block on top of the given ID and initialises it.
macro_rules! with_runtime {
($client: ident, $at: expr, $exec: expr) => {{
$client.state_at($at.block_id()).map_err(Error::from).and_then(|state| {
let parent = $at.block_id();
let header = Header {
parent_hash: $client.block_hash_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))?,
number: $client.block_number_from_id(parent)?.ok_or(ErrorKind::UnknownBlock(*parent))? + 1,
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: Default::default(),
};
$client.state_at(parent).map_err(Error::from).and_then(|state| {
let mut changes = Default::default();
let mut ext = state_machine::Ext {
overlay: &mut changes,
backend: &state,
};
::substrate_executor::with_native_environment(&mut ext, $exec).map_err(Into::into)
::substrate_executor::with_native_environment(&mut ext, || {
::runtime::Executive::initialise_block(&header);
($exec)()
}).map_err(Into::into)
})
}}
}
......@@ -196,16 +209,7 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
}
fn duty_roster(&self, at: &CheckedId) -> Result<DutyRoster> {
// duty roster can only be queried at the start of a block,
// so we create a dummy.
let id = at.block_id();
let parent_hash = self.block_hash_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))?;
let number = self.block_number_from_id(id)?.ok_or(ErrorKind::UnknownBlock(*id))? + 1;
with_runtime!(self, at, || {
::runtime::System::initialise(&number, &parent_hash, &Default::default());
::runtime::Parachains::calculate_duty_roster()
})
with_runtime!(self, at, ::runtime::Parachains::calculate_duty_roster)
}
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
......@@ -422,4 +426,12 @@ mod tests {
fn fails_to_check_id_for_unknown_block() {
assert!(client().check_id(BlockId::Number(100)).is_err());
}
#[test]
fn gets_random_seed_with_genesis() {
let client = client();
let id = client.check_id(BlockId::Number(0)).unwrap();
assert!(client.random_seed(&id).is_ok());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment