Skip to content

Commit

Permalink
WIP: addressesm JSON roundtrop fails for addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Feb 20, 2024
1 parent 342b52a commit 4955e21
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 122 deletions.
99 changes: 0 additions & 99 deletions src/profile/v100/address/access_controller_address.rs

This file was deleted.

176 changes: 176 additions & 0 deletions src/profile/v100/address/accesscontroller_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
use crate::prelude::*;

#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
derive_more::FromStr,
derive_more::Display,
SerializeDisplay,
DeserializeFromStr,
uniffi::Record,
)]
#[display("{__inner}")]
pub struct AccessControllerAddress {
pub(crate) __inner: InnerAccessControllerAddress,
}

impl HasPlaceholder for AccessControllerAddress {
fn placeholder() -> Self {
Self::placeholder_mainnet()
}

fn placeholder_other() -> Self {
Self::placeholder_stokenet()
}
}

impl AccessControllerAddress {
/*
these should all be valid
[
"accesscontroller_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a",
"accesscontroller_rdx1cv93xuha64eay8ctkx9km0el2jgkuh6gqlwec7tzecccyu0rj37xak",
"accesscontroller_rdx1cva6mtja4crwxxhmd63q2xlhew7fh0af67zw3snhzj8cm7xq2cm06g",
"accesscontroller_rdx1cvlu8kvmqu56arywyzkkewyuv7mdg448d69k083dpq0nvrd44me6qd",
"accesscontroller_rdx1cw9383xuqx6cme0knucw5aggknvrqmc8lzu7jcn3kwherk8x55zmtt",
"accesscontroller_rdx1cwggxzkqxwg9zjhv3jvyvkcn2hl7gxgwgjeqxl2d7xyuyx3tklg77y",
"accesscontroller_rdx1cwtvlhhg0pwyrlcujv9gv2adastmcc03ewg9vww8ke3s5t9gjf7jmp",
"accesscontroller_rdx1cwufa4a2j7klu5hh72uwxvd9gyevxfuxspxynne7fqnnzzr7nh4uya"
]
and these:
accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s
accesscontroller_rdx1cvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq09959m
from GW:
accesscontroller_rdx1cw9383xuqx6cme0knucw5aggknvrqmc8lzu7jcn3kwherk8x55zmtt
accesscontroller_tdx_2_1cw68j9ca4fye09mz3hshp4qydjnxhsahm68hvmz9cjhftcz9f53juq
Working roundtrip test from OA:
#[test]
fn access_controller() {
let address = CanonicalAccessControllerAddress::from_str("accesscontroller_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a").unwrap();
assert_eq!(CanonicalAccessControllerAddress::from_str(&address.to_string()).unwrap().to_string(), "accesscontroller_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a");
}
*/
pub fn placeholder_mainnet() -> Self {
"accesscontroller_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a".parse().expect("Placeholder")
}

pub fn placeholder_stokenet() -> Self {
"accesscontroller_tdx_2_1c0llllllllllllllllllllllllllllllllllllllllllllllhcg0ny".parse().expect("Placeholder")
}
}

#[cfg(test)]
mod tests {
use radix_engine_toolkit::models::canonical_address_types::CanonicalAccessControllerAddress;

use crate::prelude::*;

#[allow(clippy::upper_case_acronyms)]
type SUT = AccessControllerAddress;

#[test]
fn equality() {
assert_eq!(SUT::placeholder(), SUT::placeholder());
assert_eq!(SUT::placeholder_other(), SUT::placeholder_other());
}

#[test]
fn inequality() {
assert_ne!(SUT::placeholder(), SUT::placeholder_other());
}

#[test]
fn display() {
let s = "accesscontroller_rdx1cw9383xuqx6cme0knucw5aggknvrqmc8lzu7jcn3kwherk8x55zmtt";
let a = SUT::try_from_bech32(s).unwrap();
assert_eq!(format!("{a}"), s);
}

#[test]
fn json_roundtrip() {
let a: SUT =
"accesscontroller_rdx1cw9383xuqx6cme0knucw5aggknvrqmc8lzu7jcn3kwherk8x55zmtt"
.parse()
.unwrap();

assert_json_value_eq_after_roundtrip(
&a,
json!("accesscontroller_rdx1cw9383xuqx6cme0knucw5aggknvrqmc8lzu7jcn3kwherk8x55zmtt"),
);
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
);
}

