-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(network): Adds a network magic field to
testnet::Parameters
and…
… the config (#8524) * Adds a `target_difficulty_limit` field on `testnet::Parameters` * updates test to increment block nonce until finding a block that's below the difficulty threshold * increment the nonce while the difficulty is invalid instead of while the difficulty threshold is invalid * Adds comments * moves network Magic type from zebra-network to zebra-chain * Adds `network_magic` field to `testnet::Parameters` and uses the regtest network magic from zcashd * Add a network magic config field for custom testnets * Adds/updates tests * Update zebra-chain/src/parameters/network/testnet.rs * Adds a link to the Regtest network magic in zcashd --------- Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
- Loading branch information
1 parent
e0da45b
commit 5ca40aa
Showing
12 changed files
with
240 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! Network `Magic` type and implementation. | ||
|
||
use std::fmt; | ||
|
||
use crate::parameters::{constants::magics, Network}; | ||
|
||
#[cfg(any(test, feature = "proptest-impl"))] | ||
use proptest_derive::Arbitrary; | ||
|
||
/// A magic number identifying the network. | ||
#[derive(Copy, Clone, Eq, PartialEq)] | ||
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))] | ||
pub struct Magic(pub [u8; 4]); | ||
|
||
impl fmt::Debug for Magic { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("Magic").field(&hex::encode(self.0)).finish() | ||
} | ||
} | ||
|
||
impl Network { | ||
/// Get the magic value associated to this `Network`. | ||
pub fn magic(&self) -> Magic { | ||
match self { | ||
Network::Mainnet => magics::MAINNET, | ||
Network::Testnet(params) => params.network_magic(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod proptest { | ||
|
||
use proptest::prelude::*; | ||
|
||
use super::{magics, Magic}; | ||
|
||
#[test] | ||
fn magic_debug() { | ||
let _init_guard = zebra_test::init(); | ||
|
||
assert_eq!(format!("{:?}", magics::MAINNET), "Magic(\"24e92764\")"); | ||
assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")"); | ||
assert_eq!(format!("{:?}", magics::REGTEST), "Magic(\"aae83f5f\")"); | ||
} | ||
|
||
proptest! { | ||
|
||
#[test] | ||
fn proptest_magic_from_array(data in any::<[u8; 4]>()) { | ||
let _init_guard = zebra_test::init(); | ||
|
||
assert_eq!(format!("{:?}", Magic(data)), format!("Magic({:x?})", hex::encode(data))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.