tests for relay

This commit is contained in:
debris 2017-08-25 15:01:47 +02:00
parent 9201a19967
commit 6399b1c8e5
5 changed files with 67 additions and 0 deletions

1
Cargo.lock generated
View File

@ -81,6 +81,7 @@ dependencies = [
"ethabi-contract 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi-derive 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-core 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -15,3 +15,4 @@ error-chain = "0.11.0-rc.2"
ethabi = "4.0"
ethabi-derive = "4.0"
ethabi-contract = "4.0"
rustc-hex = "1.0"

View File

@ -108,3 +108,29 @@ impl<T: Transport> Stream for DepositRelay<T> {
}
}
}
#[cfg(test)]
mod tests {
use rustc_hex::FromHex;
use web3::types::{Log, Bytes};
use contracts::{mainnet, testnet};
use super::deposit_relay_payload;
#[test]
fn test_deposit_relay_payload() {
let mainnet = mainnet::EthereumBridge::default();
let testnet = testnet::KovanBridge::default();
let data = "000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebcccc00000000000000000000000000000000000000000000000000000000000000f0".from_hex().unwrap();
let log = Log {
data: data.into(),
topics: vec!["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c".parse().unwrap()],
transaction_hash: Some("0x884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364".parse().unwrap()),
..Default::default()
};
let payload = deposit_relay_payload(&mainnet, &testnet, log).unwrap();
let expected: Bytes = "26b3293f000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebcccc00000000000000000000000000000000000000000000000000000000000000f0884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364".from_hex().unwrap().into();
assert_eq!(expected, payload);
}
}

View File

@ -14,6 +14,7 @@ extern crate ethabi;
extern crate ethabi_derive;
#[macro_use]
extern crate ethabi_contract;
extern crate rustc_hex;
#[macro_use]
mod macros;

View File

@ -38,3 +38,41 @@ test_app_stream! {
],
testnet_transport => []
}
test_app_stream! {
name => deposit_relay_single_log,
database => Database::default(),
mainnet =>
account => "0x0000000000000000000000000000000000000001",
confirmations => 12;
testnet =>
account => "0x0000000000000000000000000000000000000001",
confirmations => 12;
authorities =>
accounts => [
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000002",
],
signatures => 1;
init => |app, db| create_deposit_relay(app, db).take(2),
expected => vec![0x1005, 0x1006],
mainnet_transport => [
"eth_blockNumber" =>
req => r#"[]"#,
res => r#""0x1011""#;
"eth_getLogs" =>
req => r#"[{"address":["0x0000000000000000000000000000000000000000"],"fromBlock":"0x1","limit":null,"toBlock":"0x1005","topics":[["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c"],[],[],[]]}]"#,
res => r#"[{"address":"0x0000000000000000000000000000000000000000","topics":["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c"],"data":"0x000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebcccc00000000000000000000000000000000000000000000000000000000000000f0","type":"","transactionHash":"0x884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364"}]"#;
"eth_blockNumber" =>
req => r#"[]"#,
res => r#""0x1012""#;
"eth_getLogs" =>
req => r#"[{"address":["0x0000000000000000000000000000000000000000"],"fromBlock":"0x1006","limit":null,"toBlock":"0x1006","topics":[["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c"],[],[],[]]}]"#,
res => r#"[]"#;
],
testnet_transport => [
"eth_sendTransaction" =>
req => r#"[{"data":"0x26b3293f000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebcccc00000000000000000000000000000000000000000000000000000000000000f0884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364","from":"0x0000000000000000000000000000000000000001","gas":"0x0","gasPrice":"0x0","to":"0x0000000000000000000000000000000000000000"}]"#,
res => r#""0x1db8f385535c0d178b8f40016048f3a3cffee8f94e68978ea4b277f57b638f0b""#;
]
}