Skip to content

Commit

Permalink
Merge pull request #178 from r8d8/issue/add_tests
Browse files Browse the repository at this point in the history
"Morden" as chain name produces incorrect rlp of transaction
  • Loading branch information
ziol-pixel authored Jul 1, 2017
2 parents d192621 + f06130c commit 7bb06ca
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
50 changes: 50 additions & 0 deletions emerald-core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,54 @@ mod tests {
a0b17da8416f42d62192b07ff855f4a8e8e9ee1a2e920e3c407fd9a3bd5e388daa\
a0547981b617c88587bfcd924437f6134b0b75f4484042db0750a2b1c0ccccc597");
}

#[test]
fn should_sign_transaction_for_testnet() {
let tx = Transaction {
nonce: 1048585,
gas_price: /* 21000000000 */
to_32bytes("00000000000000000000000000000\
000000000000000000000000004a817c800"),
gas_limit: 21000,
to: Some("0x163b454d1ccdd0a12e88341b12afb2c98044c599"
.parse::<Address>()
.unwrap()),
value: /* 1 ETC */
to_32bytes("000000000000000000000000000000\
00000000000000001e7751166579880000"),
data: Vec::new(),
};

/*
{
"jsonrpc":"2.0","method":"emerald_signTransaction",
"params":[{"from":"0xc0de379b51d582e1600c76dd1efee8ed024b844a",
"passphrase":"1234567890",
"to":"0x163b454d1ccdd0a12e88341b12afb2c98044c599",
"gas":"0x5208",
"gasPrice":"0x04a817c800",
"value":"0x1e7751166579880000",
"nonce":"0x100009"},
{"chain":"morden"}],
"id":11
}'
*/

let pk = PrivateKey(to_32bytes(
"28b469dc4b039ff63fcd4cb708c668545e644cb25f21df6920aac20e4bc743f7",
));

assert_eq!(tx.to_signed_raw(pk, 62 /*TESTNET_ID*/).unwrap().to_hex(),
"f871\
83\
1000098504a8\
17c800\
82520894163b454d1ccdd0a12e88341b12afb2c980\
44c599891e77511665\
79\
8800\
0080819fa0cc6cd05d41bbbeb71913bf403a09db118f22e4ed7ebf707fcfb483dd1cde\
d890a03c0a3985771bc0f10cf9fe85e3ea3c17132e3f09551eaedb8d2ae97cec3ad9f7");
}

}
8 changes: 7 additions & 1 deletion emerald-core/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn to_chain_name(id: u8) -> Option<String> {
pub fn to_chain_id(name: &str) -> Option<u8> {
match name {
"mainnet" => Some(61),
"testnet" => Some(62),
"testnet" | "morden" => Some(62),
_ => None,
}
}
Expand Down Expand Up @@ -433,4 +433,10 @@ mod tests {

assert!(re.is_match(&timestamp()));
}

#[test]
fn should_convert_to_chain_id() {
assert_eq!(to_chain_id("testnet"), Some(62));
assert_eq!(to_chain_id("testnet"), to_chain_id("morden"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"id":"a928d7c2-b37b-464c-a70b-b9979d59fac4","address":"c0de379b51d582e1600c76dd1efee8ed024b844a","name":null,"description":null,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"c6e9af499c386cfb86bc8bcb71e132bc"},"ciphertext":"c4f6e2f2037c5c8e15cbcb13dc414d8821ad288305cad0d03cb05e57f45632b1","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"f15e7957b423b58986a13127406af823a411796e3cee4aed7f84c6a60834968b","n":1024,"r":8,"p":1},"mac":"b782cf25b6796cfeaec2183b75ca7157a8ac604deaea86129167310969d48cb4"}}

0 comments on commit 7bb06ca

Please sign in to comment.