Asynchronous RPC support (#2017)
* Async RPC * Limiting number of transactions in queue * Fixing tests * Bumping serde and jsonrpc-core * serde updated to 0.8 * fixed failing tests * Bumping ipc server * Fixing API for endpoints * Experimenting with tests without --release mode
This commit is contained in:
committed by
Arkadiy Paronyan
parent
ca03cfa58a
commit
b4f3c4bd7a
@@ -157,7 +157,7 @@ fn eth_get_balance() {
|
||||
"id": 1
|
||||
}"#;
|
||||
let res_latest = r#"{"jsonrpc":"2.0","result":"0x09","id":1}"#.to_owned();
|
||||
assert_eq!(tester.handler.handle_request(req_latest).unwrap(), res_latest);
|
||||
assert_eq!(tester.handler.handle_request_sync(req_latest).unwrap(), res_latest);
|
||||
|
||||
// non-existant account
|
||||
let req_new_acc = r#"{
|
||||
@@ -168,7 +168,7 @@ fn eth_get_balance() {
|
||||
}"#;
|
||||
|
||||
let res_new_acc = r#"{"jsonrpc":"2.0","result":"0x00","id":3}"#.to_owned();
|
||||
assert_eq!(tester.handler.handle_request(req_new_acc).unwrap(), res_new_acc);
|
||||
assert_eq!(tester.handler.handle_request_sync(req_new_acc).unwrap(), res_new_acc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -183,7 +183,7 @@ fn eth_block_number() {
|
||||
}"#;
|
||||
|
||||
let res_number = r#"{"jsonrpc":"2.0","result":"0x20","id":1}"#.to_owned();
|
||||
assert_eq!(tester.handler.handle_request(req_number).unwrap(), res_number);
|
||||
assert_eq!(tester.handler.handle_request_sync(req_number).unwrap(), res_number);
|
||||
}
|
||||
|
||||
// a frontier-like test with an expanded gas limit and balance on known account.
|
||||
@@ -299,7 +299,7 @@ fn eth_transaction_count() {
|
||||
|
||||
let res_before = r#"{"jsonrpc":"2.0","result":"0x00","id":15}"#;
|
||||
|
||||
assert_eq!(tester.handler.handle_request(&req_before).unwrap(), res_before);
|
||||
assert_eq!(tester.handler.handle_request_sync(&req_before).unwrap(), res_before);
|
||||
|
||||
let req_send_trans = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
@@ -315,7 +315,7 @@ fn eth_transaction_count() {
|
||||
}"#;
|
||||
|
||||
// dispatch the transaction.
|
||||
tester.handler.handle_request(&req_send_trans).unwrap();
|
||||
tester.handler.handle_request_sync(&req_send_trans).unwrap();
|
||||
|
||||
// we have submitted the transaction -- but this shouldn't be reflected in a "latest" query.
|
||||
let req_after_latest = r#"{
|
||||
@@ -327,7 +327,7 @@ fn eth_transaction_count() {
|
||||
|
||||
let res_after_latest = r#"{"jsonrpc":"2.0","result":"0x00","id":17}"#;
|
||||
|
||||
assert_eq!(&tester.handler.handle_request(&req_after_latest).unwrap(), res_after_latest);
|
||||
assert_eq!(&tester.handler.handle_request_sync(&req_after_latest).unwrap(), res_after_latest);
|
||||
|
||||
// the pending transactions should have been updated.
|
||||
let req_after_pending = r#"{
|
||||
@@ -339,7 +339,7 @@ fn eth_transaction_count() {
|
||||
|
||||
let res_after_pending = r#"{"jsonrpc":"2.0","result":"0x01","id":18}"#;
|
||||
|
||||
assert_eq!(&tester.handler.handle_request(&req_after_pending).unwrap(), res_after_pending);
|
||||
assert_eq!(&tester.handler.handle_request_sync(&req_after_pending).unwrap(), res_after_pending);
|
||||
}
|
||||
|
||||
fn verify_transaction_counts(name: String, chain: BlockChain) {
|
||||
@@ -400,12 +400,12 @@ fn verify_transaction_counts(name: String, chain: BlockChain) {
|
||||
let number = b.header_view().number();
|
||||
|
||||
let (req, res) = by_hash(hash, count, &mut id);
|
||||
assert_eq!(tester.handler.handle_request(&req), Some(res));
|
||||
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
||||
|
||||
// uncles can share block numbers, so skip them.
|
||||
if tester.client.block_hash(BlockID::Number(number)) == Some(hash) {
|
||||
let (req, res) = by_number(number, count, &mut id);
|
||||
assert_eq!(tester.handler.handle_request(&req), Some(res));
|
||||
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,7 +415,7 @@ fn starting_nonce_test() {
|
||||
let tester = EthTester::from_spec(Spec::load(POSITIVE_NONCE_SPEC));
|
||||
let address = Address::from(10);
|
||||
|
||||
let sample = tester.handler.handle_request(&(r#"
|
||||
let sample = tester.handler.handle_request_sync(&(r#"
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_getTransactionCount",
|
||||
|
||||
@@ -97,7 +97,7 @@ fn rpc_eth_protocol_version() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_protocolVersion", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"63","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -107,7 +107,7 @@ fn rpc_eth_syncing() {
|
||||
let tester = EthTester::default();
|
||||
|
||||
let false_res = r#"{"jsonrpc":"2.0","result":false,"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request(request), Some(false_res.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(false_res.to_owned()));
|
||||
|
||||
{
|
||||
let mut status = tester.sync.status.write();
|
||||
@@ -123,7 +123,7 @@ fn rpc_eth_syncing() {
|
||||
}
|
||||
|
||||
let true_res = r#"{"jsonrpc":"2.0","result":{"currentBlock":"0x03e8","highestBlock":"0x09c4","startingBlock":"0x00"},"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request(request), Some(true_res.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(true_res.to_owned()));
|
||||
|
||||
{
|
||||
// finish "syncing"
|
||||
@@ -133,7 +133,7 @@ fn rpc_eth_syncing() {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(false_res.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(false_res.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -146,7 +146,7 @@ fn rpc_eth_hashrate() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_hashrate", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xfffc","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -163,7 +163,7 @@ fn rpc_eth_submit_hashrate() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.hashrates.lock().get(&H256::from("0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c")).cloned().unwrap().1,
|
||||
U256::from(0x500_000));
|
||||
}
|
||||
@@ -188,7 +188,7 @@ fn rpc_eth_sign() {
|
||||
}"#;
|
||||
let res = r#"{"jsonrpc":"2.0","result":""#.to_owned() + &format!("0x{}", signed) + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(&req), Some(res));
|
||||
assert_eq!(tester.io.handle_request_sync(&req), Some(res));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -203,13 +203,13 @@ fn rpc_eth_author() {
|
||||
"id": 1
|
||||
}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(req), Some(make_res(Address::zero())));
|
||||
assert_eq!(tester.io.handle_request_sync(req), Some(make_res(Address::zero())));
|
||||
|
||||
for i in 0..20 {
|
||||
let addr = tester.accounts_provider.new_account(&format!("{}", i)).unwrap();
|
||||
tester.miner.set_author(addr.clone());
|
||||
|
||||
assert_eq!(tester.io.handle_request(req), Some(make_res(addr)));
|
||||
assert_eq!(tester.io.handle_request_sync(req), Some(make_res(addr)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ fn rpc_eth_mining() {
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_mining", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":false,"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -228,7 +228,7 @@ fn rpc_eth_gas_price() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_gasPrice", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x04a817c800","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -239,7 +239,7 @@ fn rpc_eth_accounts() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_accounts", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":[""#.to_owned() + &format!("0x{:?}", address) + r#""],"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -250,7 +250,7 @@ fn rpc_eth_block_number() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x0a","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -266,7 +266,7 @@ fn rpc_eth_balance() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x05","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -286,7 +286,7 @@ fn rpc_eth_balance_pending() {
|
||||
// miner.
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x00","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -302,7 +302,7 @@ fn rpc_eth_storage_at() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000007","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -315,7 +315,7 @@ fn rpc_eth_transaction_count() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x00","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -328,7 +328,7 @@ fn rpc_eth_block_transaction_count_by_hash() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -341,7 +341,7 @@ fn rpc_eth_transaction_count_by_number() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x00","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -354,7 +354,7 @@ fn rpc_eth_transaction_count_by_number_pending() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x01","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -375,7 +375,7 @@ fn rpc_eth_pending_transaction_by_hash() {
|
||||
"params": ["0x0000000000000000000000000000000000000000000000000000000000000000"],
|
||||
"id": 1
|
||||
}"#;
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ fn rpc_eth_uncle_count_by_block_hash() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -402,7 +402,7 @@ fn rpc_eth_uncle_count_by_block_number() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x00","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -418,7 +418,7 @@ fn rpc_eth_code() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff21","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -453,7 +453,7 @@ fn rpc_eth_call_latest() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x1234ff","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -488,7 +488,7 @@ fn rpc_eth_call() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x1234ff","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -522,7 +522,7 @@ fn rpc_eth_call_default_block() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x1234ff","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -557,7 +557,7 @@ fn rpc_eth_estimate_gas() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff35","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -591,7 +591,7 @@ fn rpc_eth_estimate_gas_default_block() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff35","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -625,7 +625,7 @@ fn rpc_eth_send_transaction() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response));
|
||||
|
||||
tester.miner.last_nonces.write().insert(address.clone(), U256::zero());
|
||||
|
||||
@@ -642,7 +642,7 @@ fn rpc_eth_send_transaction() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response));
|
||||
}
|
||||
#[test]
|
||||
fn rpc_eth_send_transaction_with_bad_to() {
|
||||
@@ -663,7 +663,7 @@ fn rpc_eth_send_transaction_with_bad_to() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.into()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
}
|
||||
|
||||
|
||||
@@ -685,7 +685,7 @@ fn rpc_eth_send_transaction_error() {
|
||||
}"#;
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32020,"message":"Your account is locked. Unlock the account via CLI, personal_unlockAccount or use Trusted Signer.","data":"NotUnlocked"},"id":1}"#;
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.into()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -718,7 +718,7 @@ fn rpc_eth_send_raw_transaction() {
|
||||
|
||||
let res = r#"{"jsonrpc":"2.0","result":""#.to_owned() + &format!("0x{:?}", t.hash()) + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(&req), Some(res));
|
||||
assert_eq!(tester.io.handle_request_sync(&req), Some(res));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -760,7 +760,7 @@ fn rpc_eth_transaction_receipt() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","data":"0x","logIndex":"0x01","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","type":"mined"}],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00"},"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -775,7 +775,7 @@ fn rpc_eth_transaction_receipt_null() {
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
// These tests are incorrect: their output is undefined as long as eth_getCompilers is [].
|
||||
@@ -788,7 +788,7 @@ fn rpc_eth_compilers() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@@ -797,7 +797,7 @@ fn rpc_eth_compile_lll() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_compileLLL", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@@ -806,7 +806,7 @@ fn rpc_eth_compile_solidity() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_compileSolidity", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@@ -815,7 +815,7 @@ fn rpc_eth_compile_serpent() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_compileSerpent", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(EthTester::default().io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -826,7 +826,7 @@ fn rpc_get_work_returns_no_work_if_cant_mine() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32001,"message":"Still syncing.","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -837,7 +837,7 @@ fn rpc_get_work_returns_correct_work_package() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":["0x3bbe93f74e7b97ae00784aeff8819c5cb600dd87e8b282a5d3446f3f871f0347","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}"#;
|
||||
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -851,7 +851,7 @@ fn rpc_get_work_should_not_return_block_number() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":["0x3bbe93f74e7b97ae00784aeff8819c5cb600dd87e8b282a5d3446f3f871f0347","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000"],"id":1}"#;
|
||||
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -867,7 +867,7 @@ fn rpc_get_work_should_timeout() {
|
||||
r#"{{"jsonrpc":"2.0","result":["0x{:?}","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}}"#,
|
||||
hash,
|
||||
);
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(work_response.to_owned()));
|
||||
|
||||
// Request with timeout of 0 seconds. This should work since we're disabling timeout.
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["0"], "id": 1}"#;
|
||||
@@ -875,14 +875,14 @@ fn rpc_get_work_should_timeout() {
|
||||
r#"{{"jsonrpc":"2.0","result":["0x{:?}","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000800000000000000000000000000000000000000000000000000000000000","0x01"],"id":1}}"#,
|
||||
hash,
|
||||
);
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(work_response.to_owned()));
|
||||
|
||||
// Request with timeout of 10K seconds. This should work.
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["10000"], "id": 1}"#;
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(work_response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(work_response.to_owned()));
|
||||
|
||||
// Request with timeout of 10 seconds. This should fail.
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getWork", "params": ["10"], "id": 1}"#;
|
||||
let err_response = r#"{"jsonrpc":"2.0","error":{"code":-32003,"message":"Work has not changed.","data":null},"id":1}"#;
|
||||
assert_eq!(eth_tester.io.handle_request(request), Some(err_response.to_owned()));
|
||||
assert_eq!(eth_tester.io.handle_request_sync(request), Some(err_response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use jsonrpc_core::{IoHandler, to_value};
|
||||
use v1::impls::EthSigningQueueClient;
|
||||
use v1::traits::EthSigning;
|
||||
use v1::helpers::{ConfirmationsQueue, SigningQueue};
|
||||
use v1::types::{H256 as RpcH256, H520 as RpcH520};
|
||||
use v1::tests::helpers::TestMinerService;
|
||||
use util::{Address, FixedHash, Uint, U256, H256};
|
||||
use util::{Address, FixedHash, Uint, U256, H256, H520};
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
@@ -37,7 +37,7 @@ struct EthSigningTester {
|
||||
|
||||
impl Default for EthSigningTester {
|
||||
fn default() -> Self {
|
||||
let queue = Arc::new(ConfirmationsQueue::with_timeout(Duration::from_millis(1)));
|
||||
let queue = Arc::new(ConfirmationsQueue::default());
|
||||
let client = Arc::new(TestBlockChainClient::default());
|
||||
let miner = Arc::new(TestMinerService::default());
|
||||
let accounts = Arc::new(AccountProvider::transient_provider());
|
||||
@@ -78,8 +78,13 @@ fn should_add_sign_to_queue() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
let async_result = tester.io.handle_request(&request).unwrap();
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
// respond
|
||||
tester.queue.request_confirmed(U256::from(1), Ok(to_value(&RpcH520::from(H520::default()))));
|
||||
assert!(async_result.on_result(move |res| {
|
||||
assert_eq!(res, response.to_owned());
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -102,7 +107,7 @@ fn should_post_sign_to_queue() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x01","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
}
|
||||
|
||||
@@ -120,7 +125,7 @@ fn should_check_status_of_request() {
|
||||
],
|
||||
"id": 1
|
||||
}"#;
|
||||
tester.io.handle_request(&request).expect("Sent");
|
||||
tester.io.handle_request_sync(&request).expect("Sent");
|
||||
|
||||
// when
|
||||
let request = r#"{
|
||||
@@ -132,7 +137,7 @@ fn should_check_status_of_request() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -149,8 +154,8 @@ fn should_check_status_of_request_when_its_resolved() {
|
||||
],
|
||||
"id": 1
|
||||
}"#;
|
||||
tester.io.handle_request(&request).expect("Sent");
|
||||
tester.queue.request_confirmed(U256::from(1), to_value(&"Hello World!"));
|
||||
tester.io.handle_request_sync(&request).expect("Sent");
|
||||
tester.queue.request_confirmed(U256::from(1), Ok(to_value(&"Hello World!")));
|
||||
|
||||
// when
|
||||
let request = r#"{
|
||||
@@ -162,7 +167,7 @@ fn should_check_status_of_request_when_its_resolved() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -186,7 +191,7 @@ fn should_sign_if_account_is_unlocked() {
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{}", signature).as_ref() + r#"","id":1}"#;
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 0);
|
||||
}
|
||||
|
||||
@@ -213,8 +218,13 @@ fn should_add_transaction_to_queue() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
let async_result = tester.io.handle_request(&request).unwrap();
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
// respond
|
||||
tester.queue.request_confirmed(U256::from(1), Ok(to_value(&RpcH256::from(H256::default()))));
|
||||
assert!(async_result.on_result(move |res| {
|
||||
assert_eq!(res, response.to_owned());
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -251,5 +261,5 @@ fn should_dispatch_transaction_if_account_is_unlock() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ fn rpc_ethcore_extra_data() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -98,7 +98,7 @@ fn rpc_ethcore_default_extra_data() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#;
|
||||
let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex());
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -113,7 +113,7 @@ fn rpc_ethcore_gas_floor_target() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -128,7 +128,7 @@ fn rpc_ethcore_min_gas_price() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -147,7 +147,7 @@ fn rpc_ethcore_dev_logs() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogs", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":["b","a"],"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -162,7 +162,7 @@ fn rpc_ethcore_dev_logs_levels() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -177,7 +177,7 @@ fn rpc_ethcore_transactions_limit() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -192,7 +192,7 @@ fn rpc_ethcore_net_chain() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -207,7 +207,7 @@ fn rpc_ethcore_net_peers() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPeers", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"active":0,"connected":120,"max":50},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -222,7 +222,7 @@ fn rpc_ethcore_net_port() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -237,7 +237,7 @@ fn rpc_ethcore_rpc_settings() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -252,7 +252,7 @@ fn rpc_ethcore_node_name() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -269,7 +269,7 @@ fn rpc_ethcore_unsigned_transactions_count() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":0,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -284,5 +284,5 @@ fn rpc_ethcore_unsigned_transactions_count_when_signer_disabled() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available.","data":null},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ fn rpc_ethcore_set_min_gas_price() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setMinGasPrice", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(miner.minimal_gas_price(), U256::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap());
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ fn rpc_ethcore_set_gas_floor_target() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setGasFloorTarget", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(miner.gas_floor_target(), U256::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap());
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ fn rpc_ethcore_set_extra_data() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setExtraData", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(miner.extra_data(), "cd1722f3947def4cf144679da39c4c32bdc35681".from_hex().unwrap());
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ fn rpc_ethcore_set_author() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setAuthor", "params":["0xcd1722f3947def4cf144679da39c4c32bdc35681"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(miner.author(), Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap());
|
||||
}
|
||||
|
||||
@@ -113,6 +113,6 @@ fn rpc_ethcore_set_transactions_limit() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_setTransactionsLimit", "params":[10240240], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
assert_eq!(miner.transactions_limit(), 10_240_240);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fn rpc_net_version() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "net_version", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"3","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -49,7 +49,7 @@ fn rpc_net_peer_count() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "net_peerCount", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x78","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -62,5 +62,5 @@ fn rpc_net_listening() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "net_listening", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ fn should_return_false_if_signer_is_disabled() {
|
||||
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -90,7 +90,7 @@ fn should_return_port_number_if_signer_is_enabled() {
|
||||
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -100,7 +100,7 @@ fn accounts() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_listAccounts", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":[""#.to_owned() + &format!("0x{:?}", address) + r#""],"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -108,7 +108,7 @@ fn new_account() {
|
||||
let tester = setup(None);
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"#;
|
||||
|
||||
let res = tester.io.handle_request(request);
|
||||
let res = tester.io.handle_request_sync(request);
|
||||
|
||||
let accounts = tester.accounts.accounts().unwrap();
|
||||
assert_eq!(accounts.len(), 1);
|
||||
@@ -131,7 +131,7 @@ fn should_be_able_to_get_account_info() {
|
||||
tester.accounts.set_account_meta(address.clone(), "{foo: 69}".to_owned()).unwrap();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_accountsInfo", "params": [], "id": 1}"#;
|
||||
let res = tester.io.handle_request(request);
|
||||
let res = tester.io.handle_request_sync(request);
|
||||
let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", address.hex(), uuid);
|
||||
assert_eq!(res, Some(response));
|
||||
}
|
||||
@@ -146,13 +146,13 @@ fn should_be_able_to_set_name() {
|
||||
|
||||
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountName", "params": ["0x{}", "Test"], "id": 1}}"#, address.hex());
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
let res = tester.io.handle_request(&request);
|
||||
let res = tester.io.handle_request_sync(&request);
|
||||
assert_eq!(res, Some(response.into()));
|
||||
|
||||
let uuid = tester.accounts.accounts_info().unwrap().get(&address).unwrap().uuid.as_ref().unwrap().clone();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_accountsInfo", "params": [], "id": 1}"#;
|
||||
let res = tester.io.handle_request(request);
|
||||
let res = tester.io.handle_request_sync(request);
|
||||
let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{}\":{{\"meta\":\"{{}}\",\"name\":\"Test\",\"uuid\":\"{}\"}}}},\"id\":1}}", address.hex(), uuid);
|
||||
assert_eq!(res, Some(response));
|
||||
}
|
||||
@@ -167,13 +167,13 @@ fn should_be_able_to_set_meta() {
|
||||
|
||||
let request = format!(r#"{{"jsonrpc": "2.0", "method": "personal_setAccountMeta", "params": ["0x{}", "{{foo: 69}}"], "id": 1}}"#, address.hex());
|
||||
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||
let res = tester.io.handle_request(&request);
|
||||
let res = tester.io.handle_request_sync(&request);
|
||||
assert_eq!(res, Some(response.into()));
|
||||
|
||||
let uuid = tester.accounts.accounts_info().unwrap().get(&address).unwrap().uuid.as_ref().unwrap().clone();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_accountsInfo", "params": [], "id": 1}"#;
|
||||
let res = tester.io.handle_request(request);
|
||||
let res = tester.io.handle_request_sync(request);
|
||||
let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":{{\"0x{}\":{{\"meta\":\"{{foo: 69}}\",\"name\":\"{}\",\"uuid\":\"{}\"}}}},\"id\":1}}", address.hex(), uuid, uuid);
|
||||
assert_eq!(res, Some(response));
|
||||
}
|
||||
@@ -197,7 +197,7 @@ fn sign_and_send_transaction_with_invalid_password() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32021,"message":"Account password is invalid or account does not exist.","data":"SStore(InvalidPassword)"},"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response.into()));
|
||||
assert_eq!(tester.io.handle_request_sync(request.as_ref()), Some(response.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -232,7 +232,7 @@ fn sign_and_send_transaction() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response));
|
||||
assert_eq!(tester.io.handle_request_sync(request.as_ref()), Some(response));
|
||||
|
||||
tester.miner.last_nonces.write().insert(address.clone(), U256::zero());
|
||||
|
||||
@@ -250,5 +250,5 @@ fn sign_and_send_transaction() {
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response));
|
||||
assert_eq!(tester.io.handle_request_sync(request.as_ref()), Some(response));
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ fn should_return_list_of_items_to_confirm() {
|
||||
value: U256::from(1),
|
||||
data: vec![],
|
||||
nonce: None,
|
||||
}));
|
||||
tester.queue.add_request(ConfirmationPayload::Sign(1.into(), 5.into()));
|
||||
})).unwrap();
|
||||
tester.queue.add_request(ConfirmationPayload::Sign(1.into(), 5.into())).unwrap();
|
||||
|
||||
// when
|
||||
let request = r#"{"jsonrpc":"2.0","method":"personal_requestsToConfirm","params":[],"id":1}"#;
|
||||
@@ -92,7 +92,7 @@ fn should_return_list_of_items_to_confirm() {
|
||||
);
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ fn should_reject_transaction_from_queue_without_dispatching() {
|
||||
value: U256::from(1),
|
||||
data: vec![],
|
||||
nonce: None,
|
||||
}));
|
||||
})).unwrap();
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
|
||||
// when
|
||||
@@ -116,7 +116,7 @@ fn should_reject_transaction_from_queue_without_dispatching() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 0);
|
||||
assert_eq!(tester.miner.imported_transactions.lock().len(), 0);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ fn should_not_remove_transaction_if_password_is_invalid() {
|
||||
value: U256::from(1),
|
||||
data: vec![],
|
||||
nonce: None,
|
||||
}));
|
||||
})).unwrap();
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
|
||||
// when
|
||||
@@ -141,7 +141,7 @@ fn should_not_remove_transaction_if_password_is_invalid() {
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32021,"message":"Account password is invalid or account does not exist.","data":"SStore(InvalidAccount)"},"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ fn should_not_remove_transaction_if_password_is_invalid() {
|
||||
fn should_not_remove_sign_if_password_is_invalid() {
|
||||
// given
|
||||
let tester = signer_tester();
|
||||
tester.queue.add_request(ConfirmationPayload::Sign(0.into(), 5.into()));
|
||||
tester.queue.add_request(ConfirmationPayload::Sign(0.into(), 5.into())).unwrap();
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
|
||||
// when
|
||||
@@ -157,7 +157,7 @@ fn should_not_remove_sign_if_password_is_invalid() {
|
||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32021,"message":"Account password is invalid or account does not exist.","data":"SStore(InvalidAccount)"},"id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 1);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ fn should_confirm_transaction_and_dispatch() {
|
||||
value: U256::from(1),
|
||||
data: vec![],
|
||||
nonce: None,
|
||||
}));
|
||||
})).unwrap();
|
||||
|
||||
let t = Transaction {
|
||||
nonce: U256::zero(),
|
||||
@@ -201,7 +201,7 @@ fn should_confirm_transaction_and_dispatch() {
|
||||
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 0);
|
||||
assert_eq!(tester.miner.imported_transactions.lock().len(), 1);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fn modules() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "modules", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"rpc":"1.0","web3":"1.0"},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -48,5 +48,5 @@ fn rpc_modules() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "rpc_modules", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"ethcore":"1.0","rpc":"1.0","web3":"1.0"},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ fn rpc_web3_version() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "web3_clientVersion", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"VER","id":1}"#.to_owned().replace("VER", v.as_ref());
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -41,7 +41,7 @@ fn rpc_web3_sha3() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "web3_sha3", "params": ["0x00"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xbc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -53,5 +53,5 @@ fn rpc_web3_sha3_wiki() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "web3_sha3", "params": ["0x68656c6c6f20776f726c64"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user