segwit: basic serialization tests
This commit is contained in:
parent
db46633ef8
commit
5fb35020f6
|
@ -84,3 +84,18 @@ impl From<&'static str> for IndexedBlock {
|
||||||
deserialize(&s.from_hex().unwrap() as &[u8]).unwrap()
|
deserialize(&s.from_hex().unwrap() as &[u8]).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::IndexedBlock;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn size_with_witness_not_equal_to_size() {
|
||||||
|
let block_without_witness: IndexedBlock = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
|
||||||
|
assert_eq!(block_without_witness.size(), block_without_witness.size_with_witness());
|
||||||
|
|
||||||
|
// bip143 block
|
||||||
|
let block_with_witness: IndexedBlock = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000001010000000000".into();
|
||||||
|
assert!(block_with_witness.size() != block_with_witness.size_with_witness());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ impl Deserializable for Transaction {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use hash::H256;
|
use hash::H256;
|
||||||
use ser::Serializable;
|
use ser::{Serializable, serialize_with_flags, SERIALIZE_TRANSACTION_WITNESS};
|
||||||
use super::{Transaction, TransactionInput, OutPoint, TransactionOutput};
|
use super::{Transaction, TransactionInput, OutPoint, TransactionOutput};
|
||||||
|
|
||||||
// real transaction from block 80000
|
// real transaction from block 80000
|
||||||
|
@ -335,4 +335,13 @@ mod tests {
|
||||||
};
|
};
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serialization_with_flags() {
|
||||||
|
let transaction_without_witness: Transaction = "000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into();
|
||||||
|
assert_eq!(serialize_with_flags(&transaction_without_witness, 0), serialize_with_flags(&transaction_without_witness, SERIALIZE_TRANSACTION_WITNESS));
|
||||||
|
|
||||||
|
let transaction_with_witness: Transaction = "0000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000001010000000000".into();
|
||||||
|
assert!(serialize_with_flags(&transaction_with_witness, 0) != serialize_with_flags(&transaction_with_witness, SERIALIZE_TRANSACTION_WITNESS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue