From 877c4fc818b9f216c5a96154c2f94da19cc1f142 Mon Sep 17 00:00:00 2001 From: r8d8 Date: Sat, 1 Jul 2017 08:32:46 +0300 Subject: [PATCH 1/2] "Morden" as chain name produces incorrect rlp of transaction Added proper handling for 'morden' inside utils --- emerald-core/src/util/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/emerald-core/src/util/mod.rs b/emerald-core/src/util/mod.rs index 8c0b074a..66a0e464 100644 --- a/emerald-core/src/util/mod.rs +++ b/emerald-core/src/util/mod.rs @@ -57,7 +57,7 @@ pub fn to_chain_name(id: u8) -> Option { pub fn to_chain_id(name: &str) -> Option { match name { "mainnet" => Some(61), - "testnet" => Some(62), + "testnet" | "morden" => Some(62), _ => None, } } @@ -433,4 +433,10 @@ mod tests { assert!(re.is_match(×tamp())); } + + #[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")); + } } From f06130c8ed9b4f524eb47800b7ee4030c1ba3852 Mon Sep 17 00:00:00 2001 From: r8d8 Date: Sat, 1 Jul 2017 09:27:14 +0300 Subject: [PATCH 2/2] transaction signing test for testnet --- emerald-core/src/core/transaction.rs | 50 +++++++++++++++++++ ...-46Z--a928d7c2-b37b-464c-a70b-b9979d59fac4 | 1 + 2 files changed, 51 insertions(+) create mode 100644 emerald-core/tests/keystore/serialize/UTC--2017-05-30T06-16-46Z--a928d7c2-b37b-464c-a70b-b9979d59fac4 diff --git a/emerald-core/src/core/transaction.rs b/emerald-core/src/core/transaction.rs index 556eb822..2604941a 100644 --- a/emerald-core/src/core/transaction.rs +++ b/emerald-core/src/core/transaction.rs @@ -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::
() + .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"); + } + } diff --git a/emerald-core/tests/keystore/serialize/UTC--2017-05-30T06-16-46Z--a928d7c2-b37b-464c-a70b-b9979d59fac4 b/emerald-core/tests/keystore/serialize/UTC--2017-05-30T06-16-46Z--a928d7c2-b37b-464c-a70b-b9979d59fac4 new file mode 100644 index 00000000..6cd9eb65 --- /dev/null +++ b/emerald-core/tests/keystore/serialize/UTC--2017-05-30T06-16-46Z--a928d7c2-b37b-464c-a70b-b9979d59fac4 @@ -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"}} \ No newline at end of file