2016-05-24 16:56:09 +02:00
|
|
|
// Copyright 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! rpc integration tests.
|
|
|
|
use std::sync::Arc;
|
2016-06-29 16:26:19 +02:00
|
|
|
use std::time::Duration;
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2017-01-11 20:02:27 +01:00
|
|
|
use devtools::RandomTempPath;
|
2016-06-02 12:40:31 +02:00
|
|
|
use ethcore::client::{BlockChainClient, Client, ClientConfig};
|
2016-12-09 23:01:43 +01:00
|
|
|
use ethcore::ids::BlockId;
|
2016-05-30 20:06:10 +02:00
|
|
|
use ethcore::spec::{Genesis, Spec};
|
2016-05-24 16:56:09 +02:00
|
|
|
use ethcore::block::Block;
|
2016-05-31 19:30:40 +02:00
|
|
|
use ethcore::views::BlockView;
|
2016-05-24 16:56:09 +02:00
|
|
|
use ethcore::ethereum;
|
2016-10-27 19:28:34 +02:00
|
|
|
use ethcore::miner::{MinerOptions, Banning, GasPricer, MinerService, ExternalMiner, Miner, PendingSet, PrioritizationStrategy, GasLimit};
|
2016-06-20 00:10:34 +02:00
|
|
|
use ethcore::account_provider::AccountProvider;
|
2016-05-24 19:20:07 +02:00
|
|
|
use ethjson::blockchain::BlockChain;
|
2017-01-11 20:02:27 +01:00
|
|
|
use io::IoChannel;
|
|
|
|
use util::{U256, H256, Uint, Address, Hashable};
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2017-01-11 20:02:27 +01:00
|
|
|
use jsonrpc_core::IoHandler;
|
2016-11-06 12:51:53 +01:00
|
|
|
use v1::impls::{EthClient, SigningUnsafeClient};
|
2017-01-11 20:02:27 +01:00
|
|
|
use v1::metadata::Metadata;
|
|
|
|
use v1::tests::helpers::{TestSnapshotService, TestSyncProvider, Config};
|
2016-10-15 14:44:08 +02:00
|
|
|
use v1::traits::eth::Eth;
|
|
|
|
use v1::traits::eth_signing::EthSigning;
|
2017-01-11 20:02:27 +01:00
|
|
|
use v1::types::U256 as NU256;
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-06-20 00:10:34 +02:00
|
|
|
fn account_provider() -> Arc<AccountProvider> {
|
|
|
|
Arc::new(AccountProvider::transient_provider())
|
2016-05-24 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn sync_provider() -> Arc<TestSyncProvider> {
|
|
|
|
Arc::new(TestSyncProvider::new(Config {
|
2016-11-03 22:22:25 +01:00
|
|
|
network_id: 3,
|
2016-05-24 16:56:09 +02:00
|
|
|
num_peers: 120,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2016-08-05 23:33:55 +02:00
|
|
|
fn miner_service(spec: &Spec, accounts: Arc<AccountProvider>) -> Arc<Miner> {
|
2016-06-27 17:23:54 +02:00
|
|
|
Miner::new(
|
|
|
|
MinerOptions {
|
2016-06-30 12:56:58 +02:00
|
|
|
new_work_notify: vec![],
|
2016-06-27 17:23:54 +02:00
|
|
|
force_sealing: true,
|
|
|
|
reseal_on_external_tx: true,
|
|
|
|
reseal_on_own_tx: true,
|
2016-06-28 10:21:29 +02:00
|
|
|
tx_queue_size: 1024,
|
2016-06-28 10:40:35 +02:00
|
|
|
tx_gas_limit: !U256::zero(),
|
2016-10-15 14:46:33 +02:00
|
|
|
tx_queue_strategy: PrioritizationStrategy::GasPriceOnly,
|
2016-10-10 23:04:43 +02:00
|
|
|
tx_queue_gas_limit: GasLimit::None,
|
2016-10-27 19:28:34 +02:00
|
|
|
tx_queue_banning: Banning::Disabled,
|
2016-06-27 19:16:26 +02:00
|
|
|
pending_set: PendingSet::SealingOrElseQueue,
|
2016-06-29 16:26:19 +02:00
|
|
|
reseal_min_period: Duration::from_secs(0),
|
|
|
|
work_queue_size: 50,
|
2016-06-30 12:56:58 +02:00
|
|
|
enable_resubmission: true,
|
2017-01-22 16:15:22 +01:00
|
|
|
refuse_service_transactions: false,
|
2016-06-27 17:23:54 +02:00
|
|
|
},
|
2016-07-09 16:39:59 +02:00
|
|
|
GasPricer::new_fixed(20_000_000_000u64.into()),
|
2016-08-05 23:33:55 +02:00
|
|
|
&spec,
|
|
|
|
Some(accounts),
|
2016-06-27 17:23:54 +02:00
|
|
|
)
|
2016-05-24 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-31 17:32:53 +01:00
|
|
|
fn snapshot_service() -> Arc<TestSnapshotService> {
|
|
|
|
Arc::new(TestSnapshotService::new())
|
|
|
|
}
|
|
|
|
|
2016-05-30 20:06:10 +02:00
|
|
|
fn make_spec(chain: &BlockChain) -> Spec {
|
2016-05-24 16:56:09 +02:00
|
|
|
let genesis = Genesis::from(chain.genesis());
|
|
|
|
let mut spec = ethereum::new_frontier_test();
|
|
|
|
let state = chain.pre_state.clone().into();
|
|
|
|
spec.set_genesis_state(state);
|
|
|
|
spec.overwrite_genesis_params(genesis);
|
|
|
|
assert!(spec.is_state_root_valid());
|
2016-05-30 20:06:10 +02:00
|
|
|
spec
|
|
|
|
}
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-25 13:27:03 +02:00
|
|
|
struct EthTester {
|
2016-06-01 13:03:26 +02:00
|
|
|
client: Arc<Client>,
|
2016-05-25 13:27:03 +02:00
|
|
|
_miner: Arc<MinerService>,
|
2016-10-31 17:32:53 +01:00
|
|
|
_snapshot: Arc<TestSnapshotService>,
|
2016-06-20 00:10:34 +02:00
|
|
|
accounts: Arc<AccountProvider>,
|
2017-01-11 20:02:27 +01:00
|
|
|
handler: IoHandler<Metadata>,
|
2016-05-25 13:27:03 +02:00
|
|
|
}
|
|
|
|
|
2016-05-30 20:06:10 +02:00
|
|
|
impl EthTester {
|
2016-05-31 19:30:40 +02:00
|
|
|
fn from_chain(chain: &BlockChain) -> Self {
|
2016-08-05 23:33:55 +02:00
|
|
|
let tester = Self::from_spec(make_spec(chain));
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
for b in &chain.blocks_rlp() {
|
|
|
|
if Block::is_good(&b) {
|
|
|
|
let _ = tester.client.import_block(b.clone());
|
|
|
|
tester.client.flush_queue();
|
2016-07-19 09:21:41 +02:00
|
|
|
tester.client.import_verified_blocks();
|
2016-05-30 20:06:10 +02:00
|
|
|
}
|
2016-05-24 16:56:09 +02:00
|
|
|
}
|
2016-05-30 20:06:10 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
tester.client.flush_queue();
|
|
|
|
|
|
|
|
assert!(tester.client.chain_info().best_block_hash == chain.best_block.clone().into());
|
2016-05-30 20:06:10 +02:00
|
|
|
tester
|
2016-05-24 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 23:33:55 +02:00
|
|
|
fn from_spec(spec: Spec) -> Self {
|
2016-05-30 20:06:10 +02:00
|
|
|
let dir = RandomTempPath::new();
|
|
|
|
let account_provider = account_provider();
|
2016-08-05 23:33:55 +02:00
|
|
|
let miner_service = miner_service(&spec, account_provider.clone());
|
2016-10-31 17:32:53 +01:00
|
|
|
let snapshot_service = snapshot_service();
|
2016-09-07 15:27:28 +02:00
|
|
|
|
|
|
|
let db_config = ::util::kvdb::DatabaseConfig::with_columns(::ethcore::db::NUM_COLUMNS);
|
|
|
|
let client = Client::new(
|
|
|
|
ClientConfig::default(),
|
|
|
|
&spec,
|
|
|
|
dir.as_path(),
|
|
|
|
miner_service.clone(),
|
|
|
|
IoChannel::disconnected(),
|
|
|
|
&db_config
|
|
|
|
).unwrap();
|
2016-06-01 13:03:26 +02:00
|
|
|
let sync_provider = sync_provider();
|
2016-05-30 20:06:10 +02:00
|
|
|
let external_miner = Arc::new(ExternalMiner::default());
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 21:50:25 +02:00
|
|
|
let eth_client = EthClient::new(
|
|
|
|
&client,
|
2016-10-31 17:32:53 +01:00
|
|
|
&snapshot_service,
|
2016-05-31 21:50:25 +02:00
|
|
|
&sync_provider,
|
|
|
|
&account_provider,
|
|
|
|
&miner_service,
|
2016-06-19 14:51:51 +02:00
|
|
|
&external_miner,
|
2016-08-03 15:31:00 +02:00
|
|
|
Default::default(),
|
2016-05-31 21:50:25 +02:00
|
|
|
);
|
2016-11-06 12:51:53 +01:00
|
|
|
let eth_sign = SigningUnsafeClient::new(
|
2016-06-01 19:37:34 +02:00
|
|
|
&client,
|
|
|
|
&account_provider,
|
|
|
|
&miner_service
|
|
|
|
);
|
2016-05-30 20:06:10 +02:00
|
|
|
|
2017-01-11 20:02:27 +01:00
|
|
|
let mut handler = IoHandler::default();
|
|
|
|
handler.extend_with(eth_client.to_delegate());
|
|
|
|
handler.extend_with(eth_sign.to_delegate());
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
EthTester {
|
|
|
|
_miner: miner_service,
|
2016-10-31 17:32:53 +01:00
|
|
|
_snapshot: snapshot_service,
|
2016-05-30 20:06:10 +02:00
|
|
|
client: client,
|
|
|
|
accounts: account_provider,
|
|
|
|
handler: handler,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-24 16:56:09 +02:00
|
|
|
#[test]
|
|
|
|
fn harness_works() {
|
2016-05-24 19:20:07 +02:00
|
|
|
let chain: BlockChain = extract_chain!("BlockchainTests/bcUncleTest");
|
2016-05-31 19:30:40 +02:00
|
|
|
let _ = EthTester::from_chain(&chain);
|
2016-05-24 19:20:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eth_get_balance() {
|
|
|
|
let chain = extract_chain!("BlockchainTests/bcWalletTest", "wallet2outOf3txs");
|
2016-05-31 19:30:40 +02:00
|
|
|
let tester = EthTester::from_chain(&chain);
|
2016-05-30 20:06:10 +02:00
|
|
|
// final account state
|
|
|
|
let req_latest = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getBalance",
|
|
|
|
"params": ["0xaaaf5374fce5edbc8e2a8697c15331677e6ebaaa", "latest"],
|
|
|
|
"id": 1
|
|
|
|
}"#;
|
2016-09-02 11:38:16 +02:00
|
|
|
let res_latest = r#"{"jsonrpc":"2.0","result":"0x9","id":1}"#.to_owned();
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(req_latest).unwrap(), res_latest);
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
// non-existant account
|
|
|
|
let req_new_acc = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getBalance",
|
|
|
|
"params": ["0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
|
|
|
|
"id": 3
|
|
|
|
}"#;
|
|
|
|
|
2016-09-02 11:38:16 +02:00
|
|
|
let res_new_acc = r#"{"jsonrpc":"2.0","result":"0x0","id":3}"#.to_owned();
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(req_new_acc).unwrap(), res_new_acc);
|
2016-05-25 13:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eth_block_number() {
|
|
|
|
let chain = extract_chain!("BlockchainTests/bcRPC_API_Test");
|
2016-05-31 19:30:40 +02:00
|
|
|
let tester = EthTester::from_chain(&chain);
|
2016-05-30 20:06:10 +02:00
|
|
|
let req_number = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_blockNumber",
|
|
|
|
"params": [],
|
|
|
|
"id": 1
|
|
|
|
}"#;
|
|
|
|
|
|
|
|
let res_number = r#"{"jsonrpc":"2.0","result":"0x20","id":1}"#.to_owned();
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(req_number).unwrap(), res_number);
|
2016-05-30 20:06:10 +02:00
|
|
|
}
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2017-01-24 21:57:29 +01:00
|
|
|
#[test]
|
|
|
|
fn eth_get_block() {
|
|
|
|
let chain = extract_chain!("BlockchainTests/bcRPC_API_Test");
|
|
|
|
let tester = EthTester::from_chain(&chain);
|
|
|
|
let req_block = r#"{"method":"eth_getBlockByNumber","params":["0x0",false],"id":1,"jsonrpc":"2.0"}"#;
|
|
|
|
|
|
|
|
let res_block = r#"{"jsonrpc":"2.0","result":{"author":"0x8888f1f195afa192cfee860698584c030f4c9db1","difficulty":"0x20000","extraData":"0x42","gasLimit":"0x2fefd8","gasUsed":"0x0","hash":"0x5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x8888f1f195afa192cfee860698584c030f4c9db1","mixHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","nonce":"0x0102030405060708","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":["0xa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","0x880102030405060708"],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1ff","stateRoot":"0x7dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1","timestamp":"0x54c98c81","totalDifficulty":"0x20000","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]},"id":1}"#.to_owned();
|
|
|
|
assert_eq!(tester.handler.handle_request_sync(req_block).unwrap(), res_block);
|
|
|
|
}
|
|
|
|
|
2016-05-30 20:06:10 +02:00
|
|
|
// a frontier-like test with an expanded gas limit and balance on known account.
|
|
|
|
const TRANSACTION_COUNT_SPEC: &'static [u8] = br#"{
|
|
|
|
"name": "Frontier (Test)",
|
|
|
|
"engine": {
|
|
|
|
"Ethash": {
|
|
|
|
"params": {
|
|
|
|
"gasLimitBoundDivisor": "0x0400",
|
|
|
|
"minimumDifficulty": "0x020000",
|
|
|
|
"difficultyBoundDivisor": "0x0800",
|
|
|
|
"durationLimit": "0x0d",
|
|
|
|
"blockReward": "0x4563918244F40000",
|
|
|
|
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
2016-10-15 14:39:15 +02:00
|
|
|
"homesteadTransition": "0xffffffffffffffff",
|
2016-07-16 13:02:56 +02:00
|
|
|
"daoHardforkTransition": "0xffffffffffffffff",
|
|
|
|
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
|
|
|
|
"daoHardforkAccounts": []
|
2016-05-30 20:06:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"accountStartNonce": "0x00",
|
|
|
|
"maximumExtraDataSize": "0x20",
|
|
|
|
"minGasLimit": "0x50000",
|
|
|
|
"networkID" : "0x1"
|
|
|
|
},
|
|
|
|
"genesis": {
|
|
|
|
"seal": {
|
|
|
|
"ethereum": {
|
|
|
|
"nonce": "0x0000000000000042",
|
|
|
|
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"difficulty": "0x400000000",
|
|
|
|
"author": "0x0000000000000000000000000000000000000000",
|
|
|
|
"timestamp": "0x00",
|
|
|
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
|
|
|
|
"gasLimit": "0x50000"
|
|
|
|
},
|
|
|
|
"accounts": {
|
|
|
|
"0000000000000000000000000000000000000001": { "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
|
|
|
"0000000000000000000000000000000000000002": { "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
|
|
|
"0000000000000000000000000000000000000003": { "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
|
|
|
"0000000000000000000000000000000000000004": { "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
|
|
|
"faa34835af5c2ea724333018a515fbb7d5bc0b33": { "balance": "10000000000000", "nonce": "0" }
|
|
|
|
}
|
2016-05-25 13:27:03 +02:00
|
|
|
}
|
2016-05-30 20:06:10 +02:00
|
|
|
"#;
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2016-08-04 18:17:39 +02:00
|
|
|
const POSITIVE_NONCE_SPEC: &'static [u8] = br#"{
|
|
|
|
"name": "Frontier (Test)",
|
|
|
|
"engine": {
|
|
|
|
"Ethash": {
|
|
|
|
"params": {
|
|
|
|
"gasLimitBoundDivisor": "0x0400",
|
|
|
|
"minimumDifficulty": "0x020000",
|
|
|
|
"difficultyBoundDivisor": "0x0800",
|
|
|
|
"durationLimit": "0x0d",
|
|
|
|
"blockReward": "0x4563918244F40000",
|
|
|
|
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
|
2016-10-15 14:39:15 +02:00
|
|
|
"homesteadTransition": "0xffffffffffffffff",
|
2016-08-04 18:17:39 +02:00
|
|
|
"daoHardforkTransition": "0xffffffffffffffff",
|
|
|
|
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
|
|
|
|
"daoHardforkAccounts": []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"params": {
|
|
|
|
"accountStartNonce": "0x0100",
|
|
|
|
"maximumExtraDataSize": "0x20",
|
|
|
|
"minGasLimit": "0x50000",
|
|
|
|
"networkID" : "0x1"
|
|
|
|
},
|
|
|
|
"genesis": {
|
|
|
|
"seal": {
|
|
|
|
"ethereum": {
|
|
|
|
"nonce": "0x0000000000000042",
|
|
|
|
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"difficulty": "0x400000000",
|
|
|
|
"author": "0x0000000000000000000000000000000000000000",
|
|
|
|
"timestamp": "0x00",
|
|
|
|
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
|
|
|
|
"gasLimit": "0x50000"
|
|
|
|
},
|
|
|
|
"accounts": {
|
|
|
|
"0000000000000000000000000000000000000001": { "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
|
|
|
|
"0000000000000000000000000000000000000002": { "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
|
|
|
|
"0000000000000000000000000000000000000003": { "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
|
|
|
|
"0000000000000000000000000000000000000004": { "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
|
|
|
|
"faa34835af5c2ea724333018a515fbb7d5bc0b33": { "balance": "10000000000000", "nonce": "0" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
|
2016-05-25 13:27:03 +02:00
|
|
|
#[test]
|
|
|
|
fn eth_transaction_count() {
|
2017-01-11 12:16:47 +01:00
|
|
|
let secret = "8a283037bb19c4fed7b1c569e40c7dcff366165eb869110a1b11532963eb9cb2".parse().unwrap();
|
2016-09-07 10:36:18 +02:00
|
|
|
let tester = EthTester::from_spec(Spec::load(TRANSACTION_COUNT_SPEC).expect("invalid chain spec"));
|
2016-06-20 00:10:34 +02:00
|
|
|
let address = tester.accounts.insert_account(secret, "").unwrap();
|
|
|
|
tester.accounts.unlock_account_permanently(address, "".into()).unwrap();
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2016-05-30 20:06:10 +02:00
|
|
|
let req_before = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getTransactionCount",
|
|
|
|
"params": [""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"", "latest"],
|
|
|
|
"id": 15
|
|
|
|
}"#;
|
|
|
|
|
2016-09-02 11:38:16 +02:00
|
|
|
let res_before = r#"{"jsonrpc":"2.0","result":"0x0","id":15}"#;
|
2016-05-30 20:06:10 +02:00
|
|
|
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(&req_before).unwrap(), res_before);
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
let req_send_trans = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_sendTransaction",
|
|
|
|
"params": [{
|
|
|
|
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
|
|
|
|
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
|
|
|
"gas": "0x30000",
|
2016-09-02 11:38:16 +02:00
|
|
|
"gasPrice": "0x1",
|
2016-05-30 20:06:10 +02:00
|
|
|
"value": "0x9184e72a"
|
|
|
|
}],
|
|
|
|
"id": 16
|
|
|
|
}"#;
|
|
|
|
|
|
|
|
// dispatch the transaction.
|
2016-09-01 12:00:00 +02:00
|
|
|
tester.handler.handle_request_sync(&req_send_trans).unwrap();
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
// we have submitted the transaction -- but this shouldn't be reflected in a "latest" query.
|
|
|
|
let req_after_latest = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getTransactionCount",
|
|
|
|
"params": [""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"", "latest"],
|
|
|
|
"id": 17
|
|
|
|
}"#;
|
|
|
|
|
2016-09-02 11:38:16 +02:00
|
|
|
let res_after_latest = r#"{"jsonrpc":"2.0","result":"0x0","id":17}"#;
|
2016-05-30 20:06:10 +02:00
|
|
|
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(&tester.handler.handle_request_sync(&req_after_latest).unwrap(), res_after_latest);
|
2016-05-30 20:06:10 +02:00
|
|
|
|
|
|
|
// the pending transactions should have been updated.
|
|
|
|
let req_after_pending = r#"{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getTransactionCount",
|
|
|
|
"params": [""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"", "pending"],
|
|
|
|
"id": 18
|
|
|
|
}"#;
|
|
|
|
|
2016-09-02 11:38:16 +02:00
|
|
|
let res_after_pending = r#"{"jsonrpc":"2.0","result":"0x1","id":18}"#;
|
2016-05-30 20:06:10 +02:00
|
|
|
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(&tester.handler.handle_request_sync(&req_after_pending).unwrap(), res_after_pending);
|
2016-05-31 19:30:40 +02:00
|
|
|
}
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
fn verify_transaction_counts(name: String, chain: BlockChain) {
|
|
|
|
struct PanicHandler(String);
|
|
|
|
impl Drop for PanicHandler {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
if ::std::thread::panicking() {
|
|
|
|
println!("Test failed: {}", self.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-26 13:30:19 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let _panic = PanicHandler(name);
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
fn by_hash(hash: H256, count: usize, id: &mut usize) -> (String, String) {
|
|
|
|
let req = r#"{
|
2016-05-25 13:27:03 +02:00
|
|
|
"jsonrpc": "2.0",
|
2016-05-31 19:30:40 +02:00
|
|
|
"method": "eth_getBlockTransactionCountByHash",
|
|
|
|
"params": [
|
|
|
|
""#.to_owned() + format!("0x{:?}", hash).as_ref() + r#""
|
|
|
|
],
|
|
|
|
"id": "# + format!("{}", *id).as_ref() + r#"
|
2016-05-25 13:27:03 +02:00
|
|
|
}"#;
|
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let res = r#"{"jsonrpc":"2.0","result":""#.to_owned()
|
2016-09-02 11:38:16 +02:00
|
|
|
+ format!("0x{:x}", count).as_ref()
|
2016-05-31 19:30:40 +02:00
|
|
|
+ r#"","id":"#
|
|
|
|
+ format!("{}", *id).as_ref() + r#"}"#;
|
|
|
|
*id += 1;
|
|
|
|
(req, res)
|
|
|
|
}
|
2016-05-25 13:27:03 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
fn by_number(num: u64, count: usize, id: &mut usize) -> (String, String) {
|
|
|
|
let req = r#"{
|
2016-05-25 13:27:03 +02:00
|
|
|
"jsonrpc": "2.0",
|
2016-05-31 19:30:40 +02:00
|
|
|
"method": "eth_getBlockTransactionCountByNumber",
|
|
|
|
"params": [
|
2016-07-06 11:23:29 +02:00
|
|
|
"#.to_owned() + &::serde_json::to_string(&NU256::from(num)).unwrap() + r#"
|
2016-05-31 19:30:40 +02:00
|
|
|
],
|
|
|
|
"id": "# + format!("{}", *id).as_ref() + r#"
|
2016-05-25 13:27:03 +02:00
|
|
|
}"#;
|
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let res = r#"{"jsonrpc":"2.0","result":""#.to_owned()
|
2016-09-02 11:38:16 +02:00
|
|
|
+ format!("0x{:x}", count).as_ref()
|
2016-05-31 19:30:40 +02:00
|
|
|
+ r#"","id":"#
|
|
|
|
+ format!("{}", *id).as_ref() + r#"}"#;
|
|
|
|
*id += 1;
|
|
|
|
(req, res)
|
|
|
|
}
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let tester = EthTester::from_chain(&chain);
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let mut id = 1;
|
|
|
|
for b in chain.blocks_rlp().iter().filter(|b| Block::is_good(b)).map(|b| BlockView::new(b)) {
|
|
|
|
let count = b.transactions_count();
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let hash = b.sha3();
|
|
|
|
let number = b.header_view().number();
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
let (req, res) = by_hash(hash, count, &mut id);
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
2016-05-24 16:56:09 +02:00
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
// uncles can share block numbers, so skip them.
|
2016-12-09 23:01:43 +01:00
|
|
|
if tester.client.block_hash(BlockId::Number(number)) == Some(hash) {
|
2016-05-31 19:30:40 +02:00
|
|
|
let (req, res) = by_number(number, count, &mut id);
|
2016-09-01 12:00:00 +02:00
|
|
|
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
|
2016-05-24 16:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 19:30:40 +02:00
|
|
|
|
2016-08-04 18:17:39 +02:00
|
|
|
#[test]
|
|
|
|
fn starting_nonce_test() {
|
2016-09-07 10:36:18 +02:00
|
|
|
let tester = EthTester::from_spec(Spec::load(POSITIVE_NONCE_SPEC).expect("invalid chain spec"));
|
2016-08-15 15:09:00 +02:00
|
|
|
let address = Address::from(10);
|
2016-08-04 18:17:39 +02:00
|
|
|
|
2016-09-01 12:00:00 +02:00
|
|
|
let sample = tester.handler.handle_request_sync(&(r#"
|
2016-08-04 18:17:39 +02:00
|
|
|
{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"method": "eth_getTransactionCount",
|
|
|
|
"params": [""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"", "latest"],
|
|
|
|
"id": 15
|
|
|
|
}
|
|
|
|
"#)
|
|
|
|
).unwrap();
|
|
|
|
|
2016-09-02 11:38:16 +02:00
|
|
|
assert_eq!(r#"{"jsonrpc":"2.0","result":"0x100","id":15}"#, &sample);
|
2016-08-04 18:17:39 +02:00
|
|
|
}
|
|
|
|
|
2016-05-31 19:30:40 +02:00
|
|
|
register_test!(eth_transaction_count_1, verify_transaction_counts, "BlockchainTests/bcWalletTest");
|
|
|
|
register_test!(eth_transaction_count_2, verify_transaction_counts, "BlockchainTests/bcTotalDifficultyTest");
|
2016-06-01 12:54:47 +02:00
|
|
|
register_test!(eth_transaction_count_3, verify_transaction_counts, "BlockchainTests/bcGasPricerTest");
|