From e251d1cedb2ee16c2ccdc8972261337377ee2156 Mon Sep 17 00:00:00 2001 From: zjb0807 Date: Sun, 8 Aug 2021 02:52:03 +0800 Subject: [PATCH] Support test-runner to submit unsigned_extrinsic (#9512) * support to submit unsigned_extrinsic * format * update comment --- .../bin/node/test-runner-example/src/lib.rs | 5 +++- substrate/test-utils/test-runner/src/node.rs | 29 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/substrate/bin/node/test-runner-example/src/lib.rs b/substrate/bin/node/test-runner-example/src/lib.rs index f0b306db6b..cee050ba4f 100644 --- a/substrate/bin/node/test-runner-example/src/lib.rs +++ b/substrate/bin/node/test-runner-example/src/lib.rs @@ -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(); diff --git a/substrate/test-utils/test-runner/src/node.rs b/substrate/test-utils/test-runner/src/node.rs index 83fc236813..32b8bc5206 100644 --- a/substrate/test-utils/test-runner/src/node.rs +++ b/substrate/test-utils/test-runner/src/node.rs @@ -130,6 +130,23 @@ where self.client.clone() } + /// Return a reference to the pool. + pub fn pool( + &self, + ) -> Arc< + dyn TransactionPool< + Block = ::Block, + Hash = <::Block as BlockT>::Hash, + Error = sc_transaction_pool::error::Error, + InPoolTransaction = sc_transaction_pool::Transaction< + <::Block as BlockT>::Hash, + <::Block as BlockT>::Extrinsic, + >, + >, + > { + self.pool.clone() + } + /// Executes closure in an externalities provided environment. pub fn with_state(&self, closure: impl FnOnce() -> R) -> R where @@ -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<::Call>, - from: ::AccountId, + signer: Option<::AccountId>, ) -> Result<::Hash, sc_transaction_pool::error::Error> where ::Extrinsic: From< @@ -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< ::AccountId,