Add proptest for work roundtrip
This commit is contained in:
parent
a798074088
commit
b287ea58c2
|
|
@ -123,6 +123,12 @@ impl fmt::Debug for ExpandedDifficulty {
|
||||||
#[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub struct Work(u128);
|
pub struct Work(u128);
|
||||||
|
|
||||||
|
impl From<Work> for u128 {
|
||||||
|
fn from(work: Work) -> Self {
|
||||||
|
work.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Work {
|
impl fmt::Debug for Work {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// There isn't a standard way to represent alternate formats for the
|
// There isn't a standard way to represent alternate formats for the
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{mem, sync::Arc};
|
use std::{convert::TryFrom, mem, sync::Arc};
|
||||||
|
|
||||||
use primitive_types::U256;
|
use primitive_types::U256;
|
||||||
use zebra_chain::{
|
use zebra_chain::{
|
||||||
|
|
@ -6,6 +6,7 @@ use zebra_chain::{
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
transparent,
|
transparent,
|
||||||
work::difficulty::ExpandedDifficulty,
|
work::difficulty::ExpandedDifficulty,
|
||||||
|
work::difficulty::Work,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -77,6 +78,22 @@ static BLOCK_LOCATOR_CASES: &[(u32, u32)] = &[
|
||||||
(10000, 9901),
|
(10000, 9901),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn round_trip_work_expanded() {
|
||||||
|
zebra_test::init();
|
||||||
|
|
||||||
|
proptest!(|(work in 1..std::u128::MAX)| {
|
||||||
|
let work: U256 = work.into();
|
||||||
|
let expanded = work_to_expanded(work);
|
||||||
|
let work_after = Work::try_from(expanded).unwrap();
|
||||||
|
let work_after = u128::from(work_after);
|
||||||
|
let work_after = U256::from(work_after);
|
||||||
|
prop_assert_eq!(work, work_after);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Check that the block locator heights are sensible.
|
/// Check that the block locator heights are sensible.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_block_locator_heights() {
|
fn test_block_locator_heights() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue