Skip to content

Commit

Permalink
Support test-runner to submit unsigned_extrinsic (paritytech#9512)
Browse files Browse the repository at this point in the history
* support to submit unsigned_extrinsic

* format

* update comment
  • Loading branch information
zjb0807 authored Aug 7, 2021
1 parent 2b7309b commit 0c9e901
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
5 changes: 4 additions & 1 deletion bin/node/test-runner-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ mod tests {
// submit extrinsics
let alice = MultiSigner::from(Alice.public()).into_account();
let _hash = node
.submit_extrinsic(frame_system::Call::remark((b"hello world").to_vec()), alice)
.submit_extrinsic(
frame_system::Call::remark((b"hello world").to_vec()),
Some(alice),
)
.await
.unwrap();

Expand Down
29 changes: 25 additions & 4 deletions test-utils/test-runner/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ where
self.client.clone()
}

/// Return a reference to the pool.
pub fn pool(
&self,
) -> Arc<
dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
InPoolTransaction = sc_transaction_pool::Transaction<
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>,
> {
self.pool.clone()
}

/// Executes closure in an externalities provided environment.
pub fn with_state<R>(&self, closure: impl FnOnce() -> R) -> R
where
Expand Down Expand Up @@ -164,11 +181,11 @@ where
sp_externalities::set_and_run_with_externalities(&mut ext, closure)
}

/// submit some extrinsic to the node, providing the sending account.
/// submit some extrinsic to the node. if signer is None, will submit unsigned_extrinsic.
pub async fn submit_extrinsic(
&self,
call: impl Into<<T::Runtime as frame_system::Config>::Call>,
from: <T::Runtime as frame_system::Config>::AccountId,
signer: Option<<T::Runtime as frame_system::Config>::AccountId>,
) -> Result<<T::Block as BlockT>::Hash, sc_transaction_pool::error::Error>
where
<T::Block as BlockT>::Extrinsic: From<
Expand All @@ -183,8 +200,12 @@ where
>,
>,
{
let extra = self.with_state(|| T::signed_extras(from.clone()));
let signed_data = Some((from.into(), MultiSignature::Sr25519(Default::default()), extra));
let signed_data = if let Some(signer) = signer {
let extra = self.with_state(|| T::signed_extras(signer.clone()));
Some((signer.into(), MultiSignature::Sr25519(Default::default()), extra))
} else {
None
};
let ext = UncheckedExtrinsic::<
MultiAddress<
<T::Runtime as frame_system::Config>::AccountId,
Expand Down

0 comments on commit 0c9e901

Please sign in to comment.