implemented rpc eth_estimateGas method, added tests for rpc eth_call and eth_estimateGas

This commit is contained in:
debris
2016-03-20 11:34:19 +01:00
parent d15ce15751
commit aa47d944e1
7 changed files with 107 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ pub use self::client::*;
pub use self::config::{ClientConfig, BlockQueueConfig, BlockChainConfig};
pub use self::ids::{BlockId, TransactionId};
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use executive::Executed;
use std::collections::HashSet;
use util::bytes::Bytes;
@@ -38,7 +39,6 @@ use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry;
use filter::Filter;
use error::{ImportResult, Error};
use executive::Executed;
/// Blockchain database client. Owns and manages a blockchain and a block queue.
pub trait BlockChainClient : Sync + Send {

View File

@@ -50,6 +50,8 @@ pub struct TestBlockChainClient {
pub storage: RwLock<HashMap<(Address, H256), H256>>,
/// Code.
pub code: RwLock<HashMap<Address, Bytes>>,
/// Execution result.
pub execution_result: RwLock<Option<Executed>>,
}
#[derive(Clone)]
@@ -84,12 +86,18 @@ impl TestBlockChainClient {
balances: RwLock::new(HashMap::new()),
storage: RwLock::new(HashMap::new()),
code: RwLock::new(HashMap::new()),
execution_result: RwLock::new(None),
};
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
client.genesis_hash = client.last_hash.read().unwrap().clone();
client
}
/// Set the execution result.
pub fn set_execution_result(&self, result: Executed) {
*self.execution_result.write().unwrap() = Some(result);
}
/// Set the balance of account `address` to `balance`.
pub fn set_balance(&self, address: Address, balance: U256) {
self.balances.write().unwrap().insert(address, balance);
@@ -185,7 +193,7 @@ impl TestBlockChainClient {
impl BlockChainClient for TestBlockChainClient {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> {
unimplemented!()
Ok(self.execution_result.read().unwrap().clone().unwrap())
}
fn block_total_difficulty(&self, _id: BlockId) -> Option<U256> {

View File

@@ -37,7 +37,7 @@ pub fn contract_address(address: &Address, nonce: &U256) -> Address {
}
/// Transaction execution receipt.
#[derive(Debug)]
#[derive(Debug, PartialEq, Clone)]
pub struct Executed {
/// Gas paid up front for execution of transaction.
pub gas: U256,