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

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork committed Apr 4, 2018
1 parent 80c90a8 commit 6b7b944
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
36 changes: 32 additions & 4 deletions polkadot/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ impl<B: Backend> PolkadotApi for Client<B, NativeExecutor<LocalDispatch>>
extrinsics: extrinsics.clone(),
};

builder.initialise_block()?;

for inherent in extrinsics {
builder.apply_extrinsic(inherent)?;
}
Expand All @@ -255,6 +257,32 @@ pub struct ClientBlockBuilder<S> {
impl<S: state_machine::Backend> ClientBlockBuilder<S>
where S::Error: Into<client::error::Error>
{
// executes a extrinsic, inherent or otherwise, without appending to the list
fn initialise_block(&mut self) -> Result<()> {
let mut ext = state_machine::Ext {
overlay: &mut self.changes,
backend: &self.state,
};

let h = self.header.clone();

let result = ::substrate_executor::with_native_environment(
&mut ext,
|| runtime::Executive::initialise_block(&h),
).map_err(Into::into);

match result {
Ok(_) => {
ext.overlay.commit_prospective();
Ok(())
}
Err(e) => {
ext.overlay.discard_prospective();
Err(e)
}
}
}

// executes a extrinsic, inherent or otherwise, without appending to the list
fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
let mut ext = state_machine::Ext {
Expand Down Expand Up @@ -340,10 +368,10 @@ mod tests {
validators: validators(),
session_length: 100,
}),
council: None,
democracy: None,
parachains: None,
staking: None,
council: Some(Default::default()),
democracy: Some(Default::default()),
parachains: Some(Default::default()),
staking: Some(Default::default()),
};
::client::new_in_mem(
LocalDispatch::new(),
Expand Down
4 changes: 2 additions & 2 deletions substrate/runtime/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ impl<
/// Apply outside of the block execution function.
/// This doesn't attempt to validate anything regarding the block.
pub fn apply_extrinsic(uxt: Block::Extrinsic) {
<system::ExtrinsicIndex<System>>::put(<system::ExtrinsicIndex<System>>::get() + 1u32);

// Verify the signature is good.
let xt = match uxt.check() {
Ok(xt) => xt,
Expand All @@ -146,6 +144,8 @@ impl<

// decode parameters and dispatch
xt.apply();

<system::ExtrinsicIndex<System>>::put(<system::ExtrinsicIndex<System>>::get() + 1u32);
}

fn final_checks(header: &System::Header) {
Expand Down
2 changes: 1 addition & 1 deletion substrate/runtime/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ impl<T: Trait> Module<T> {
fn set(aux: &T::PublicAux, now: T::Value) {
assert!(aux.is_empty());
assert!(!<Self as Store>::DidUpdate::exists(), "Timestamp must be updated only once in the block");
assert!(<system::Module<T>>::extrinsic_index() == 0, "Timestamp must be first extrinsic in the block");
<Self as Store>::Now::put(now);
<Self as Store>::DidUpdate::put(true);
assert!(<system::Module<T>>::extrinsic_index() == 0, "Timestamp must be first extrinsic in the block");
}
}

Expand Down

0 comments on commit 6b7b944

Please sign in to comment.