fixed eth_getCode and added tests for it
This commit is contained in:
@@ -221,7 +221,8 @@ impl<C, S, A> Eth for EthClient<C, S, A> where C: BlockChainClient + 'static, S:
|
||||
// TODO: do not ignore block number param
|
||||
fn code_at(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Address, BlockNumber)>(params)
|
||||
.and_then(|(address, _block_number)| to_value(&take_weak!(self.client).code(&address).map_or_else(Bytes::default, Bytes::new)))
|
||||
.and_then(|(address, _block_number)|
|
||||
to_value(&take_weak!(self.client).code(&address).map_or_else(Bytes::default, Bytes::new)))
|
||||
}
|
||||
|
||||
fn block_by_hash(&self, params: Params) -> Result<Value, Error> {
|
||||
|
||||
@@ -28,6 +28,7 @@ fn blockchain_client() -> Arc<TestBlockChainClient> {
|
||||
client.add_blocks(10, EachBlockWith::Nothing);
|
||||
client.set_balance(Address::from(1), U256::from(5));
|
||||
client.set_storage(Address::from(1), H256::from(4), H256::from(7));
|
||||
client.set_code(Address::from(1), vec![0xff, 0x21]);
|
||||
Arc::new(client)
|
||||
}
|
||||
|
||||
@@ -216,3 +217,16 @@ fn rpc_eth_uncle_count_by_block_number() {
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_code() {
|
||||
let request = r#"{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_getCode",
|
||||
"params": ["0x0000000000000000000000000000000000000001", "latest"],
|
||||
"id": 1
|
||||
}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xff21","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ pub trait Eth: Sized + Send + Sync + 'static {
|
||||
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count_by_number);
|
||||
delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count_by_hash);
|
||||
delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count_by_number);
|
||||
delegate.add_method("eth_code", Eth::code_at);
|
||||
delegate.add_method("eth_getCode", Eth::code_at);
|
||||
delegate.add_method("eth_sendTransaction", Eth::send_transaction);
|
||||
delegate.add_method("eth_call", Eth::call);
|
||||
delegate.add_method("eth_estimateGas", Eth::estimate_gas);
|
||||
|
||||
Reference in New Issue
Block a user