mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
fix up wallet tests (#101)
fix wallet tests add test to verify input commitment == output commitment on spend
This commit is contained in:
parent
babb6110c4
commit
fa339f3c0b
3 changed files with 43 additions and 2 deletions
|
@ -9,6 +9,7 @@ byteorder = "1"
|
||||||
log = "^0.3"
|
log = "^0.3"
|
||||||
rand = "^0.3"
|
rand = "^0.3"
|
||||||
rust-crypto = "^0.2"
|
rust-crypto = "^0.2"
|
||||||
|
rustc-serialize = "0.3.24"
|
||||||
serde = "~1.0.8"
|
serde = "~1.0.8"
|
||||||
serde_derive = "~1.0.8"
|
serde_derive = "~1.0.8"
|
||||||
serde_json = "~1.0.2"
|
serde_json = "~1.0.2"
|
||||||
|
|
|
@ -209,7 +209,7 @@ mod test {
|
||||||
let secret_key = SecretKey::from_slice(&s, sec.as_slice()).unwrap();
|
let secret_key = SecretKey::from_slice(&s, sec.as_slice()).unwrap();
|
||||||
let chaincode =
|
let chaincode =
|
||||||
"b7c6740dea1920ec629b3593678f6d8dc40fe6ec1ed824fcde37f476cd6c048c".from_hex().unwrap();
|
"b7c6740dea1920ec629b3593678f6d8dc40fe6ec1ed824fcde37f476cd6c048c".from_hex().unwrap();
|
||||||
let fingerprint = "00000000".from_hex().unwrap();
|
let fingerprint = "8963be69".from_hex().unwrap();
|
||||||
let depth = 0;
|
let depth = 0;
|
||||||
let n_child = 0;
|
let n_child = 0;
|
||||||
assert_eq!(extk.key, secret_key);
|
assert_eq!(extk.key, secret_key);
|
||||||
|
@ -221,7 +221,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extkey_derivation() {
|
fn extkey_derivation() {
|
||||||
// TODO More test verctors
|
// TODO More test vectors
|
||||||
let s = Secp256k1::new();
|
let s = Secp256k1::new();
|
||||||
let seed = "000102030405060708090a0b0c0d0e0f".from_hex().unwrap();
|
let seed = "000102030405060708090a0b0c0d0e0f".from_hex().unwrap();
|
||||||
let extk = ExtendedKey::from_seed(&s, &seed.as_slice()).unwrap();
|
let extk = ExtendedKey::from_seed(&s, &seed.as_slice()).unwrap();
|
||||||
|
|
|
@ -90,3 +90,43 @@ fn build_send_tx(config: &WalletConfig, ext_key: &ExtendedKey, amount: u64) -> R
|
||||||
build::transaction(parts).map_err(&From::from)
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue