Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

More testnet fixes #145

Merged
merged 3 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
38 changes: 25 additions & 13 deletions polkadot/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}}
}
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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());
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.