RPC Middleware & Get/Set dapp-specific accounts

This commit is contained in:
Tomasz Drwięga
2016-11-22 11:56:27 +01:00
parent 21b2b4ac27
commit cd6f565f69
34 changed files with 655 additions and 224 deletions

View File

@@ -30,7 +30,7 @@ use devtools::RandomTempPath;
use util::Hashable;
use io::IoChannel;
use util::{U256, H256, Uint, Address};
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use ethjson::blockchain::BlockChain;
use v1::impls::{EthClient, SigningUnsafeClient};

View File

@@ -31,7 +31,7 @@ use ethcore::transaction::{Transaction, Action};
use ethcore::miner::{ExternalMiner, MinerService};
use ethsync::SyncState;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{Eth, EthClient, EthClientOptions, EthFilter, EthFilterClient, EthSigning, SigningUnsafeClient};
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService, TestSnapshotService};
@@ -357,15 +357,15 @@ fn rpc_eth_accounts() {
let address = tester.accounts_provider.new_account("").unwrap();
let address2 = Address::default();
tester.accounts_provider.set_address_name(address2, "Test Account".into()).unwrap();
// even with some account it should return empty list (no dapp detected)
let request = r#"{"jsonrpc": "2.0", "method": "eth_accounts", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":[""#.to_owned()
+ &format!("0x{:?}", address2)
+ r#"",""#
+ &format!("0x{:?}", address)
+ r#""],"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":[],"id":1}"#;
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
// when we add visible address it should return that.
tester.accounts_provider.set_dapps_addresses("app1".into(), vec![10.into()]).unwrap();
let request = r#"{"jsonrpc": "2.0", "method": "eth_accounts", "params": ["app1"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":["0x000000000000000000000000000000000000000a"],"id":1}"#;
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

View File

@@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{Net, NetClient};
use v1::tests::helpers::{Config, TestSyncProvider};

View File

@@ -23,7 +23,7 @@ use ethcore::client::{TestBlockChainClient};
use ethcore::miner::LocalTransactionStatus;
use ethstore::ethkey::{Generator, Random};
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{Parity, ParityClient};
use v1::helpers::{SignerService, NetworkSettings};
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService};

View File

@@ -19,7 +19,7 @@ use std::sync::Arc;
use ethcore::account_provider::AccountProvider;
use ethcore::client::TestBlockChainClient;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{ParityAccounts, ParityAccountsClient};
struct ParityAccountsTester {
@@ -116,3 +116,18 @@ fn should_be_able_to_set_meta() {
assert_eq!(res, Some(response));
}
#[test]
fn rpc_parity_set_dapps_accounts() {
// given
let tester = setup();
assert_eq!(tester.accounts.dapps_addresses("app1".into()).unwrap(), vec![]);
// when
let request = r#"{"jsonrpc": "2.0", "method": "parity_setDappsAddresses","params":["app1",["0x000000000000000000000000000000000000000a"]], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
// then
assert_eq!(tester.accounts.dapps_addresses("app1".into()).unwrap(), vec![10.into()]);
}

View File

@@ -23,7 +23,7 @@ use ethcore::miner::MinerService;
use ethcore::client::TestBlockChainClient;
use ethsync::ManageNetwork;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{ParitySet, ParitySetClient};
use v1::tests::helpers::{TestMinerService, TestFetch};
use super::manage_network::TestManageNetwork;

View File

@@ -16,7 +16,7 @@
use std::sync::Arc;
use std::str::FromStr;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use util::{U256, Uint, Address};
use ethcore::account_provider::AccountProvider;
use v1::{PersonalClient, Personal};

View File

@@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{Rpc, RpcClient};

View File

@@ -23,7 +23,7 @@ use ethcore::client::TestBlockChainClient;
use ethcore::transaction::{Transaction, Action};
use rlp::encode;
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use v1::{SignerClient, Signer};
use v1::tests::helpers::TestMinerService;
use v1::helpers::{SigningQueue, SignerService, FilledTransactionRequest, ConfirmationPayload};

View File

@@ -15,10 +15,10 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::str::FromStr;
use std::sync::Arc;
use std::sync::{mpsc, Arc};
use rlp;
use jsonrpc_core::{IoHandler, Success};
use jsonrpc_core::{IoHandler, Success, GenericIoHandler};
use v1::impls::SigningQueueClient;
use v1::traits::{EthSigning, ParitySigning, Parity};
use v1::helpers::{SignerService, SigningQueue};
@@ -87,13 +87,16 @@ fn should_add_sign_to_queue() {
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
// then
let async_result = tester.io.handle_request(&request).unwrap();
let (tx, rx) = mpsc::channel();
tester.io.handle_request(&request, move |response| {
tx.send(response).unwrap();
});
assert_eq!(tester.signer.requests().len(), 1);
// respond
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Signature(0.into())));
assert!(async_result.on_result(move |res| {
assert_eq!(res, response.to_owned());
}));
let res = rx.try_recv().unwrap();
assert_eq!(res, Some(response.to_owned()));
}
#[test]
@@ -227,13 +230,16 @@ fn should_add_transaction_to_queue() {
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
// then
let async_result = tester.io.handle_request(&request).unwrap();
let (tx, rx) = mpsc::channel();
tester.io.handle_request(&request, move |response| {
tx.send(response).unwrap();
});
assert_eq!(tester.signer.requests().len(), 1);
// respond
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SendTransaction(0.into())));
assert!(async_result.on_result(move |res| {
assert_eq!(res, response.to_owned());
}));
let res = rx.try_recv().unwrap();
assert_eq!(res, Some(response.to_owned()));
}
#[test]
@@ -289,14 +295,17 @@ fn should_add_sign_transaction_to_the_queue() {
r#"}},"id":1}"#;
// then
let (tx, rx) = mpsc::channel();
tester.miner.last_nonces.write().insert(address.clone(), U256::zero());
let async_result = tester.io.handle_request(&request).unwrap();
tester.io.handle_request(&request, move |response| {
tx.send(response).unwrap();
});
assert_eq!(tester.signer.requests().len(), 1);
// respond
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::SignTransaction(t.into())));
assert!(async_result.on_result(move |res| {
assert_eq!(res, response.to_owned());
}));
let res = rx.try_recv().unwrap();
assert_eq!(res, Some(response.to_owned()));
}
#[test]
@@ -387,11 +396,14 @@ fn should_add_decryption_to_the_queue() {
let response = r#"{"jsonrpc":"2.0","result":"0x0102","id":1}"#;
// then
let async_result = tester.io.handle_request(&request).unwrap();
let (tx, rx) = mpsc::channel();
tester.io.handle_request(&request, move |response| {
tx.send(response).unwrap();
});
assert_eq!(tester.signer.requests().len(), 1);
// respond
tester.signer.request_confirmed(1.into(), Ok(ConfirmationResponse::Decrypt(vec![0x1, 0x2].into())));
assert!(async_result.on_result(move |res| {
assert_eq!(res, response.to_owned());
}));
let res = rx.try_recv().unwrap();
assert_eq!(res, Some(response.to_owned()));
}

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use jsonrpc_core::IoHandler;
use jsonrpc_core::{IoHandler, GenericIoHandler};
use util::version;
use v1::{Web3, Web3Client};