mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +00:00
Fix RPC tests for machines with a high number of cores (#6021)
This commit is contained in:
@@ -30,7 +30,7 @@ use substrate_test_runtime_client::{
|
||||
DefaultTestClientBuilderExt, TestClientBuilderExt, Backend, Client,
|
||||
};
|
||||
use sc_transaction_pool::{BasicPool, FullChainApi};
|
||||
use tokio::runtime;
|
||||
use futures::{executor, compat::Future01CompatExt};
|
||||
|
||||
fn uxt(sender: AccountKeyring, nonce: u64) -> Extrinsic {
|
||||
let tx = Transfer {
|
||||
@@ -48,7 +48,6 @@ type FullTransactionPool = BasicPool<
|
||||
>;
|
||||
|
||||
struct TestSetup {
|
||||
pub runtime: runtime::Runtime,
|
||||
pub client: Arc<Client<Backend>>,
|
||||
pub keystore: BareCryptoStorePtr,
|
||||
pub pool: Arc<FullTransactionPool>,
|
||||
@@ -68,7 +67,6 @@ impl Default for TestSetup {
|
||||
None,
|
||||
).0);
|
||||
TestSetup {
|
||||
runtime: runtime::Runtime::new().expect("Failed to create runtime in test setup"),
|
||||
client,
|
||||
keystore,
|
||||
pool,
|
||||
@@ -81,7 +79,7 @@ impl TestSetup {
|
||||
Author {
|
||||
client: self.client.clone(),
|
||||
pool: self.pool.clone(),
|
||||
subscriptions: Subscriptions::new(Arc::new(self.runtime.executor())),
|
||||
subscriptions: Subscriptions::new(Arc::new(crate::testing::TaskExecutor)),
|
||||
keystore: self.keystore.clone(),
|
||||
deny_unsafe: DenyUnsafe::No,
|
||||
}
|
||||
@@ -121,16 +119,20 @@ fn submit_rich_transaction_should_not_cause_error() {
|
||||
#[test]
|
||||
fn should_watch_extrinsic() {
|
||||
//given
|
||||
let mut setup = TestSetup::default();
|
||||
let setup = TestSetup::default();
|
||||
let p = setup.author();
|
||||
|
||||
let (subscriber, id_rx, data) = jsonrpc_pubsub::typed::Subscriber::new_test("test");
|
||||
|
||||
// when
|
||||
p.watch_extrinsic(Default::default(), subscriber, uxt(AccountKeyring::Alice, 0).encode().into());
|
||||
p.watch_extrinsic(
|
||||
Default::default(),
|
||||
subscriber,
|
||||
uxt(AccountKeyring::Alice, 0).encode().into(),
|
||||
);
|
||||
|
||||
// then
|
||||
assert_eq!(setup.runtime.block_on(id_rx), Ok(Ok(1.into())));
|
||||
assert_eq!(executor::block_on(id_rx.compat()), Ok(Ok(1.into())));
|
||||
// check notifications
|
||||
let replacement = {
|
||||
let tx = Transfer {
|
||||
@@ -142,14 +144,14 @@ fn should_watch_extrinsic() {
|
||||
tx.into_signed_tx()
|
||||
};
|
||||
AuthorApi::submit_extrinsic(&p, replacement.encode().into()).wait().unwrap();
|
||||
let (res, data) = setup.runtime.block_on(data.into_future()).unwrap();
|
||||
let (res, data) = executor::block_on(data.into_future().compat()).unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
Some(r#"{"jsonrpc":"2.0","method":"test","params":{"result":"ready","subscription":1}}"#.into())
|
||||
);
|
||||
let h = blake2_256(&replacement.encode());
|
||||
assert_eq!(
|
||||
setup.runtime.block_on(data.into_future()).unwrap().0,
|
||||
executor::block_on(data.into_future().compat()).unwrap().0,
|
||||
Some(format!(r#"{{"jsonrpc":"2.0","method":"test","params":{{"result":{{"usurped":"0x{}"}},"subscription":1}}}}"#, HexDisplay::from(&h)))
|
||||
);
|
||||
}
|
||||
@@ -157,7 +159,7 @@ fn should_watch_extrinsic() {
|
||||
#[test]
|
||||
fn should_return_watch_validation_error() {
|
||||
//given
|
||||
let mut setup = TestSetup::default();
|
||||
let setup = TestSetup::default();
|
||||
let p = setup.author();
|
||||
|
||||
let (subscriber, id_rx, _data) = jsonrpc_pubsub::typed::Subscriber::new_test("test");
|
||||
@@ -166,7 +168,7 @@ fn should_return_watch_validation_error() {
|
||||
p.watch_extrinsic(Default::default(), subscriber, uxt(AccountKeyring::Alice, 179).encode().into());
|
||||
|
||||
// then
|
||||
let res = setup.runtime.block_on(id_rx).unwrap();
|
||||
let res = executor::block_on(id_rx.compat()).unwrap();
|
||||
assert!(res.is_err(), "Expected the transaction to be rejected as invalid.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user