Skip to content

Commit

Permalink
Merge pull request #584 from Emurgo/evgenii/network_id_fix
Browse files Browse the repository at this point in the history
Address fix for new test networks
  • Loading branch information
lisicky authored Mar 9, 2023
2 parents d15e624 + 86ecf4c commit d478315
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rust/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ impl ByronAddress {
magic if magic == NetworkInfo::testnet().protocol_magic() => {
Ok(NetworkInfo::testnet().network_id())
}
magic if magic == NetworkInfo::testnet_preprod().protocol_magic() => {
Ok(NetworkInfo::testnet_preprod().network_id())
}
magic if magic == NetworkInfo::testnet_preview().protocol_magic() => {
Ok(NetworkInfo::testnet_preview().network_id())
}
_ => Err(JsError::from_str(
&format! {"Unknown network {}", protocol_magic},
)),
Expand Down Expand Up @@ -582,6 +588,8 @@ impl Address {
};
let prefix_tail = match self.network_id()? {
id if id == NetworkInfo::testnet().network_id() => "_test",
id if id == NetworkInfo::testnet_preprod().network_id() => "_test",
id if id == NetworkInfo::testnet_preview().network_id() => "_test",
_ => "",
};
format!("{}{}", prefix_header, prefix_tail)
Expand Down Expand Up @@ -1457,4 +1465,11 @@ mod tests {
let p2 = Pointer::new_pointer(&to_bignum(10), &to_bignum(20), &to_bignum(30));
assert_eq!(p1, p2);
}

#[test]
fn prepod_network_id_test() {
let address = "KjgoiXJS2coTnqpCLHXFtd89Hv9ttjsE6yW4msyLXFNkykUpTsyBs85r2rDDia2uKrhdpGKCJnmFXwvPSWLe75564ixZWdTxRh7TnuaDLnHx";
let network_id = ByronAddress::from_base58(address).unwrap().to_address().network_id().unwrap();
assert_eq!(network_id, NetworkInfo::testnet_preprod().network_id());
}
}

0 comments on commit d478315

Please sign in to comment.