openethereum/rpc/src/v1/tests/eth.rs

516 lines
20 KiB
Rust
Raw Normal View History

// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! rpc integration tests.
use std::env;
use std::sync::Arc;
use accounts::AccountProvider;
`Client` refactoring (#7038) * Improves `BestBlock` comment * Improves `TraceDB` comment * Improves `journaldb::Algorithm` comment. Probably the whole enum should be renamed to `Strategy` or something alike. * Comments some of the `Client`'s fields * Deglobs client imports * Fixes comments * Extracts `import_lock` to `Importer` struct * Extracts `verifier` to `Importer` struct * Extracts `block_queue` to `Importer` struct * Extracts `miner` to `Importer` struct * Extracts `ancient_verifier` to `Importer` struct * Extracts `rng` to `Importer` struct * Extracts `import_old_block` to `Importer` struct * Adds `Nonce` trait * Adds `Balance` trait * Adds `ChainInfo` trait * Fixes imports for tests using `chain_info` method * Adds `BlockInfo` trait * Adds more `ChainInfo` imports * Adds `BlockInfo` imports * Adds `ReopenBlock` trait * Adds `PrepareOpenBlock` trait * Fixes import in tests * Adds `CallContract` trait * Fixes imports in tests using `call_contract` method * Adds `TransactionInfo` trait * Adds `RegistryInfo` trait * Fixes imports in tests using `registry_address` method * Adds `ScheduleInfo` trait * Adds `ImportSealedBlock` trait * Fixes imports in test using `import_sealed_block` method * Adds `BroadcastProposalBlock` trait * Migrates `Miner` to static dispatch * Fixes tests * Moves `calculate_enacted_retracted` to `Importer` * Moves import-related methods to `Importer` * Removes redundant `import_old_block` wrapper * Extracts `import_block*` into separate trait * Fixes tests * Handles `Pending` in `LightFetch` * Handles `Pending` in filters * Handles `Pending` in `ParityClient` * Handles `Pending` in `EthClient` * Removes `BlockId::Pending`, partly refactors dependent code * Adds `StateInfo` trait * Exports `StateOrBlock` and `BlockChain` types from `client` module * Refactors `balance` RPC using generic API * Refactors `storage_at` RPC using generic API * Makes `MinerService::pending_state`'s return type dynamic * Adds `StateOrBlock` and `BlockChain` types * Adds impl of `client::BlockChain` for `Client` * Exports `StateInfo` trait from `client` module * Missing `self` use To be fixed up to "Adds impl of `client::BlockChain` for `Client`" * Adds `number_to_id` and refactors dependent RPC methods * Refactors `code_at` using generic API * Adds `StateClient` trait * Refactors RPC to use `StateClient` trait * Reverts `client::BlockChain` trait stuff, refactors methods to accept `StateOrBlock` * Refactors TestClient * Adds helper function `block_number_to_id` * Uses `block_number_to_id` instead of local function * Handles `Pending` in `list_accounts` and `list_storage_keys` * Attempt to use associated types for state instead of trait objects * Simplifies `state_at_beginning` * Extracts `call` and `call_many` into separate trait * Refactors `build_last_hashes` to accept reference * Exports `Call` type from the module * Refactors `call` and `call_many` to accept state and header * Exports `state_at` in `StateClient` * Exports `pending_block_header` from `MinerService` * Refactors RPC `call` method using new API * Adds missing parentheses * Refactors `parity::call` to use new call API * Update .gitlab-ci.yml fix gitlab lint * Fixes error handling * Refactors `traces::call` and `call_many` to use new call API * Refactors `call_contract` * Refactors `block_header` * Refactors internal RPC method `block` * Moves `estimate_gas` to `Call` trait, refactors parameters * Refactors `estimate_gas` in RPC * Refactors `uncle` * Refactors RPC `transaction` * Covers missing branches * Makes it all compile, fixes compiler grumbles * Adds casts in `blockchain` module * Fixes `PendingBlock` tests, work on `MinerService` * Adds test stubs for StateClient and EngineInfo * Makes `state_db` public * Adds missing impls for `TestBlockChainClient` * Adds trait documentation * Adds missing docs to the `state_db` module * Fixes trivial compilation errors * Moves `code_hash` method to a `BlockInfo` trait * Refactors `Verifier` to be generic over client * Refactors `TransactionFilter` to be generic over client * Refactors `Miner` and `Client` to reflect changes in verifier and txfilter API * Moves `ServiceTransactionChecker` back to `ethcore` * Fixes trait bounds in `Miner` API * Fixes `Client` * Fixes lifetime bound in `FullFamilyParams` * Adds comments to `FullFamilyParams` * Fixes imports in `ethcore` * Fixes BlockNumber handling in `code_at` and `replay_block_transactions` * fix compile issues * First step to redundant trait merge * Fixes compilation error in RPC tests * Adds mock `State` as a stub for `TestClient` * Handles `StateOrBlock::State` in `TestBlockChainClient::balance` * Fixes `transaction_count` RPC * Fixes `transaction_count` * Moves `service_transaction.json` to the `contracts` subfolder * Fixes compilation errors in tests * Refactors client to use `AccountData` * Refactors client to use `BlockChain` * Refactors miner to use aggregate traits * Adds `SealedBlockImporter` trait * Refactors miner to use `SealedBlockImporter` trait * Removes unused imports * Simplifies `RegistryInfo::registry_address` * Fixes indentation * Removes commented out trait bound
2018-03-03 18:42:13 +01:00
use ethcore::client::{BlockChainClient, Client, ClientConfig, ChainInfo, ImportBlock};
use ethcore::ethereum;
New Transaction Queue implementation (#8074) * Implementation of Verifier, Scoring and Ready. * Queue in progress. * TransactionPool. * Prepare for txpool release. * Miner refactor [WiP] * WiP reworking miner. * Make it compile. * Add some docs. * Split blockchain access to a separate file. * Work on miner API. * Fix ethcore tests. * Refactor miner interface for sealing/work packages. * Implement next nonce. * RPC compiles. * Implement couple of missing methdods for RPC. * Add transaction queue listeners. * Compiles! * Clean-up and parallelize. * Get rid of RefCell in header. * Revert "Get rid of RefCell in header." This reverts commit 0f2424c9b7319a786e1565ea2a8a6d801a21b4fb. * Override Sync requirement. * Fix status display. * Unify logging. * Extract some cheap checks. * Measurements and optimizations. * Fix scoring bug, heap size of bug and add cache * Disable tx queueing and parallel verification. * Make ethcore and ethcore-miner compile again. * Make RPC compile again. * Bunch of txpool tests. * Migrate transaction queue tests. * Nonce Cap * Nonce cap cache and tests. * Remove stale future transactions from the queue. * Optimize scoring and write some tests. * Simple penalization. * Clean up and support for different scoring algorithms. * Add CLI parameters for the new queue. * Remove banning queue. * Disable debug build. * Change per_sender limit to be 1% instead of 5% * Avoid cloning when propagating transactions. * Remove old todo. * Post-review fixes. * Fix miner options default. * Implement back ready transactions for light client. * Get rid of from_pending_block * Pass rejection reason. * Add more details to drop. * Rollback heap size of. * Avoid cloning hashes when propagating and include more details on rejection. * Fix tests. * Introduce nonces cache. * Remove uneccessary hashes allocation. * Lower the mem limit. * Re-enable parallel verification. * Add miner log. Don't check the type if not below min_gas_price. * Add more traces, fix disabling miner. * Fix creating pending blocks twice on AuRa authorities. * Fix tests. * re-use pending blocks in AuRa * Use reseal_min_period to prevent too frequent update_sealing. * Fix log to contain hash not sender. * Optimize local transactions. * Fix aura tests. * Update locks comments. * Get rid of unsafe Sync impl. * Review fixes. * Remove excessive matches. * Fix compilation errors. * Use new pool in private transactions. * Fix private-tx test. * Fix secret store tests. * Actually use gas_floor_target * Fix config tests. * Fix pool tests. * Address grumbles.
2018-04-13 17:34:27 +02:00
use ethcore::miner::Miner;
use ethcore::spec::{Genesis, Spec};
use ethcore::test_helpers;
use ethcore::verification::VerifierType;
use ethcore::verification::queue::kind::blocks::Unverified;
use ethereum_types::{H256, Address};
use ethjson::blockchain::BlockChain;
use ethjson::spec::ForkSpec;
use io::IoChannel;
use miner::external::ExternalMiner;
use parity_runtime::Runtime;
use parking_lot::Mutex;
use types::ids::BlockId;
use jsonrpc_core::IoHandler;
use v1::helpers::dispatch::{self, FullDispatcher};
use v1::helpers::nonce;
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
use v1::impls::{EthClient, EthClientOptions, SigningUnsafeClient};
use v1::metadata::Metadata;
use v1::tests::helpers::{TestSnapshotService, TestSyncProvider, Config};
use v1::traits::{Eth, EthSigning};
use v1::types::U256 as NU256;
fn account_provider() -> Arc<AccountProvider> {
Arc::new(AccountProvider::transient_provider())
}
fn sync_provider() -> Arc<TestSyncProvider> {
Arc::new(TestSyncProvider::new(Config {
network_id: 3,
num_peers: 120,
}))
}
fn miner_service(spec: &Spec) -> Arc<Miner> {
Arc::new(Miner::new_for_tests(spec, None))
}
fn snapshot_service() -> Arc<TestSnapshotService> {
Arc::new(TestSnapshotService::new())
}
fn make_spec(chain: &BlockChain) -> Spec {
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).expect("unable to set genesis state");
spec.overwrite_genesis_params(genesis);
assert!(spec.is_state_root_valid());
spec
}
struct EthTester {
`Client` refactoring (#7038) * Improves `BestBlock` comment * Improves `TraceDB` comment * Improves `journaldb::Algorithm` comment. Probably the whole enum should be renamed to `Strategy` or something alike. * Comments some of the `Client`'s fields * Deglobs client imports * Fixes comments * Extracts `import_lock` to `Importer` struct * Extracts `verifier` to `Importer` struct * Extracts `block_queue` to `Importer` struct * Extracts `miner` to `Importer` struct * Extracts `ancient_verifier` to `Importer` struct * Extracts `rng` to `Importer` struct * Extracts `import_old_block` to `Importer` struct * Adds `Nonce` trait * Adds `Balance` trait * Adds `ChainInfo` trait * Fixes imports for tests using `chain_info` method * Adds `BlockInfo` trait * Adds more `ChainInfo` imports * Adds `BlockInfo` imports * Adds `ReopenBlock` trait * Adds `PrepareOpenBlock` trait * Fixes import in tests * Adds `CallContract` trait * Fixes imports in tests using `call_contract` method * Adds `TransactionInfo` trait * Adds `RegistryInfo` trait * Fixes imports in tests using `registry_address` method * Adds `ScheduleInfo` trait * Adds `ImportSealedBlock` trait * Fixes imports in test using `import_sealed_block` method * Adds `BroadcastProposalBlock` trait * Migrates `Miner` to static dispatch * Fixes tests * Moves `calculate_enacted_retracted` to `Importer` * Moves import-related methods to `Importer` * Removes redundant `import_old_block` wrapper * Extracts `import_block*` into separate trait * Fixes tests * Handles `Pending` in `LightFetch` * Handles `Pending` in filters * Handles `Pending` in `ParityClient` * Handles `Pending` in `EthClient` * Removes `BlockId::Pending`, partly refactors dependent code * Adds `StateInfo` trait * Exports `StateOrBlock` and `BlockChain` types from `client` module * Refactors `balance` RPC using generic API * Refactors `storage_at` RPC using generic API * Makes `MinerService::pending_state`'s return type dynamic * Adds `StateOrBlock` and `BlockChain` types * Adds impl of `client::BlockChain` for `Client` * Exports `StateInfo` trait from `client` module * Missing `self` use To be fixed up to "Adds impl of `client::BlockChain` for `Client`" * Adds `number_to_id` and refactors dependent RPC methods * Refactors `code_at` using generic API * Adds `StateClient` trait * Refactors RPC to use `StateClient` trait * Reverts `client::BlockChain` trait stuff, refactors methods to accept `StateOrBlock` * Refactors TestClient * Adds helper function `block_number_to_id` * Uses `block_number_to_id` instead of local function * Handles `Pending` in `list_accounts` and `list_storage_keys` * Attempt to use associated types for state instead of trait objects * Simplifies `state_at_beginning` * Extracts `call` and `call_many` into separate trait * Refactors `build_last_hashes` to accept reference * Exports `Call` type from the module * Refactors `call` and `call_many` to accept state and header * Exports `state_at` in `StateClient` * Exports `pending_block_header` from `MinerService` * Refactors RPC `call` method using new API * Adds missing parentheses * Refactors `parity::call` to use new call API * Update .gitlab-ci.yml fix gitlab lint * Fixes error handling * Refactors `traces::call` and `call_many` to use new call API * Refactors `call_contract` * Refactors `block_header` * Refactors internal RPC method `block` * Moves `estimate_gas` to `Call` trait, refactors parameters * Refactors `estimate_gas` in RPC * Refactors `uncle` * Refactors RPC `transaction` * Covers missing branches * Makes it all compile, fixes compiler grumbles * Adds casts in `blockchain` module * Fixes `PendingBlock` tests, work on `MinerService` * Adds test stubs for StateClient and EngineInfo * Makes `state_db` public * Adds missing impls for `TestBlockChainClient` * Adds trait documentation * Adds missing docs to the `state_db` module * Fixes trivial compilation errors * Moves `code_hash` method to a `BlockInfo` trait * Refactors `Verifier` to be generic over client * Refactors `TransactionFilter` to be generic over client * Refactors `Miner` and `Client` to reflect changes in verifier and txfilter API * Moves `ServiceTransactionChecker` back to `ethcore` * Fixes trait bounds in `Miner` API * Fixes `Client` * Fixes lifetime bound in `FullFamilyParams` * Adds comments to `FullFamilyParams` * Fixes imports in `ethcore` * Fixes BlockNumber handling in `code_at` and `replay_block_transactions` * fix compile issues * First step to redundant trait merge * Fixes compilation error in RPC tests * Adds mock `State` as a stub for `TestClient` * Handles `StateOrBlock::State` in `TestBlockChainClient::balance` * Fixes `transaction_count` RPC * Fixes `transaction_count` * Moves `service_transaction.json` to the `contracts` subfolder * Fixes compilation errors in tests * Refactors client to use `AccountData` * Refactors client to use `BlockChain` * Refactors miner to use aggregate traits * Adds `SealedBlockImporter` trait * Refactors miner to use `SealedBlockImporter` trait * Removes unused imports * Simplifies `RegistryInfo::registry_address` * Fixes indentation * Removes commented out trait bound
2018-03-03 18:42:13 +01:00
_miner: Arc<Miner>,
_runtime: Runtime,
_snapshot: Arc<TestSnapshotService>,
accounts: Arc<AccountProvider>,
client: Arc<Client>,
handler: IoHandler<Metadata>,
}
impl EthTester {
2016-05-31 19:30:40 +02:00
fn from_chain(chain: &BlockChain) -> Self {
let tester = if ::ethjson::blockchain::Engine::NoProof == chain.engine {
let mut config = ClientConfig::default();
config.verifier_type = VerifierType::CanonNoSeal;
config.check_seal = false;
Self::from_spec_conf(make_spec(chain), config)
} else {
Self::from_spec(make_spec(chain))
};
for b in chain.blocks_rlp() {
if let Ok(block) = Unverified::from_rlp(b) {
let _ = tester.client.import_block(block);
tester.client.flush_queue();
tester.client.import_verified_blocks();
}
}
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());
tester
}
fn from_spec(spec: Spec) -> Self {
let config = ClientConfig::default();
Self::from_spec_conf(spec, config)
}
fn from_spec_conf(spec: Spec, config: ClientConfig) -> Self {
let runtime = Runtime::with_thread_count(1);
let account_provider = account_provider();
let ap = account_provider.clone();
let accounts = Arc::new(move || ap.accounts().unwrap_or_default()) as _;
let miner_service = miner_service(&spec);
let snapshot_service = snapshot_service();
let client = Client::new(
config,
&spec,
test_helpers::new_db(),
miner_service.clone(),
IoChannel::disconnected(),
).unwrap();
2016-06-01 13:03:26 +02:00
let sync_provider = sync_provider();
let external_miner = Arc::new(ExternalMiner::default());
2016-05-31 21:50:25 +02:00
let eth_client = EthClient::new(
&client,
&snapshot_service,
2016-05-31 21:50:25 +02:00
&sync_provider,
&accounts,
2016-05-31 21:50:25 +02:00
&miner_service,
&external_miner,
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
EthClientOptions {
pending_nonce_from_queue: false,
allow_pending_receipt_query: true,
send_block_number_in_get_work: true,
gas_price_percentile: 50,
allow_experimental_rpcs: true,
allow_missing_blocks: false
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
},
2016-05-31 21:50:25 +02:00
);
2017-02-08 17:57:18 +01:00
let reservations = Arc::new(Mutex::new(nonce::Reservations::new(runtime.executor())));
let dispatcher = FullDispatcher::new(client.clone(), miner_service.clone(), reservations, 50);
let signer = Arc::new(dispatch::Signer::new(account_provider.clone())) as _;
let eth_sign = SigningUnsafeClient::new(
&signer,
2017-02-08 17:57:18 +01:00
dispatcher,
);
let mut handler = IoHandler::default();
handler.extend_with(eth_client.to_delegate());
handler.extend_with(eth_sign.to_delegate());
EthTester {
_miner: miner_service,
_runtime: runtime,
_snapshot: snapshot_service,
accounts: account_provider,
client: client,
handler: handler,
}
}
}
#[test]
fn harness_works() {
let chain: BlockChain = extract_chain!("BlockchainTests/bcWalletTest/wallet2outOf3txs");
2016-05-31 19:30:40 +02:00
let _ = EthTester::from_chain(&chain);
}
#[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);
// 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();
assert_eq!(tester.handler.handle_request_sync(req_latest).unwrap(), res_latest);
// 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();
assert_eq!(tester.handler.handle_request_sync(req_new_acc).unwrap(), res_new_acc);
}
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
#[test]
fn eth_get_proof() {
let chain = extract_chain!("BlockchainTests/bcWalletTest/wallet2outOf3txs");
let tester = EthTester::from_chain(&chain);
// final account state
let req_latest = r#"{
"jsonrpc": "2.0",
"method": "eth_getProof",
"params": ["0xaaaf5374fce5edbc8e2a8697c15331677e6ebaaa", [], "latest"],
"id": 1
}"#;
let res_latest = r#","address":"0xaaaf5374fce5edbc8e2a8697c15331677e6ebaaa","balance":"0x9","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":1}"#.to_owned();
assert!(tester.handler.handle_request_sync(req_latest).unwrap().to_string().ends_with(res_latest.as_str()));
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
// non-existant account
let req_new_acc = r#"{
"jsonrpc": "2.0",
"method": "eth_getProof",
"params": ["0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",[],"latest"],
"id": 3
}"#;
let res_new_acc = r#","address":"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","balance":"0x0","codeHash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","nonce":"0x0","storageHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","storageProof":[]},"id":3}"#.to_owned();
assert!(tester.handler.handle_request_sync(req_new_acc).unwrap().to_string().ends_with(res_new_acc.as_str()));
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
}
#[test]
fn eth_block_number() {
let chain = extract_chain!("BlockchainTests/bcGasPricerTest/RPC_API_Test");
2016-05-31 19:30:40 +02:00
let tester = EthTester::from_chain(&chain);
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();
assert_eq!(tester.handler.handle_request_sync(req_number).unwrap(), res_number);
}
#[test]
fn eth_get_block() {
let chain = extract_chain!("BlockchainTests/bcGasPricerTest/RPC_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":"0x1df5d44","gasUsed":"0x0","hash":"0xcded1bc807465a72e2d54697076ab858f28b15d4beaae8faa47339c8eee386a3","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x8888f1f195afa192cfee860698584c030f4c9db1","mixHash":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","nonce":"0x0102030405060708","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":["0xa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","0x880102030405060708"],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x200","stateRoot":"0x7dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1","timestamp":"0x54c98c81","totalDifficulty":"0x20000","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[]},"id":1}"#;
assert_eq!(tester.handler.handle_request_sync(req_block).unwrap(), res_block);
}
#[test]
fn eth_get_block_by_hash() {
let chain = extract_chain!("BlockchainTests/bcGasPricerTest/RPC_API_Test");
let tester = EthTester::from_chain(&chain);
// We're looking for block number 4 from "RPC_API_Test_Frontier"
let req_block = r#"{"method":"eth_getBlockByHash","params":["0xaddb9e39795e9e041c936b88a2577802569f34afded0948707b074caa3163a87",false],"id":1,"jsonrpc":"2.0"}"#;
let res_block = r#"{"jsonrpc":"2.0","result":{"author":"0x8888f1f195afa192cfee860698584c030f4c9db1","difficulty":"0x20080","extraData":"0x","gasLimit":"0x1dd7ea0","gasUsed":"0x5458","hash":"0xaddb9e39795e9e041c936b88a2577802569f34afded0948707b074caa3163a87","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x8888f1f195afa192cfee860698584c030f4c9db1","mixHash":"0x713b0b31f6e72d8cb7367eaf59447ea531f209fc80e6379edd9f8d3bb73931c4","nonce":"0x4534b406bc23b86d","number":"0x4","parentHash":"0x17567aa5995b703736e32972289d68af50543acc4d56d37e8ad1fea7252cac4a","receiptsRoot":"0x7ed8026cf72ed0e98e6fd53ab406e51ffd34397d9da0052494ff41376fda7b5f","sealFields":["0xa0713b0b31f6e72d8cb7367eaf59447ea531f209fc80e6379edd9f8d3bb73931c4","0x884534b406bc23b86d"],"sha3Uncles":"0xe588a44b3e320e72e70b32b531f3ac0d432e756120135ae8fe5fa10895196b40","size":"0x661","stateRoot":"0x68805721294e365020aca15ed56c360d9dc2cf03cbeff84c9b84b8aed023bfb5","timestamp":"0x5bbdf772","totalDifficulty":"0xa00c0","transactions":["0xb094b9dc356dbb8b256402c6d5709288066ad6a372c90c9c516f14277545fd58"],"transactionsRoot":"0x97a593d8d7e15b57f5c6bb25bc6c325463ef99f874bc08a78656c3ab5cb23262","uncles":["0x86b48f5186c4b0882d3dca7977aa37840008832ef092f8ef797019dc74bfa8c7","0x2da9d062c11d536f0f1cc2a4e0111597c79926958d0fc26ae1a2d07d1a3bf47d"]},"id":1}"#;
assert_eq!(tester.handler.handle_request_sync(req_block).unwrap(), res_block);
}
// 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": {
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"blockReward": "0x4563918244F40000",
"durationLimit": "0x0d",
"homesteadTransition": "0xffffffffffffffff",
"daoHardforkTransition": "0xffffffffffffffff",
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
"daoHardforkAccounts": []
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"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" }
}
}
"#;
const POSITIVE_NONCE_SPEC: &'static [u8] = br#"{
"name": "Frontier (Test)",
"engine": {
"Ethash": {
"params": {
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"blockReward": "0x4563918244F40000",
"durationLimit": "0x0d",
"homesteadTransition": "0xffffffffffffffff",
"daoHardforkTransition": "0xffffffffffffffff",
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
"daoHardforkAccounts": []
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"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" }
}
}
"#;
#[test]
fn eth_transaction_count() {
let secret = "8a283037bb19c4fed7b1c569e40c7dcff366165eb869110a1b11532963eb9cb2".parse().unwrap();
let tester = EthTester::from_spec(Spec::load(&env::temp_dir(), TRANSACTION_COUNT_SPEC).expect("invalid chain spec"));
let address = tester.accounts.insert_account(secret, &"".into()).unwrap();
tester.accounts.unlock_account_permanently(address, "".into()).unwrap();
let req_before = r#"{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [""#.to_owned() + format!("0x{:x}", 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}"#;
assert_eq!(tester.handler.handle_request_sync(&req_before).unwrap(), res_before);
let req_send_trans = r#"{
"jsonrpc": "2.0",
"method": "eth_sendTransaction",
"params": [{
"from": ""#.to_owned() + format!("0x{:x}", address).as_ref() + r#"",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x30000",
2016-09-02 11:38:16 +02:00
"gasPrice": "0x1",
"value": "0x9184e72a"
}],
"id": 16
}"#;
// dispatch the transaction.
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#"{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [""#.to_owned() + format!("0x{:x}", 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}"#;
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#"{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [""#.to_owned() + format!("0x{:x}", 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}"#;
assert_eq!(&tester.handler.handle_request_sync(&req_after_pending).unwrap(), res_after_pending);
2016-05-31 19:30:40 +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-31 19:30:40 +02:00
let _panic = PanicHandler(name);
2016-05-31 19:30:40 +02:00
fn by_hash(hash: H256, count: usize, id: &mut usize) -> (String, String) {
let req = r#"{
"jsonrpc": "2.0",
2016-05-31 19:30:40 +02:00
"method": "eth_getBlockTransactionCountByHash",
"params": [
""#.to_owned() + format!("0x{:x}", hash).as_ref() + r#""
2016-05-31 19:30:40 +02:00
],
"id": "# + format!("{}", *id).as_ref() + r#"
}"#;
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-31 19:30:40 +02:00
fn by_number(num: u64, count: usize, id: &mut usize) -> (String, String) {
let req = r#"{
"jsonrpc": "2.0",
2016-05-31 19:30:40 +02:00
"method": "eth_getBlockTransactionCountByNumber",
"params": [
"#.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-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-31 19:30:40 +02:00
let tester = EthTester::from_chain(&chain);
2016-05-31 19:30:40 +02:00
let mut id = 1;
for b in chain.blocks_rlp().into_iter().filter_map(|b| Unverified::from_rlp(b).ok()) {
let count = b.transactions.len();
let hash = b.header.hash();
let number = b.header.number();
2016-05-31 19:30:40 +02:00
let (req, res) = by_hash(hash, count, &mut id);
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
2016-05-31 19:30:40 +02:00
// uncles can share block numbers, so skip them.
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);
assert_eq!(tester.handler.handle_request_sync(&req), Some(res));
}
}
}
2016-05-31 19:30:40 +02:00
#[test]
fn starting_nonce_test() {
let tester = EthTester::from_spec(Spec::load(&env::temp_dir(), POSITIVE_NONCE_SPEC).expect("invalid chain spec"));
let address = Address::from(10);
let sample = tester.handler.handle_request_sync(&(r#"
{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [""#.to_owned() + format!("0x{:x}", 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);
}
register_test!(eth_transaction_count_1, verify_transaction_counts, "BlockchainTests/bcWalletTest/wallet2outOf3txs");
register_test!(eth_transaction_count_2, verify_transaction_counts, "BlockchainTests/bcTotalDifficultyTest/sideChainWithMoreTransactions");
register_test!(eth_transaction_count_3, verify_transaction_counts, "BlockchainTests/bcGasPricerTest/RPC_API_Test");