Skip to content

Commit

Permalink
fix UniFFI bindgen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Feb 20, 2024
1 parent 4955e21 commit 4f4c140
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 55 deletions.
73 changes: 34 additions & 39 deletions src/profile/v100/address/accesscontroller_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,30 @@ impl HasPlaceholder for AccessControllerAddress {
}

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_mainnet_other() -> Self {
"accesscontroller_rdx1cv93xuha64eay8ctkx9km0el2jgkuh6gqlwec7tzecccyu0rj37xak".parse().expect("Placeholder")
}

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

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

#[cfg(test)]
mod tests {
use radix_engine_toolkit::models::canonical_address_types::CanonicalAccessControllerAddress;
use radix_engine_common::address::AddressBech32DecodeError;
use radix_engine_toolkit::models::canonical_address_types::{
CanonicalAccessControllerAddress, CanonicalAddress,
CanonicalAddressError,
};

use crate::prelude::*;

Expand All @@ -75,13 +60,29 @@ mod tests {

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

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

#[test]
Expand All @@ -105,14 +106,14 @@ mod tests {
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
json!("accesscontroller_rdx1cv93xuha64eay8ctkx9km0el2jgkuh6gqlwec7tzecccyu0rj37xak"),
);
}

#[test]
fn json_roundtrip_fails_for_invalid() {
assert_json_value_fails::<SUT>(
json!("accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2v3s")
json!("accesscontroller_rdx1c0llllllllllllllllllllllllllllllllllllllllllllllkl2vxx")
);
assert_json_value_fails::<SUT>(
json!("account_rdx1c0duj4lq0dc3cpl8qd420fpn5eckh8ljeysvjm894lyl5ja5yq6y5a")
Expand All @@ -137,12 +138,6 @@ mod tests {
.unwrap();
assert_eq!(a.network_id(), NetworkID::Mainnet);
}

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

#[cfg(test)]
Expand Down
7 changes: 3 additions & 4 deletions src/profile/v100/address/component_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mod tests {
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
json!("internal_component_rdx1lrhpef83s2c25zp9kzlk7qjak4en6llr7pw2zpuv5cswzufh9ff2ug"),
);
}

Expand Down Expand Up @@ -155,9 +155,8 @@ mod uniffi_tests {
type SUT = ComponentAddress;

#[test]
fn internal_component_rdx1lrhpef83s2c25zp9kzlk7qjak4en6llr7pw2zpuv5cswzufh9ff2ug(
) {
let b32 = "account_rdx16xlfcpp0vf7e3gqnswv8j9k58n6rjccu58vvspmdva22kf3aplease";
fn new_from_bech32_get_network_id_and_address() {
let b32 = "internal_component_rdx1lrhpef83s2c25zp9kzlk7qjak4en6llr7pw2zpuv5cswzufh9ff2ug";
let address = new_component_address(b32.to_owned()).unwrap();
assert_eq!(component_address_network_id(&address), NetworkID::Mainnet);
assert_eq!(component_address_bech32_address(&address), b32);
Expand Down
2 changes: 1 addition & 1 deletion src/profile/v100/address/package_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
json!("package_rdx1p589ehmmvqa2dnw0jaky3kesjdjvln94hzunsqse8k52083hfcjh63"),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/profile/v100/address/pool_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
json!("pool_rdx1c5dkfdtdqvczcwzdyvzeuhddyha768p2q28erden533fty8h68ay6m"),
);
}

Expand All @@ -119,7 +119,7 @@ mod tests {
#[test]
fn network_id_stokenet() {
let a: SUT =
"pool_rdx1c325zs6dz3un8ykkjavy9fkvvyzarkaehgsl408qup6f95aup3le3w"
"pool_tdx_2_1c3qzq55xdg6a66kn0qsdnw2zwvvxwljx5m3cp7xcdzeym3kpnzmpcp"
.parse()
.unwrap();
assert_eq!(a.network_id(), NetworkID::Stokenet);
Expand All @@ -128,7 +128,7 @@ mod tests {
#[test]
fn network_id_mainnet() {
let a: SUT =
"resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd"
"pool_rdx1c325zs6dz3un8ykkjavy9fkvvyzarkaehgsl408qup6f95aup3le3w"
.parse()
.unwrap();
assert_eq!(a.network_id(), NetworkID::Mainnet);
Expand Down
2 changes: 1 addition & 1 deletion src/profile/v100/address/resource_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
SUT::placeholder_stokenet_candy(),
])
.len(),
8
6
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/profile/v100/address/vault_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {
use crate::prelude::*;

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

#[test]
fn equality() {
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
assert_json_roundtrip(&a);
assert_json_value_ne_after_roundtrip(
&a,
json!("resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"),
json!("internal_vault_rdx1tz474x29nxxd4k2p2reete9xyz4apawv63dphxkr00qt23vyju49fq"),
);
}

Expand Down
14 changes: 11 additions & 3 deletions tests/uniffi/bindings/test_account_address.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import sargon.*

fun AccountAddress.networkId(): NetworkId {
return accountAddressNetworkId(address = this)
}

fun AccountAddress.address(): String {
return accountAddressBech32Address(address = this)
}

fun testAddress() {
val bech32 = "account_rdx129qdd2yp9vs8jkkn2uwn6sw0ejwmcwr3r4c3usr2hp0nau67m2kzdm"
val key = newEd25519PublicKeyFromHex(
Expand All @@ -10,12 +18,12 @@ fun testAddress() {
publicKey = PublicKey.Ed25519(value = key),
networkId = NetworkId.MAINNET
)
assert(address0.address == bech32)
assert(address0.address() == bech32)

val address1 = newAccountAddress(bech32 = bech32)
assert(address1.address == bech32)
assert(address1.address() == bech32)
assert(accountAddressToShort(address = address1) == "acco...m2kzdm")
assert(address1.networkId == NetworkId.MAINNET)
assert(address1.networkId() == NetworkId.MAINNET)
}

fun test() {
Expand Down
10 changes: 10 additions & 0 deletions tests/uniffi/bindings/test_account_address.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import Sargon

extension AccountAddress {
public var address: String {
accountAddressBech32Address(address: self)
}

public var networkId: NetworkId {
accountAddressNetworkId(address: self)
}
}

func testAddress() throws {
let bech32 = "account_rdx129qdd2yp9vs8jkkn2uwn6sw0ejwmcwr3r4c3usr2hp0nau67m2kzdm"
let key = try newEd25519PublicKeyFromHex(
Expand Down
12 changes: 10 additions & 2 deletions tests/uniffi/bindings/test_resource_address.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import sargon.*

fun ResourceAddress.networkId(): NetworkId {
return resourceAddressNetworkId(address = this)
}

fun ResourceAddress.address(): String {
return resourceAddressBech32Address(address = this)
}

fun test() {
val bech32 = "resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd"
val address = newResourceAddress(bech32 = bech32)
assert(address.address == bech32)
assert(address.networkId == NetworkId.MAINNET)
assert(address.address() == bech32)
assert(address.networkId() == NetworkId.MAINNET)
}

test()
10 changes: 10 additions & 0 deletions tests/uniffi/bindings/test_resource_address.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import Sargon

extension ResourceAddress {
public var address: String {
resourceAddressBech32Address(address: self)
}

public var networkId: NetworkId {
resourceAddressNetworkId(address: self)
}
}

func test() throws {
let bech32 =
"resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd"
Expand Down

0 comments on commit 4f4c140

Please sign in to comment.