feature: Expect the hard-coded checkpoint lists to parse

This commit is contained in:
teor 2020-07-21 11:33:22 +10:00
parent 53606dfae8
commit f1a0036824
3 changed files with 14 additions and 9 deletions

View File

@ -122,8 +122,8 @@ impl CheckpointVerifier {
// Until we implement the overall verifier in #516, this function, and some of the
// functions and enum variants it uses, are only used in the tests.
#[allow(dead_code)]
pub fn new(network: Network) -> Result<Self, Error> {
Ok(Self::from_checkpoint_list(CheckpointList::new(network)?))
pub fn new(network: Network) -> Self {
Self::from_checkpoint_list(CheckpointList::new(network))
}
/// Return a checkpoint verification service using `list`.

View File

@ -61,16 +61,22 @@ impl FromStr for CheckpointList {
impl CheckpointList {
/// Returns the hard-coded checkpoint list for `network`.
pub fn new(network: Network) -> Result<Self, Error> {
pub fn new(network: Network) -> Self {
// parse calls CheckpointList::from_list
let checkpoint_list: CheckpointList = match network {
Mainnet => MAINNET_CHECKPOINTS.parse()?,
Testnet => TESTNET_CHECKPOINTS.parse()?,
Mainnet => MAINNET_CHECKPOINTS
.parse()
.expect("Hard-coded Mainnet checkpoint list parses and validates"),
Testnet => TESTNET_CHECKPOINTS
.parse()
.expect("Hard-coded Testnet checkpoint list parses and validates"),
};
match checkpoint_list.hash(BlockHeight(0)) {
Some(hash) if hash == parameters::genesis_hash(network) => Ok(checkpoint_list),
Some(_) => Err("the genesis checkpoint does not match the network genesis hash")?,
Some(hash) if hash == parameters::genesis_hash(network) => checkpoint_list,
Some(_) => {
panic!("The hard-coded genesis checkpoint does not match the network genesis hash")
}
None => unreachable!("Parser should have checked for a missing genesis checkpoint"),
}
}

View File

@ -688,8 +688,7 @@ async fn hard_coded_mainnet() -> Result<(), Report> {
let hash0: BlockHeaderHash = block0.as_ref().into();
// Use the hard-coded checkpoint list
let mut checkpoint_verifier =
CheckpointVerifier::new(Network::Mainnet).map_err(|e| eyre!(e))?;
let mut checkpoint_verifier = CheckpointVerifier::new(Network::Mainnet);
assert_eq!(
checkpoint_verifier.previous_checkpoint_height(),