Skip to content

Commit

Permalink
Codebase upgrade (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 authored and tomusdrw committed Jul 10, 2019
1 parent 21cb38c commit f043b22
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 166 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ edition = "2018"

[dependencies]
arrayvec = "0.4.10"
ethabi = "7.0.0"
ethereum-types = "0.5.2"
ethabi = "8.0.0"
ethereum-types = "0.6.0"
futures = "0.1.26"
jsonrpc-core = "11.0.0"
log = "0.4.6"
parking_lot = "0.7.1"
parking_lot = "0.8.0"
rustc-hex = "2.0.1"
serde = { version="1.0.90", features = ["derive"] }
serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0.39"
tokio-timer = "0.1"
url = "1.7.2"
base64 = "0.10.1"
derive_more = "0.14.0"
derive_more = "0.15.0"
# Optional deps
hyper = { version = "0.12.25", optional = true }
hyper-tls = { version = "0.3.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
println!("Accounts: {:?}", accounts);

println!("Calling balance.");
let balance = web3.eth().balance(0.into(), None).wait().unwrap();
let balance = web3.eth().balance("0x0".parse().unwrap(), None).wait().unwrap();
println!("Balance: {}", balance);
}
48 changes: 24 additions & 24 deletions src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ mod tests {

rpc_test! (
Eth:accounts => "eth_accounts";
Value::Array(vec![Value::String("0x0000000000000000000000000000000000000123".into())]) => vec![0x123.into()]
Value::Array(vec![Value::String("0x0000000000000000000000000000000000000123".into())]) => vec![Address::from_low_u64_be(0x123)]
);

rpc_test! (
Expand All @@ -418,7 +418,7 @@ mod tests {

rpc_test! (
Eth:call, CallRequest {
from: None, to: 0x123.into(),
from: None, to: Address::from_low_u64_be(0x123),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
}, None
Expand All @@ -429,7 +429,7 @@ mod tests {

rpc_test! (
Eth:coinbase => "eth_coinbase";
Value::String("0x0000000000000000000000000000000000000123".into()) => 0x123
Value::String("0x0000000000000000000000000000000000000123".into()) => Address::from_low_u64_be(0x123)
);

rpc_test! (
Expand All @@ -449,7 +449,7 @@ mod tests {

rpc_test! (
Eth:estimate_gas, CallRequest {
from: None, to: 0x123.into(),
from: None, to: Address::from_low_u64_be(0x123),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
}, None
Expand All @@ -464,7 +464,7 @@ mod tests {
);

rpc_test! (
Eth:balance, 0x123, None
Eth:balance, Address::from_low_u64_be(0x123), None
=>
"eth_getBalance", vec![r#""0x0000000000000000000000000000000000000123""#, r#""latest""#];
Value::String("0x123".into()) => 0x123
Expand All @@ -477,7 +477,7 @@ mod tests {
);

rpc_test! (
Eth:block:block_by_hash, BlockId::Hash(0x123.into())
Eth:block:block_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123))
=>
"eth_getBlockByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#, r#"false"#];
::serde_json::from_str(EXAMPLE_BLOCK).unwrap()
Expand All @@ -501,7 +501,7 @@ mod tests {
);

rpc_test! (
Eth:block_transaction_count:block_tx_count_by_hash, BlockId::Hash(0x123.into())
Eth:block_transaction_count:block_tx_count_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123))
=>
"eth_getBlockTransactionCountByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#];
Value::String("0x123".into()) => Some(0x123.into())
Expand All @@ -515,7 +515,7 @@ mod tests {
);

rpc_test! (
Eth:code, 0x123, Some(BlockNumber::Pending)
Eth:code, H256::from_low_u64_be(0x123), Some(BlockNumber::Pending)
=>
"eth_getCode", vec![r#""0x0000000000000000000000000000000000000123""#, r#""pending""#];
Value::String("0x0123".into()) => Bytes(vec![0x1, 0x23])
Expand All @@ -527,7 +527,7 @@ mod tests {
);

rpc_test! (
Eth:storage, 0x123, 0x456, None
Eth:storage, Address::from_low_u64_be(0x123), 0x456, None
=>
"eth_getStorageAt", vec![
r#""0x0000000000000000000000000000000000000123""#,
Expand All @@ -538,14 +538,14 @@ mod tests {
);

rpc_test! (
Eth:transaction_count, 0x123, None
Eth:transaction_count, Address::from_low_u64_be(0x123), None
=>
"eth_getTransactionCount", vec![r#""0x0000000000000000000000000000000000000123""#, r#""latest""#];
Value::String("0x123".into()) => 0x123
);

rpc_test! (
Eth:transaction:tx_by_hash, TransactionId::Hash(0x123.into())
Eth:transaction:tx_by_hash, TransactionId::Hash(H256::from_low_u64_be(0x123))
=>
"eth_getTransactionByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#];
::serde_json::from_str(EXAMPLE_TX).unwrap()
Expand All @@ -554,7 +554,7 @@ mod tests {

rpc_test! (
Eth:transaction:tx_by_block_hash_and_index, TransactionId::Block(
BlockId::Hash(0x123.into()),
BlockId::Hash(H256::from_low_u64_be(0x123)),
5.into()
)
=>
Expand All @@ -574,15 +574,15 @@ mod tests {
);

rpc_test! (
Eth:transaction_receipt, 0x123
Eth:transaction_receipt, H256::from_low_u64_be(0x123)
=>
"eth_getTransactionReceipt", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#];
::serde_json::from_str(EXAMPLE_RECEIPT).unwrap()
=> Some(::serde_json::from_str::<TransactionReceipt>(EXAMPLE_RECEIPT).unwrap())
);

rpc_test! (
Eth:uncle:uncle_by_hash, BlockId::Hash(0x123.into()), 5
Eth:uncle:uncle_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123)), 5
=>
"eth_getUncleByBlockHashAndIndex", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#, r#""0x5""#];
::serde_json::from_str(EXAMPLE_BLOCK).unwrap()
Expand All @@ -597,7 +597,7 @@ mod tests {
);

rpc_test! (
Eth:uncle_count:uncle_count_by_hash, BlockId::Hash(0x123.into())
Eth:uncle_count:uncle_count_by_hash, BlockId::Hash(H256::from_low_u64_be(0x123))
=>
"eth_getUncleCountByBlockHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#];
Value::String("0x123".into())=> Some(0x123.into())
Expand All @@ -617,9 +617,9 @@ mod tests {
Value::String("0x0000000000000000000000000000000000000000000000000000000000000456".into()),
Value::String("0x0000000000000000000000000000000000000000000000000000000000000789".into()),
]) => Work {
pow_hash: 0x123.into(),
seed_hash: 0x456.into(),
target: 0x789.into(),
pow_hash: H256::from_low_u64_be(0x123),
seed_hash: H256::from_low_u64_be(0x456),
target: H256::from_low_u64_be(0x789),
number: None,
}
);
Expand All @@ -632,9 +632,9 @@ mod tests {
Value::String("0x0000000000000000000000000000000000000000000000000000000000000789".into()),
Value::Number(5.into()),
]) => Work {
pow_hash: 0x123.into(),
seed_hash: 0x456.into(),
target: 0x789.into(),
pow_hash: H256::from_low_u64_be(0x123),
seed_hash: H256::from_low_u64_be(0x456),
target: H256::from_low_u64_be(0x789),
number: Some(5),
}
);
Expand Down Expand Up @@ -679,18 +679,18 @@ mod tests {
}
=>
"eth_sendTransaction", vec![r#"{"from":"0x0000000000000000000000000000000000000123","gasPrice":"0x1","to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#];
Value::String("0x0000000000000000000000000000000000000000000000000000000000000123".into()) => 0x123
Value::String("0x0000000000000000000000000000000000000000000000000000000000000123".into()) => H256::from_low_u64_be(0x123)
);

rpc_test! (
Eth:sign, 0x123, Bytes(vec![1, 2, 3, 4])
Eth:sign, H256::from_low_u64_be(0x123), Bytes(vec![1, 2, 3, 4])
=>
"eth_sign", vec![r#""0x0000000000000000000000000000000000000123""#, r#""0x01020304""#];
Value::String("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000123".into()) => H520::from_low_u64_be(0x123)
);

rpc_test! (
Eth:submit_hashrate, 0x123, 0x456
Eth:submit_hashrate, 0x123, H256::from_low_u64_be(0x456)
=>
"eth_submitHashrate", vec![r#""0x123""#, r#""0x0000000000000000000000000000000000000000000000000000000000000456""#];
Value::Bool(true) => true
Expand Down
33 changes: 21 additions & 12 deletions src/api/eth_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ mod tests {

use crate::api::Namespace;
use crate::helpers::tests::TestTransport;
use crate::types::{Bytes, FilterBuilder, Log};
use crate::types::{Address, Bytes, FilterBuilder, Log, H256};

use super::EthFilter;

Expand All @@ -284,12 +284,12 @@ mod tests {
fn logs_filter_get_logs() {
// given
let log = Log {
address: 1.into(),
address: Address::from_low_u64_be(1),
topics: vec![],
data: Bytes(vec![]),
block_hash: Some(2.into()),
block_hash: Some(H256::from_low_u64_be(2)),
block_number: Some(1.into()),
transaction_hash: Some(3.into()),
transaction_hash: Some(H256::from_low_u64_be(3)),
transaction_index: Some(0.into()),
log_index: Some(0.into()),
transaction_log_index: Some(0.into()),
Expand All @@ -305,7 +305,7 @@ mod tests {

// when
let filter = FilterBuilder::default()
.topics(None, Some(vec![2.into()]), None, None)
.topics(None, Some(vec![H256::from_low_u64_be(2)]), None, None)
.build();
let filter = eth.create_logs_filter(filter).wait().unwrap();
assert_eq!(filter.id, "0x123".to_owned());
Expand All @@ -326,12 +326,12 @@ mod tests {
fn logs_filter_poll() {
// given
let log = Log {
address: 1.into(),
address: Address::from_low_u64_be(1),
topics: vec![],
data: Bytes(vec![]),
block_hash: Some(2.into()),
block_hash: Some(H256::from_low_u64_be(2)),
block_number: Some(1.into()),
transaction_hash: Some(3.into()),
transaction_hash: Some(H256::from_low_u64_be(3)),
transaction_index: Some(0.into()),
log_index: Some(0.into()),
transaction_log_index: Some(0.into()),
Expand All @@ -346,7 +346,9 @@ mod tests {
let eth = EthFilter::new(&transport);

// when
let filter = FilterBuilder::default().address(vec![2.into()]).build();
let filter = FilterBuilder::default()
.address(vec![Address::from_low_u64_be(2)])
.build();
let filter = eth.create_logs_filter(filter).wait().unwrap();
assert_eq!(filter.id, "0x123".to_owned());
filter.poll().wait()
Expand Down Expand Up @@ -398,7 +400,7 @@ mod tests {
};

// then
assert_eq!(result, Ok(Some(vec![0x456.into()])));
assert_eq!(result, Ok(Some(vec![H256::from_low_u64_be(0x456)])));
transport.assert_request("eth_newBlockFilter", &[]);
transport.assert_request("eth_getFilterChanges", &[r#""0x123""#.into()]);
transport.assert_no_more_requests();
Expand Down Expand Up @@ -428,7 +430,14 @@ mod tests {
};

// then
assert_eq!(result, Ok(vec![0x456.into(), 0x457.into(), 0x458.into(), 0x459.into()]));
assert_eq!(
result,
Ok([0x456, 0x457, 0x458, 0x459]
.iter()
.copied()
.map(H256::from_low_u64_be)
.collect::<Vec<_>>())
);
transport.assert_request("eth_newBlockFilter", &[]);
transport.assert_request("eth_getFilterChanges", &[r#""0x123""#.into()]);
transport.assert_request("eth_getFilterChanges", &[r#""0x123""#.into()]);
Expand Down Expand Up @@ -471,7 +480,7 @@ mod tests {
};

// then
assert_eq!(result, Ok(Some(vec![0x456.into()])));
assert_eq!(result, Ok(Some(vec![H256::from_low_u64_be(0x456)])));
transport.assert_request("eth_newPendingTransactionFilter", &[]);
transport.assert_request("eth_getFilterChanges", &[r#""0x123""#.into()]);
transport.assert_no_more_requests();
Expand Down
6 changes: 3 additions & 3 deletions src/api/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod tests {

rpc_test! (
Personal:list_accounts => "personal_listAccounts";
Value::Array(vec![Value::String("0x0000000000000000000000000000000000000123".into())]) => vec![0x123.into()]
Value::Array(vec![Value::String("0x0000000000000000000000000000000000000123".into())]) => vec![Address::from_low_u64_be(0x123)]
);

rpc_test! (
Expand All @@ -117,15 +117,15 @@ mod tests {
);

rpc_test! (
Personal:unlock_account, 0x123, "hunter2", None
Personal:unlock_account, Address::from_low_u64_be(0x123), "hunter2", None
=>
"personal_unlockAccount", vec![r#""0x0000000000000000000000000000000000000123""#, r#""hunter2""#, r#"null"#];
Value::Bool(true) => true
);

rpc_test! (
Personal:send_transaction, TransactionRequest {
from: 0x123.into(), to: Some(0x123.into()),
from: Address::from_low_u64_be(0x123), to: Some(Address::from_low_u64_be(0x123)),
gas: None, gas_price: Some(0x1.into()),
value: Some(0x1.into()), data: None,
nonce: None, condition: None,
Expand Down
9 changes: 6 additions & 3 deletions src/api/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl<T: Transport> Namespace<T> for Traces<T> {
&self.transport
}
}

impl<T: Transport> Traces<T> {
/// Executes the given call and returns a number of possible traces for it
pub fn call(
Expand Down Expand Up @@ -99,7 +100,9 @@ mod tests {
use futures::Future;

use crate::api::Namespace;
use crate::types::{BlockNumber, BlockTrace, Bytes, CallRequest, Trace, TraceFilterBuilder, TraceType, H256};
use crate::types::{
Address, BlockNumber, BlockTrace, Bytes, CallRequest, Trace, TraceFilterBuilder, TraceType, H256,
};

use super::Traces;

Expand Down Expand Up @@ -180,9 +183,9 @@ mod tests {
}
"#;

rpc_test! (
rpc_test!(
Traces:call, CallRequest {
from: None, to: 0x123.into(),
from: None, to: Address::from_low_u64_be(0x123),
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
}, vec![TraceType::Trace], None
Expand Down
4 changes: 2 additions & 2 deletions src/api/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {

use crate::api::Namespace;
use crate::rpc::Value;
use crate::types::Bytes;
use crate::types::{Bytes, H256};

use super::Web3;

Expand All @@ -57,6 +57,6 @@ mod tests {
Web3:sha3, Bytes(vec![1, 2, 3, 4])
=>
"web3_sha3", vec![r#""0x01020304""#];
Value::String("0x0000000000000000000000000000000000000000000000000000000000000123".into()) => 0x123
Value::String("0x0000000000000000000000000000000000000000000000000000000000000123".into()) => H256::from_low_u64_be(0x123)
);
}
Loading

0 comments on commit f043b22

Please sign in to comment.