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 // 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. // functions and enum variants it uses, are only used in the tests.
#[allow(dead_code)] #[allow(dead_code)]
pub fn new(network: Network) -> Result<Self, Error> { pub fn new(network: Network) -> Self {
Ok(Self::from_checkpoint_list(CheckpointList::new(network)?)) Self::from_checkpoint_list(CheckpointList::new(network))
} }
/// Return a checkpoint verification service using `list`. /// Return a checkpoint verification service using `list`.

View File

@ -61,16 +61,22 @@ impl FromStr for CheckpointList {
impl CheckpointList { impl CheckpointList {
/// Returns the hard-coded checkpoint list for `network`. /// 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 // parse calls CheckpointList::from_list
let checkpoint_list: CheckpointList = match network { let checkpoint_list: CheckpointList = match network {
Mainnet => MAINNET_CHECKPOINTS.parse()?, Mainnet => MAINNET_CHECKPOINTS
Testnet => TESTNET_CHECKPOINTS.parse()?, .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)) { match checkpoint_list.hash(BlockHeight(0)) {
Some(hash) if hash == parameters::genesis_hash(network) => Ok(checkpoint_list), Some(hash) if hash == parameters::genesis_hash(network) => checkpoint_list,
Some(_) => Err("the genesis checkpoint does not match the network genesis hash")?, 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"), 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(); let hash0: BlockHeaderHash = block0.as_ref().into();
// Use the hard-coded checkpoint list // Use the hard-coded checkpoint list
let mut checkpoint_verifier = let mut checkpoint_verifier = CheckpointVerifier::new(Network::Mainnet);
CheckpointVerifier::new(Network::Mainnet).map_err(|e| eyre!(e))?;
assert_eq!( assert_eq!(
checkpoint_verifier.previous_checkpoint_height(), checkpoint_verifier.previous_checkpoint_height(),