fixed eth_getCode and added tests for it

This commit is contained in:
debris
2016-03-13 14:45:39 +01:00
parent c2b3ba533b
commit 00820c342a
4 changed files with 29 additions and 4 deletions

View File

@@ -44,6 +44,8 @@ pub struct TestBlockChainClient {
pub balances: RwLock<HashMap<Address, U256>>,
/// Storage.
pub storage: RwLock<HashMap<(Address, H256), H256>>,
/// Code.
pub code: RwLock<HashMap<Address, Bytes>>,
}
#[derive(Clone)]
@@ -77,16 +79,24 @@ impl TestBlockChainClient {
difficulty: RwLock::new(From::from(0)),
balances: RwLock::new(HashMap::new()),
storage: RwLock::new(HashMap::new()),
code: RwLock::new(HashMap::new()),
};
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
client.genesis_hash = client.last_hash.read().unwrap().clone();
client
}
/// Set code at given address.
pub fn set_code(&mut self, address: Address, code: Bytes) {
self.code.write().unwrap().insert(address, code);
}
/// Set balance at given address.
pub fn set_balance(&mut self, address: Address, balance: U256) {
self.balances.write().unwrap().insert(address, balance);
}
/// Set storage at given address and position.
pub fn set_storage(&mut self, address: Address, position: H256, value: H256) {
self.storage.write().unwrap().insert((address, position), value);
}
@@ -181,8 +191,8 @@ impl BlockChainClient for TestBlockChainClient {
U256::zero()
}
fn code(&self, _address: &Address) -> Option<Bytes> {
unimplemented!();
fn code(&self, address: &Address) -> Option<Bytes> {
self.code.read().unwrap().get(address).cloned()
}
fn balance(&self, address: &Address) -> U256 {