move tests to personal
This commit is contained in:
parent
c9efb56e19
commit
194ca19720
@ -521,81 +521,6 @@ fn rpc_eth_send_transaction() {
|
|||||||
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response));
|
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rpc_eth_sign_and_send_transaction_with_invalid_password() {
|
|
||||||
let account = TestAccount::new("password123");
|
|
||||||
let address = account.address();
|
|
||||||
|
|
||||||
let tester = EthTester::default();
|
|
||||||
tester.accounts_provider.accounts.write().unwrap().insert(address.clone(), account);
|
|
||||||
let request = r#"{
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": "eth_signAndSendTransaction",
|
|
||||||
"params": [{
|
|
||||||
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
|
|
||||||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
|
||||||
"gas": "0x76c0",
|
|
||||||
"gasPrice": "0x9184e72a000",
|
|
||||||
"value": "0x9184e72a"
|
|
||||||
}, "password321"],
|
|
||||||
"id": 1
|
|
||||||
}"#;
|
|
||||||
|
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
|
|
||||||
|
|
||||||
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response.into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn rpc_eth_sign_and_send_transaction() {
|
|
||||||
let account = TestAccount::new("password123");
|
|
||||||
let address = account.address();
|
|
||||||
let secret = account.secret.clone();
|
|
||||||
|
|
||||||
let tester = EthTester::default();
|
|
||||||
tester.accounts_provider.accounts.write().unwrap().insert(address.clone(), account);
|
|
||||||
let request = r#"{
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"method": "eth_signAndSendTransaction",
|
|
||||||
"params": [{
|
|
||||||
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
|
|
||||||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
|
||||||
"gas": "0x76c0",
|
|
||||||
"gasPrice": "0x9184e72a000",
|
|
||||||
"value": "0x9184e72a"
|
|
||||||
}, "password123"],
|
|
||||||
"id": 1
|
|
||||||
}"#;
|
|
||||||
|
|
||||||
let t = Transaction {
|
|
||||||
nonce: U256::zero(),
|
|
||||||
gas_price: U256::from(0x9184e72a000u64),
|
|
||||||
gas: U256::from(0x76c0),
|
|
||||||
action: Action::Call(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
|
|
||||||
value: U256::from(0x9184e72au64),
|
|
||||||
data: vec![]
|
|
||||||
}.sign(&secret);
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
tester.miner.last_nonces.write().unwrap().insert(address.clone(), U256::zero());
|
|
||||||
|
|
||||||
let t = Transaction {
|
|
||||||
nonce: U256::one(),
|
|
||||||
gas_price: U256::from(0x9184e72a000u64),
|
|
||||||
gas: U256::from(0x76c0),
|
|
||||||
action: Action::Call(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
|
|
||||||
value: U256::from(0x9184e72au64),
|
|
||||||
data: vec![]
|
|
||||||
}.sign(&secret);
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn rpc_eth_send_raw_transaction() {
|
fn rpc_eth_send_raw_transaction() {
|
||||||
|
@ -15,11 +15,29 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::collections::HashMap;
|
||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::keys::{TestAccount, TestAccountProvider};
|
use util::keys::{TestAccount, TestAccountProvider};
|
||||||
use v1::{PersonalClient, Personal};
|
use v1::{PersonalClient, Personal};
|
||||||
use std::collections::*;
|
use v1::tests::helpers::TestMinerService;
|
||||||
|
use ethcore::client::TestBlockChainClient;
|
||||||
|
use ethcore::transaction::{Action, Transaction};
|
||||||
|
|
||||||
|
struct PersonalTester {
|
||||||
|
accounts: Arc<TestAccountProvider>,
|
||||||
|
io: IoHandler,
|
||||||
|
miner: Arc<TestMinerService>,
|
||||||
|
// these unused fields are necessary to keep the data alive
|
||||||
|
// as the handler has only weak pointers.
|
||||||
|
_client: Arc<TestBlockChainClient>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn blockchain_client() -> Arc<TestBlockChainClient> {
|
||||||
|
let client = TestBlockChainClient::new();
|
||||||
|
Arc::new(client)
|
||||||
|
}
|
||||||
|
|
||||||
fn accounts_provider() -> Arc<TestAccountProvider> {
|
fn accounts_provider() -> Arc<TestAccountProvider> {
|
||||||
let accounts = HashMap::new();
|
let accounts = HashMap::new();
|
||||||
@ -27,18 +45,33 @@ fn accounts_provider() -> Arc<TestAccountProvider> {
|
|||||||
Arc::new(ap)
|
Arc::new(ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup() -> (Arc<TestAccountProvider>, IoHandler) {
|
fn miner_service() -> Arc<TestMinerService> {
|
||||||
let test_provider = accounts_provider();
|
Arc::new(TestMinerService::default())
|
||||||
let personal = PersonalClient::new(&test_provider);
|
}
|
||||||
|
|
||||||
|
fn setup() -> PersonalTester {
|
||||||
|
let accounts = accounts_provider();
|
||||||
|
let client = blockchain_client();
|
||||||
|
let miner = miner_service();
|
||||||
|
let personal = PersonalClient::new(&accounts, &client, &miner);
|
||||||
|
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(personal.to_delegate());
|
io.add_delegate(personal.to_delegate());
|
||||||
(test_provider, io)
|
|
||||||
|
let tester = PersonalTester {
|
||||||
|
accounts: accounts,
|
||||||
|
io: io,
|
||||||
|
miner: miner,
|
||||||
|
_client: client,
|
||||||
|
};
|
||||||
|
|
||||||
|
tester
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accounts() {
|
fn accounts() {
|
||||||
let (test_provider, io) = setup();
|
let tester = setup();
|
||||||
test_provider.accounts
|
tester.accounts.accounts
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(Address::from(1), TestAccount::new("test"));
|
.insert(Address::from(1), TestAccount::new("test"));
|
||||||
@ -46,17 +79,17 @@ fn accounts() {
|
|||||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_listAccounts", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "personal_listAccounts", "params": [], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":["0x0000000000000000000000000000000000000001"],"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":["0x0000000000000000000000000000000000000001"],"id":1}"#;
|
||||||
|
|
||||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_account() {
|
fn new_account() {
|
||||||
let (test_provider, io) = setup();
|
let tester = setup();
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"#;
|
||||||
|
|
||||||
let res = io.handle_request(request);
|
let res = tester.io.handle_request(request);
|
||||||
|
|
||||||
let accounts = test_provider.accounts.read().unwrap();
|
let accounts = tester.accounts.accounts.read().unwrap();
|
||||||
assert_eq!(accounts.len(), 1);
|
assert_eq!(accounts.len(), 1);
|
||||||
|
|
||||||
let address = accounts
|
let address = accounts
|
||||||
@ -70,3 +103,77 @@ fn new_account() {
|
|||||||
assert_eq!(res, Some(response));
|
assert_eq!(res, Some(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sign_and_send_transaction_with_invalid_password() {
|
||||||
|
let account = TestAccount::new("password123");
|
||||||
|
let address = account.address();
|
||||||
|
|
||||||
|
let tester = setup();
|
||||||
|
tester.accounts.accounts.write().unwrap().insert(address.clone(), account);
|
||||||
|
let request = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "personal_signAndSendTransaction",
|
||||||
|
"params": [{
|
||||||
|
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
|
||||||
|
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
||||||
|
"gas": "0x76c0",
|
||||||
|
"gasPrice": "0x9184e72a000",
|
||||||
|
"value": "0x9184e72a"
|
||||||
|
}, "password321"],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000000000000000000000000000000","id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(tester.io.handle_request(request.as_ref()), Some(response.into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sign_and_send_transaction() {
|
||||||
|
let account = TestAccount::new("password123");
|
||||||
|
let address = account.address();
|
||||||
|
let secret = account.secret.clone();
|
||||||
|
|
||||||
|
let tester = setup();
|
||||||
|
tester.accounts.accounts.write().unwrap().insert(address.clone(), account);
|
||||||
|
let request = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "personal_signAndSendTransaction",
|
||||||
|
"params": [{
|
||||||
|
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
|
||||||
|
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
||||||
|
"gas": "0x76c0",
|
||||||
|
"gasPrice": "0x9184e72a000",
|
||||||
|
"value": "0x9184e72a"
|
||||||
|
}, "password123"],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let t = Transaction {
|
||||||
|
nonce: U256::zero(),
|
||||||
|
gas_price: U256::from(0x9184e72a000u64),
|
||||||
|
gas: U256::from(0x76c0),
|
||||||
|
action: Action::Call(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
|
||||||
|
value: U256::from(0x9184e72au64),
|
||||||
|
data: vec![]
|
||||||
|
}.sign(&secret);
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
tester.miner.last_nonces.write().unwrap().insert(address.clone(), U256::zero());
|
||||||
|
|
||||||
|
let t = Transaction {
|
||||||
|
nonce: U256::one(),
|
||||||
|
gas_price: U256::from(0x9184e72a000u64),
|
||||||
|
gas: U256::from(0x76c0),
|
||||||
|
action: Action::Call(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
|
||||||
|
value: U256::from(0x9184e72au64),
|
||||||
|
data: vec![]
|
||||||
|
}.sign(&secret);
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
@ -3,6 +3,4 @@
|
|||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mocked;
|
mod mocked;
|
||||||
#[cfg(test)]
|
|
||||||
mod eth;
|
|
Loading…
Reference in New Issue
Block a user