Skip to content

Commit

Permalink
fix: set network according to pols
Browse files Browse the repository at this point in the history
Sets the network according to the principle of least surprise. i.e. if
TARI_NETWORK is set, try and make that the default network.
  • Loading branch information
CjS77 committed Feb 9, 2024
1 parent 2f67f31 commit b16b492
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ async fn sender_signature_verification() {

#[test]
fn kernel_hash() {
#[cfg(tari_target_network_mainnet)]
if let Network::MainNet = Network::get_current_or_default() {
eprintln!("This test is configured for stagenet only");
return;
}
let s = PrivateKey::from_hex("6c6eebc5a9c02e1f3c16a69ba4331f9f63d0718401dea10adc4f9d3b879a2c09").unwrap();
let r = PublicKey::from_hex("28e8efe4e5576aac931d358d0f6ace43c55fa9d4186d1d259d1436caa876d43b").unwrap();
let sig = Signature::new(r, s);
Expand Down Expand Up @@ -310,6 +315,8 @@ fn kernel_hash() {

#[test]
fn kernel_metadata() {
#[cfg(tari_target_network_mainnet)]
Network::set_current(Network::StageNet).unwrap();
let s = PrivateKey::from_hex("df9a004360b1cf6488d8ff7fb625bc5877f4b013f9b2b20d84932172e605b207").unwrap();
let r = PublicKey::from_hex("5c6bfaceaa1c83fa4482a816b5f82ca3975cb9b61b6e8be4ee8f01c5f1bee561").unwrap();
let sig = Signature::new(r, s);
Expand Down
6 changes: 5 additions & 1 deletion base_layer/tari_mining_helper_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ mod tests {
#[test]
fn detect_change_in_consensus_encoding() {
#[cfg(tari_target_network_mainnet)]
let (nonce, difficulty) = (5341281394393564685, Difficulty::from_u64(12916).unwrap());
let (nonce, difficulty) = match Network::get_current_or_default() {
Network::MainNet => (5341281394393564685, Difficulty::from_u64(12916).unwrap()),
Network::StageNet => (9657996013746357039, Difficulty::from_u64(3024).unwrap()),
_ => panic!("Invalid network for mainnet target"),
};
#[cfg(tari_target_network_nextnet)]
let (nonce, difficulty) = (3515524755266397098, Difficulty::from_u64(2607).unwrap());
#[cfg(not(any(tari_target_network_mainnet, tari_target_network_nextnet)))]
Expand Down
7 changes: 5 additions & 2 deletions common/src/configuration/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ impl Network {
impl Default for Network {
#[cfg(tari_target_network_mainnet)]
fn default() -> Self {
Network::MainNet
match std::env::var("TARI_NETWORK") {
Ok(network) => Network::from_str(network.as_str()).unwrap_or(Network::MainNet),
Err(_) => Network::MainNet,
}
}

#[cfg(tari_target_network_nextnet)]
Expand Down Expand Up @@ -192,7 +195,7 @@ mod test {
fn network_default() {
let network = Network::default();
#[cfg(tari_target_network_mainnet)]
assert_eq!(network, Network::MainNet);
assert!(matches!(network, Network::MainNet | Network::StageNet));
#[cfg(tari_target_network_nextnet)]
assert_eq!(network, Network::NextNet);
#[cfg(not(any(tari_target_network_mainnet, tari_target_network_nextnet)))]
Expand Down

0 comments on commit b16b492

Please sign in to comment.