mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Reintroduce block tests with new tx building
The build module introduced some facilities to build transactions that can now be leveraged when building blocks and in related tests.
This commit is contained in:
parent
6bd3fc0d48
commit
b6b815f6c1
1 changed files with 77 additions and 98 deletions
|
@ -402,101 +402,80 @@ impl Block {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
#[cfg(test)]
|
||||||
// mod test {
|
mod test {
|
||||||
// use super::*;
|
use super::*;
|
||||||
// use core::{Input, Output, Transaction};
|
use core::{Input, Output, Transaction};
|
||||||
// use core::hash::{Hash, Hashed};
|
use core::build::{self, input, output, input_rand, output_rand, with_fee};
|
||||||
// use core::test::{tx1i1o, tx2i1o};
|
use core::hash::{Hash, Hashed};
|
||||||
//
|
use core::test::{tx1i1o, tx2i1o};
|
||||||
// use secp::{self, Secp256k1};
|
|
||||||
// use secp::key::SecretKey;
|
use secp::{self, Secp256k1};
|
||||||
// use rand::Rng;
|
use secp::key::SecretKey;
|
||||||
// use rand::os::OsRng;
|
use rand::Rng;
|
||||||
//
|
use rand::os::OsRng;
|
||||||
// fn new_secp() -> Secp256k1 {
|
|
||||||
// secp::Secp256k1::with_caps(secp::ContextFlag::Commit)
|
fn new_secp() -> Secp256k1 {
|
||||||
// }
|
secp::Secp256k1::with_caps(secp::ContextFlag::Commit)
|
||||||
//
|
}
|
||||||
// // utility to create a block without worrying about the key or previous
|
|
||||||
// header
|
// utility to create a block without worrying about the key or previous
|
||||||
// fn new_block(txs: Vec<&mut Transaction>, secp: &Secp256k1) -> Block {
|
//header
|
||||||
// let mut rng = OsRng::new().unwrap();
|
fn new_block(txs: Vec<&mut Transaction>, secp: &Secp256k1) -> Block {
|
||||||
// let skey = SecretKey::new(secp, &mut rng);
|
let mut rng = OsRng::new().unwrap();
|
||||||
// Block::new(&BlockHeader::default(), txs, skey).unwrap()
|
let skey = SecretKey::new(secp, &mut rng);
|
||||||
// }
|
Block::new(&BlockHeader::default(), txs, skey).unwrap()
|
||||||
//
|
}
|
||||||
// // utility producing a transaction that spends the above
|
|
||||||
// fn txspend1i1o<R: Rng>(secp: &Secp256k1, rng: &mut R, oout: Output, outh:
|
// utility producing a transaction that spends an output with the provided
|
||||||
// Hash) -> Transaction {
|
// value and blinding key
|
||||||
// if let Output::OvertOutput { blindkey, value } = oout {
|
fn txspend1i1o(v: u64, b: SecretKey) -> Transaction {
|
||||||
// Transaction::new(vec![Input::OvertInput {
|
build::transaction(vec![input(v, b), output_rand(3), with_fee(1)]).map(|(tx, _)| tx).unwrap()
|
||||||
// output: outh,
|
}
|
||||||
// value: value,
|
|
||||||
// blindkey: blindkey,
|
#[test]
|
||||||
// }],
|
// builds a block with a tx spending another and check if merging occurred
|
||||||
// vec![Output::OvertOutput {
|
fn compactable_block() {
|
||||||
// value: 3,
|
let mut rng = OsRng::new().unwrap();
|
||||||
// blindkey: SecretKey::new(secp, rng),
|
let ref secp = new_secp();
|
||||||
// }],
|
|
||||||
// 1)
|
let mut btx1 = tx2i1o();
|
||||||
// } else {
|
let skey = SecretKey::new(secp, &mut rng);
|
||||||
// panic!();
|
let (mut btx2, _) = build::transaction(vec![input_rand(5), output(4, skey), with_fee(1)]).unwrap();
|
||||||
// }
|
|
||||||
// }
|
// spending tx2
|
||||||
//
|
let mut btx3 = txspend1i1o(4, skey);
|
||||||
// #[test]
|
let b = new_block(vec![&mut btx1, &mut btx2, &mut btx3], secp);
|
||||||
// // builds a block with a tx spending another and check if merging occurred
|
|
||||||
// fn compactable_block() {
|
// block should have been automatically compacted (including reward
|
||||||
// let mut rng = OsRng::new().unwrap();
|
// output) and should still be valid
|
||||||
// let ref secp = new_secp();
|
b.verify(&secp).unwrap();
|
||||||
//
|
assert_eq!(b.inputs.len(), 3);
|
||||||
// let tx1 = tx2i1o(secp, &mut rng);
|
assert_eq!(b.outputs.len(), 3);
|
||||||
// let mut btx1 = tx1.blind(&secp, None).unwrap();
|
}
|
||||||
//
|
|
||||||
// let tx2 = tx1i1o(secp, &mut rng);
|
#[test]
|
||||||
// let mut btx2 = tx2.blind(&secp, None).unwrap();
|
// builds 2 different blocks with a tx spending another and check if merging
|
||||||
//
|
// occurs
|
||||||
// // spending tx2
|
fn mergeable_blocks() {
|
||||||
// let spending = txspend1i1o(secp, &mut rng, tx2.outputs[0],
|
let mut rng = OsRng::new().unwrap();
|
||||||
// btx2.outputs[0].hash());
|
let ref secp = new_secp();
|
||||||
// let mut btx3 = spending.blind(&secp, None).unwrap();
|
|
||||||
// let b = new_block(vec![&mut btx1, &mut btx2, &mut btx3], secp);
|
let mut btx1 = tx2i1o();
|
||||||
//
|
let skey = SecretKey::new(secp, &mut rng);
|
||||||
// // block should have been automatically compacted (including reward
|
let (mut btx2, _) = build::transaction(vec![input_rand(5), output(4, skey), with_fee(1)]).unwrap();
|
||||||
// output) and
|
|
||||||
// // should still be valid
|
// spending tx2
|
||||||
// b.verify(&secp).unwrap();
|
let mut btx3 = txspend1i1o(4, skey);
|
||||||
// assert_eq!(b.inputs.len(), 3);
|
|
||||||
// assert_eq!(b.outputs.len(), 3);
|
let b1 = new_block(vec![&mut btx1, &mut btx2], secp);
|
||||||
// }
|
b1.verify(&secp).unwrap();
|
||||||
//
|
let b2 = new_block(vec![&mut btx3], secp);
|
||||||
// #[test]
|
b2.verify(&secp).unwrap();
|
||||||
// // builds 2 different blocks with a tx spending another and check if merging
|
|
||||||
// // occurs
|
// block should have been automatically compacted and should still be valid
|
||||||
// fn mergeable_blocks() {
|
let b3 = b1.merge(b2);
|
||||||
// let mut rng = OsRng::new().unwrap();
|
assert_eq!(b3.inputs.len(), 3);
|
||||||
// let ref secp = new_secp();
|
assert_eq!(b3.outputs.len(), 4);
|
||||||
//
|
}
|
||||||
// let tx1 = tx2i1o(secp, &mut rng);
|
}
|
||||||
// let mut btx1 = tx1.blind(&secp, None).unwrap();
|
|
||||||
//
|
|
||||||
// let tx2 = tx1i1o(secp, &mut rng);
|
|
||||||
// let mut btx2 = tx2.blind(&secp, None).unwrap();
|
|
||||||
//
|
|
||||||
// // spending tx2
|
|
||||||
// let spending = txspend1i1o(secp, &mut rng, tx2.outputs[0],
|
|
||||||
// btx2.outputs[0].hash());
|
|
||||||
// let mut btx3 = spending.blind(&secp, None).unwrap();
|
|
||||||
//
|
|
||||||
// let b1 = new_block(vec![&mut btx1, &mut btx2], secp);
|
|
||||||
// b1.verify(&secp).unwrap();
|
|
||||||
// let b2 = new_block(vec![&mut btx3], secp);
|
|
||||||
// b2.verify(&secp).unwrap();
|
|
||||||
//
|
|
||||||
// // block should have been automatically compacted and should still be valid
|
|
||||||
// let b3 = b1.merge(b2);
|
|
||||||
// assert_eq!(b3.inputs.len(), 3);
|
|
||||||
// assert_eq!(b3.outputs.len(), 4);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in a new issue