#[test]
fn json_roundtrip_fails_for_invalid() {
assert_json_value_fails::<SUT>(
json!("accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s")
);
assert_json_value_fails::<SUT>(
json!("account_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a")
);
assert_json_value_fails::<SUT>(json!("super invalid"));
}

#[test]
fn network_id_stokenet() {
let a: SUT =
"accesscontroller_tdx_2_1c0llllllllllllllllllllllllllllllllllllllllllllllhcg0ny"
.parse()
.unwrap();
assert_eq!(a.network_id(), NetworkID::Stokenet);
}

#[test]
fn network_id_mainnet() {
let a: SUT =
"accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s"
.parse()
.unwrap();
assert_eq!(a.network_id(), NetworkID::Mainnet);
}

#[test]
fn access_controller() {
let address = CanonicalAccessControllerAddress::from_str("accesscontroller_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a").unwrap();
println!("{address}");
}
}

#[cfg(test)]
mod uniffi_tests {
use crate::prelude::*;

use super::*;

#[allow(clippy::upper_case_acronyms)]
type SUT = AccessControllerAddress;

#[test]
fn new_from_bech32_get_network_id_and_address() {
let b32 = "accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s";
let address = new_accesscontroller_address(b32.to_owned()).unwrap();
assert_eq!(
accesscontroller_address_network_id(&address),
NetworkID::Mainnet
);
assert_eq!(accesscontroller_address_bech32_address(&address), b32);
}

#[test]
fn new() {
let s = "accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s";
let a = SUT::try_from_bech32(s).unwrap();
let b = new_accesscontroller_address(s.to_string()).unwrap();
assert_eq!(b.address(), s);
assert_eq!(a, b);
}
}
2 changes: 1 addition & 1 deletion src/profile/v100/address/account_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl AccountAddress {
/// `account_rdx16xlfcpp0vf7e3gqnswv8j9k58n6rjccu58vvspmdva22kf3aplease`
///
pub fn short(&self) -> String {
let suffix = suffix_str(6, &self.address());
let suffix = suffix_str(6, self.address());
format!("{}...{}", &self.address()[0..4], suffix)
}
}
Expand Down
31 changes: 28 additions & 3 deletions src/profile/v100/address/component_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,38 @@ mod tests {

#[test]
fn equality() {
assert_eq!(SUT::placeholder(), SUT::placeholder());
assert_eq!(SUT::placeholder_other(), SUT::placeholder_other());
assert_eq!(
SUT::placeholder_mainnet_internal(),
SUT::placeholder_mainnet_internal()
);
assert_eq!(
SUT::placeholder_mainnet_global(),
SUT::placeholder_mainnet_global()
);
assert_eq!(
SUT::placeholder_stokenet_internal(),
SUT::placeholder_stokenet_internal()
);
assert_eq!(
SUT::placeholder_stokenet_global(),
SUT::placeholder_stokenet_global()
);
}

#[test]
fn inequality() {
assert_ne!(SUT::placeholder(), SUT::placeholder_other());
assert_ne!(
SUT::placeholder_mainnet_internal(),
SUT::placeholder_mainnet_global()
);
assert_ne!(
SUT::placeholder_stokenet_internal(),
SUT::placeholder_mainnet_internal()
);
assert_ne!(
SUT::placeholder_stokenet_global(),
SUT::placeholder_mainnet_global()
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/profile/v100/address/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod access_controller_address;
mod accesscontroller_address;
mod account_address;
mod component_address;
mod entity_address;
Expand All @@ -12,7 +12,7 @@ mod validator_address;
mod vault_address;
mod wrap_ret_address;

pub use access_controller_address::*;
pub use accesscontroller_address::*;
pub use account_address::*;
pub use component_address::*;

Expand Down
Loading

0 comments on commit 4955e21

Please sign in to comment.