use super::*;
impl<N: Network> Block<N> {
pub const NUM_GENESIS_TRANSACTIONS: usize = 4;
pub fn is_genesis(&self) -> Result<bool> {
if !self.header.is_genesis()? {
return Ok(false);
}
ensure!(self.previous_hash == N::BlockHash::default(), "Invalid previous hash");
ensure!(self.authority.is_beacon(), "Invalid block authority");
ensure!(self.solutions.is_empty(), "Invalid solutins");
ensure!(self.transactions.num_rejected() == 0, "Invalid number of rejected transactions");
ensure!(self.aborted_transaction_ids.is_empty(), "Genesis block must not contain aborted transactions");
#[cfg(not(any(test, feature = "test")))]
{
ensure!(self.ratifications.len() == 1, "Invalid number of ratifications");
ensure!(
self.transactions.num_accepted() == Self::NUM_GENESIS_TRANSACTIONS,
"Invalid number of accepted transactions"
);
ensure!(
self.transactions.num_finalize() == 2 * Self::NUM_GENESIS_TRANSACTIONS,
"Invalid number of finalized transactions"
);
}
Ok(true)
}
}
#[cfg(test)]
mod tests {
use super::*;
use console::network::MainnetV0;
type CurrentNetwork = MainnetV0;
#[test]
fn test_genesis() {
let genesis_block = Block::<CurrentNetwork>::read_le(CurrentNetwork::genesis_bytes()).unwrap();
assert!(genesis_block.is_genesis().unwrap());
}
}