Skip to content

Commit

Permalink
clean the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hackfisher committed Dec 9, 2019
1 parent 22264dd commit 10ffaee
Showing 1 changed file with 33 additions and 73 deletions.
106 changes: 33 additions & 73 deletions srml/eth-relay/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sr_eth_primitives::{

use hex_literal::hex;
use rustc_hex::FromHex;
use sha3::{Digest, Keccak256, Keccak512};
use sha3::Keccak256;
use std::str::FromStr;

#[test]
Expand Down Expand Up @@ -87,62 +87,32 @@ fn verify_receipt_proof() {
fn relay_header() {
ExtBuilder::default().monied(true).build().execute_with(|| {
// 6760579
// let mixh1 = H256::from(hex!("5a85e328a8bb041a386ffb25db029b7f0df4665a8a55b331b30a576761404fa6"));
// let nonce1 = H64::from(hex!("650ea83006bb108d"));
//
// let header1 = EthHeader {
// parent_hash: H256::from(hex!("91553997d11a1d978f2ea363f230f5f525aee914a726d01e1deb4ea51de315cd")),
// timestamp: 1573560715,
// number: 6760579,
// author: Address::from(hex!("d7a15baeb7ea05c9660cbe03fb7999c2c2e57625")),
// transactions_root: H256::from(hex!("c2b9e612bdac9d73d53ab38cafa959e5703dc078a9d5b184c65ee38bc471b5bf")),
// uncles_hash: H256::from(hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")),
// extra_data: "41746c616e7469632043727970746f".from_hex().unwrap(),
// state_root: H256::from(hex!("a21cdf375ebef58f606c298d6211f4edee58f2dd6430edbdd0ed3cd886a16863")),
// receipts_root: H256::from(hex!("4c573edd96da310fefc3ced2d70831173e4684728c963330d990cf360aed8550")),
// log_bloom: Bloom::from_str("040000411080018200400100100020100808080020130000004000000a80040000001000000400004010800004811000000000800604002004000000002300820008181000000a820142010c0000010418030040080010080010280018200408000020800208120100000000001828000000000200000800000080511508c0008004100482000800040080000411409000000d20400000056000000802400006420002801000108140202100000804109008000150800140000020290028404000040102800000002000020000811004020080008000100411300100422420060210100100110124080000800084022021000200808005500000000000012000").unwrap(),
// gas_used: 0x220d13.into(),
// gas_limit: 0x7a121d.into(),
// difficulty: 0x269921540_u64.into(),
// seal: vec![rlp::encode(&mixh1), rlp::encode(&nonce1)],
// hash: Some(H256::from(hex!("f1a5bc27877e219b859b0bb1f2f440134553019f9bb5a2eca7a4703263e736c9"))),
// };

let mixh1 = H256::from(hex!("c4b28f4b671b2e675634f596840d3115ce3df0ab38b6608a69371da16a3455aa"));
let nonce1 = H64::from(hex!("7afbefa403b138fa"));
// #6890091
// https://api-ropsten.etherscan.io/api?module=proxy&action=eth_getBlockByNumber&tag=0x69226b&boolean=true&apikey=YourApiKeyToken
// https://jsoneditoronline.org/
let mixh1 = H256::from(hex!("5a85e328a8bb041a386ffb25db029b7f0df4665a8a55b331b30a576761404fa6"));
let nonce1 = H64::from(hex!("650ea83006bb108d"));

let header1 = EthHeader {
parent_hash: H256::from(hex!("8a18726cacb45b078bfe6491510cfa2dd578a70be2a217f416253cf3e94adbd2")),
timestamp: 0x5de5246c,
number: 0x69226b,
author: Address::from(hex!("4ccfb3039b78d3938588157564c9ad559bafab94")),
transactions_root: H256::from(hex!("e3ab46e9eeb65fea6b0b1ffd07587f3ee7741b66f16a0b63a3b0c01900387833")),
parent_hash: H256::from(hex!("91553997d11a1d978f2ea363f230f5f525aee914a726d01e1deb4ea51de315cd")),
timestamp: 1573560715,
number: 6760579,
author: Address::from(hex!("d7a15baeb7ea05c9660cbe03fb7999c2c2e57625")),
transactions_root: H256::from(hex!("c2b9e612bdac9d73d53ab38cafa959e5703dc078a9d5b184c65ee38bc471b5bf")),
uncles_hash: H256::from(hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")),
extra_data: "d983010906846765746889676f312e31312e3133856c696e7578".from_hex().unwrap(),
state_root: H256::from(hex!("de1df18f7da776a86119d17373d252d3591b5a4270e14113701d27c852d25313")),
receipts_root: H256::from(hex!("9c9eb20b6f9176864630f84aa11f33969a355efa85b2eb1e386a5b1ea3599089")),
log_bloom: Bloom::from_str("0420000400000018000400400402044000088100000088000000010000040800202000002000a0000000000200004000800100000200000000000020003400000000000004002000000000080102004400000000010400008001000000000020000000009200100000000000004408040100000010000010022002130002000600048200000000000000004000002410000008000000000008021800100000000704010008080000200081000000004002000000009010c000010082000040400104020200000000040180000000000a803000000000002212000000000061000010000001010000400020000000002000020008008100040000005200000000").unwrap(),
gas_used: 0x769975.into(),
gas_limit: 0x7a1200.into(),
difficulty: 0xf4009f4b_u64.into(),
extra_data: "41746c616e7469632043727970746f".from_hex().unwrap(),
state_root: H256::from(hex!("a21cdf375ebef58f606c298d6211f4edee58f2dd6430edbdd0ed3cd886a16863")),
receipts_root: H256::from(hex!("4c573edd96da310fefc3ced2d70831173e4684728c963330d990cf360aed8550")),
log_bloom: Bloom::from_str("040000411080018200400100100020100808080020130000004000000a80040000001000000400004010800004811000000000800604002004000000002300820008181000000a820142010c0000010418030040080010080010280018200408000020800208120100000000001828000000000200000800000080511508c0008004100482000800040080000411409000000d20400000056000000802400006420002801000108140202100000804109008000150800140000020290028404000040102800000002000020000811004020080008000100411300100422420060210100100110124080000800084022021000200808005500000000000012000").unwrap(),
gas_used: 0x220d13.into(),
gas_limit: 0x7a121d.into(),
difficulty: 0x269921540_u64.into(),
seal: vec![rlp::encode(&mixh1), rlp::encode(&nonce1)],
hash: Some(H256::from(hex!("1dafbf6a9825241ea5dfa7c3a54781c0784428f2ef3b588748521f83209d3caa"))),
hash: Some(H256::from(hex!("f1a5bc27877e219b859b0bb1f2f440134553019f9bb5a2eca7a4703263e736c9"))),
};

type DAG = LightDAG<EthereumPatch>;

// let light_dag1 = DAG::new(header1.number().into());
// let partial_header_hash1 = header1.bare_hash();
// let mixhash1 = light_dag1
// .hashimoto(partial_header_hash1, nonce1)
// .0;
// assert_eq!(
// mixhash1,
// mixh1
// );
// #6890091
// https://api-ropsten.etherscan.io/api?module=proxy&action=eth_getBlockByNumber&tag=0x69226b&boolean=true&apikey=YourApiKeyToken
// https://jsoneditoronline.org/

type DAG = LightDAG<EthereumPatch>;

// 6760580
let mixh2 = H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb"));
Expand All @@ -169,18 +139,18 @@ fn relay_header() {

EthRelay::init_genesis_header(&header1, 0x624c22d93f8e59_u64);

let light_dag2 = DAG::new(header2.number().into());
let partial_header_hash2 = header2.bare_hash();

println!("partial_header_hash2: {:?}", partial_header_hash2);

let mixhash2 = light_dag2
.hashimoto(partial_header_hash2, nonce2)
.0;
assert_eq!(
mixhash2,
mixh2
);
// let light_dag2 = DAG::new(header2.number().into());
// let partial_header_hash2 = header2.bare_hash();
//
// println!("partial_header_hash2: {:?}", partial_header_hash2);
//
// let mixhash2 = light_dag2
// .hashimoto(partial_header_hash2, nonce2)
// .0;
// assert_eq!(
// mixhash2,
// mixh2
// );

EthRelay::verify_header(&header2).expect("Verify Failed.");

Expand Down Expand Up @@ -209,16 +179,6 @@ fn relay_header() {
hash: Some(H256::from(hex!("c86b090d12fa61c34f075530618e40a89654d8d85ac6aaa26149fb56b596a15a"))),
};

// let light_dag3 = DAG::new(header3.number().into());
// let partial_header_hash3 = header3.bare_hash();
// let mixhash3 = light_dag3
// .hashimoto(partial_header_hash3, nonce3)
// .0;
// assert_eq!(
// mixhash3,
// mixh3
// );

EthRelay::verify_header(&header3).expect("Verify Failed.");

EthRelay::store_header(&header3).expect("Store Failed.");
Expand Down

0 comments on commit 10ffaee

Please sign in to comment.