fix tests with loop hack
This commit is contained in:
parent
2ca61151ac
commit
3669d17390
@ -28,6 +28,7 @@ mod requests;
|
||||
mod signer;
|
||||
mod signing_queue;
|
||||
|
||||
pub use self::dispatch::{Dispatcher, FullDispatcher};
|
||||
pub use self::network_settings::NetworkSettings;
|
||||
pub use self::poll_manager::PollManager;
|
||||
pub use self::poll_filter::{PollFilter, limit_logs};
|
||||
|
@ -27,7 +27,7 @@ use jsonrpc_core::Error;
|
||||
use v1::helpers::{
|
||||
errors,
|
||||
DefaultAccount,
|
||||
SigningQueue, ConfirmationPromise, ConfirmationResult, ConfirmationPayload, SignerService
|
||||
SigningQueue, ConfirmationPromise, ConfirmationResult, SignerService
|
||||
};
|
||||
use v1::helpers::dispatch::{self, Dispatcher};
|
||||
use v1::metadata::Metadata;
|
||||
|
@ -33,6 +33,7 @@ use util::{U256, H256, Uint, Address, Hashable};
|
||||
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::impls::{EthClient, SigningUnsafeClient};
|
||||
use v1::helpers::dispatch::FullDispatcher;
|
||||
use v1::metadata::Metadata;
|
||||
use v1::tests::helpers::{TestSnapshotService, TestSyncProvider, Config};
|
||||
use v1::traits::eth::Eth;
|
||||
@ -141,10 +142,11 @@ impl EthTester {
|
||||
&external_miner,
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
let dispatcher = FullDispatcher::new(Arc::downgrade(&client), Arc::downgrade(&miner_service));
|
||||
let eth_sign = SigningUnsafeClient::new(
|
||||
&client,
|
||||
&account_provider,
|
||||
&miner_service
|
||||
dispatcher,
|
||||
);
|
||||
|
||||
let mut handler = IoHandler::default();
|
||||
|
@ -34,6 +34,7 @@ use ethsync::SyncState;
|
||||
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::{Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, EthSigning, SigningUnsafeClient};
|
||||
use v1::helpers::dispatch::FullDispatcher;
|
||||
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService, TestSnapshotService};
|
||||
use v1::metadata::Metadata;
|
||||
|
||||
@ -88,7 +89,9 @@ impl EthTester {
|
||||
let external_miner = Arc::new(ExternalMiner::new(hashrates.clone()));
|
||||
let eth = EthClient::new(&client, &snapshot, &sync, &ap, &miner, &external_miner, options).to_delegate();
|
||||
let filter = EthFilterClient::new(&client, &miner).to_delegate();
|
||||
let sign = SigningUnsafeClient::new(&client, &ap, &miner).to_delegate();
|
||||
|
||||
let dispatcher = FullDispatcher::new(Arc::downgrade(&client), Arc::downgrade(&miner));
|
||||
let sign = SigningUnsafeClient::new(&ap, dispatcher).to_delegate();
|
||||
let mut io: IoHandler<Metadata> = IoHandler::default();
|
||||
io.extend_with(eth);
|
||||
io.extend_with(sign);
|
||||
|
@ -16,13 +16,16 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use jsonrpc_core::IoHandler;
|
||||
use util::{U256, Uint, Address};
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use v1::{PersonalClient, Personal, Metadata};
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use ethcore::transaction::{Action, Transaction};
|
||||
use jsonrpc_core::IoHandler;
|
||||
use util::{U256, Uint, Address};
|
||||
|
||||
use v1::{PersonalClient, Personal, Metadata};
|
||||
use v1::helpers::dispatch::FullDispatcher;
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
|
||||
struct PersonalTester {
|
||||
accounts: Arc<AccountProvider>,
|
||||
@ -50,7 +53,9 @@ fn setup() -> PersonalTester {
|
||||
let accounts = accounts_provider();
|
||||
let client = blockchain_client();
|
||||
let miner = miner_service();
|
||||
let personal = PersonalClient::new(&accounts, &client, &miner, false);
|
||||
|
||||
let dispatcher = FullDispatcher::new(Arc::downgrade(&client), Arc::downgrade(&miner));
|
||||
let personal = PersonalClient::new(&accounts, dispatcher, false);
|
||||
|
||||
let mut io = IoHandler::default();
|
||||
io.extend_with(personal.to_delegate());
|
||||
|
@ -29,6 +29,7 @@ use v1::{SignerClient, Signer};
|
||||
use v1::metadata::Metadata;
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
use v1::helpers::{SigningQueue, SignerService, FilledTransactionRequest, ConfirmationPayload};
|
||||
use v1::helpers::dispatch::FullDispatcher;
|
||||
|
||||
struct SignerTester {
|
||||
signer: Arc<SignerService>,
|
||||
@ -59,8 +60,9 @@ fn signer_tester() -> SignerTester {
|
||||
let client = blockchain_client();
|
||||
let miner = miner_service();
|
||||
|
||||
let dispatcher = FullDispatcher::new(Arc::downgrade(&client), Arc::downgrade(&miner));
|
||||
let mut io = IoHandler::default();
|
||||
io.extend_with(SignerClient::new(&accounts, &client, &miner, &signer).to_delegate());
|
||||
io.extend_with(SignerClient::new(&accounts, dispatcher, &signer).to_delegate());
|
||||
|
||||
SignerTester {
|
||||
signer: signer,
|
||||
|
@ -16,13 +16,14 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use rlp;
|
||||
|
||||
use jsonrpc_core::{IoHandler, Success};
|
||||
use v1::impls::SigningQueueClient;
|
||||
use v1::metadata::Metadata;
|
||||
use v1::traits::{EthSigning, ParitySigning, Parity};
|
||||
use v1::helpers::{SignerService, SigningQueue};
|
||||
use v1::helpers::{SignerService, SigningQueue, FullDispatcher};
|
||||
use v1::types::ConfirmationResponse;
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
use v1::tests::mocked::parity;
|
||||
@ -51,9 +52,12 @@ impl Default for SigningTester {
|
||||
let miner = Arc::new(TestMinerService::default());
|
||||
let accounts = Arc::new(AccountProvider::transient_provider());
|
||||
let mut io = IoHandler::default();
|
||||
let rpc = SigningQueueClient::new(&signer, &client, &miner, &accounts);
|
||||
|
||||
let dispatcher = FullDispatcher::new(Arc::downgrade(&client), Arc::downgrade(&miner));
|
||||
|
||||
let rpc = SigningQueueClient::new(&signer, dispatcher.clone(), &accounts);
|
||||
io.extend_with(EthSigning::to_delegate(rpc));
|
||||
let rpc = SigningQueueClient::new(&signer, &client, &miner, &accounts);
|
||||
let rpc = SigningQueueClient::new(&signer, dispatcher, &accounts);
|
||||
io.extend_with(ParitySigning::to_delegate(rpc));
|
||||
|
||||
SigningTester {
|
||||
@ -91,9 +95,17 @@ fn should_add_sign_to_queue() {
|
||||
|
||||
// then
|
||||
let promise = tester.io.handle_request(&request);
|
||||
assert_eq!(tester.signer.requests().len(), 1);
|
||||
|
||||
// the future must be polled at least once before request is queued.
|
||||
let signer = tester.signer.clone();
|
||||
::std::thread::spawn(move || loop {
|
||||
if signer.requests().len() == 1 {
|
||||
// respond
|
||||
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Signature(0.into())));
|
||||
signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Signature(0.into())));
|
||||
break
|
||||
}
|
||||
::std::thread::sleep(Duration::from_millis(100))
|
||||
});
|
||||
|
||||
let res = promise.wait().unwrap();
|
||||
assert_eq!(res, Some(response.to_owned()));
|
||||
@ -229,9 +241,17 @@ fn should_add_transaction_to_queue() {
|
||||
|
||||
// then
|
||||
let promise = tester.io.handle_request(&request);
|
||||
assert_eq!(tester.signer.requests().len(), 1);
|
||||
|
||||
// the future must be polled at least once before request is queued.
|
||||
let signer = tester.signer.clone();
|
||||
::std::thread::spawn(move || loop {
|
||||
if signer.requests().len() == 1 {
|
||||
// respond
|
||||
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SendTransaction(0.into())));
|
||||
signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SendTransaction(0.into())));
|
||||
break
|
||||
}
|
||||
::std::thread::sleep(Duration::from_millis(100))
|
||||
});
|
||||
|
||||
let res = promise.wait().unwrap();
|
||||
assert_eq!(res, Some(response.to_owned()));
|
||||
@ -296,9 +316,17 @@ fn should_add_sign_transaction_to_the_queue() {
|
||||
// then
|
||||
tester.miner.last_nonces.write().insert(address.clone(), U256::zero());
|
||||
let promise = tester.io.handle_request(&request);
|
||||
assert_eq!(tester.signer.requests().len(), 1);
|
||||
|
||||
// the future must be polled at least once before request is queued.
|
||||
let signer = tester.signer.clone();
|
||||
::std::thread::spawn(move || loop {
|
||||
if signer.requests().len() == 1 {
|
||||
// respond
|
||||
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SignTransaction(t.into())));
|
||||
signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SignTransaction(t.into())));
|
||||
break
|
||||
}
|
||||
::std::thread::sleep(Duration::from_millis(100))
|
||||
});
|
||||
|
||||
let res = promise.wait().unwrap();
|
||||
assert_eq!(res, Some(response.to_owned()));
|
||||
@ -391,12 +419,22 @@ fn should_add_decryption_to_the_queue() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x0102","id":1}"#;
|
||||
|
||||
|
||||
// then
|
||||
let promise = tester.io.handle_request(&request);
|
||||
assert_eq!(tester.signer.requests().len(), 1);
|
||||
// respond
|
||||
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Decrypt(vec![0x1, 0x2].into())));
|
||||
|
||||
// the future must be polled at least once before request is queued.
|
||||
let signer = tester.signer.clone();
|
||||
::std::thread::spawn(move || loop {
|
||||
if signer.requests().len() == 1 {
|
||||
// respond
|
||||
signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Decrypt(vec![0x1, 0x2].into())));
|
||||
break
|
||||
}
|
||||
::std::thread::sleep(Duration::from_millis(100))
|
||||
});
|
||||
|
||||
// check response: will deadlock if unsuccessful.
|
||||
let res = promise.wait().unwrap();
|
||||
assert_eq!(res, Some(response.to_owned()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user