diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 6e10a1311..e884e6bc9 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -9,6 +9,7 @@ byteorder = "1" log = "^0.3" rand = "^0.3" rust-crypto = "^0.2" +rustc-serialize = "0.3.24" serde = "~1.0.8" serde_derive = "~1.0.8" serde_json = "~1.0.2" diff --git a/wallet/src/extkey.rs b/wallet/src/extkey.rs index 9e100fed0..714b72c52 100644 --- a/wallet/src/extkey.rs +++ b/wallet/src/extkey.rs @@ -209,7 +209,7 @@ mod test { let secret_key = SecretKey::from_slice(&s, sec.as_slice()).unwrap(); let chaincode = "b7c6740dea1920ec629b3593678f6d8dc40fe6ec1ed824fcde37f476cd6c048c".from_hex().unwrap(); - let fingerprint = "00000000".from_hex().unwrap(); + let fingerprint = "8963be69".from_hex().unwrap(); let depth = 0; let n_child = 0; assert_eq!(extk.key, secret_key); @@ -221,7 +221,7 @@ mod test { #[test] fn extkey_derivation() { - // TODO More test verctors + // TODO More test vectors let s = Secp256k1::new(); let seed = "000102030405060708090a0b0c0d0e0f".from_hex().unwrap(); let extk = ExtendedKey::from_seed(&s, &seed.as_slice()).unwrap(); diff --git a/wallet/src/sender.rs b/wallet/src/sender.rs index dda4edeff..29998913c 100644 --- a/wallet/src/sender.rs +++ b/wallet/src/sender.rs @@ -90,3 +90,43 @@ fn build_send_tx(config: &WalletConfig, ext_key: &ExtendedKey, amount: u64) -> R build::transaction(parts).map_err(&From::from) })? } + +#[cfg(test)] +mod test { + extern crate rustc_serialize as serialize; + + use core::core::build::{input, output, transaction}; + use types::{OutputData, OutputStatus}; + + use secp::Secp256k1; + use super::ExtendedKey; + use self::serialize::hex::FromHex; + + #[test] + // demonstrate that input.commitment == referenced output.commitment + // based on the wallet extended key and the coin being spent + fn output_commitment_equals_input_commitment_on_spend() { + let secp = Secp256k1::new(); + let seed = "000102030405060708090a0b0c0d0e0f".from_hex().unwrap(); + + let ext_key = ExtendedKey::from_seed(&secp, &seed.as_slice()).unwrap(); + + let out_key = ext_key.derive(&secp, 1).unwrap(); + + let coin = OutputData { + fingerprint: out_key.fingerprint, + n_child: out_key.n_child, + value: 5, + status: OutputStatus::Unconfirmed, + }; + + let (tx, _) = transaction(vec![output(coin.value, out_key.key)]).unwrap(); + + let in_key = ext_key.derive(&secp, coin.n_child).unwrap(); + + let (tx2, _) = transaction(vec![input(coin.value, in_key.key)]).unwrap(); + + assert_eq!(in_key.key, out_key.key); + assert_eq!(tx.outputs[0].commitment(), tx2.inputs[0].commitment()); + } +}