Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from micbakos-rdx/kotlin-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon authored Feb 7, 2024
2 parents 905e854 + 621a6b3 commit 3f59042
Show file tree
Hide file tree
Showing 25 changed files with 535 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/Cargo.lock
tarpaulin-report.html
.vscode
.idea
build_rs_cov.profraw
cobertura.xml
cobertura.xml
jna-*.jar
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ repos:
name: uniffi bindgen tests
language: system
types: [file, rust]
entry: cargo test --package profile --test uniffi
entry: bash -c 'exec env CLASSPATH="$PWD/jna-5.13.0.jar"' && bash -c 'exec env JAVA_OPTS="-Xmx8g"' && cargo test --package profile --test uniffi
pass_filenames: false
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,13 @@ cargo install cargo-nextest
```sh
cargo nextest run --package profile --test uniffi && cargo nextest run
```

> [!IMPORTANT]
> To run tests in Kotlin you need to download [JNA](https://mvnrepository.com/artifact/net.java.dev.jna/jna) (currently tested under version `5.13.0`)
> ``` sh
> wget https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar
> ```
> Then include the jar into the classpath and also increase the heap size like so
> ```sh
> JAVA_OPTS="-Xmx8g" CLASSPATH="path-to-jna/jna-5.13.0.jar" cargo nextest run --package profile --test uniffi && cargo nextest run
> ```
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub enum CAP26Path {
#[display("{value}")]
GetID { value: GetIDPath },
#[display("{value}")]
AccountPath { value: AccountPath },
Account { value: AccountPath },
#[display("{value}")]
IdentityPath { value: IdentityPath },
Identity { value: IdentityPath },
}

impl TryFrom<&HDPath> for CAP26Path {
Expand All @@ -50,8 +50,8 @@ impl FromStr for CAP26Path {
impl Derivation for CAP26Path {
fn hd_path(&self) -> &HDPath {
match self {
CAP26Path::AccountPath { value } => value.hd_path(),
CAP26Path::IdentityPath { value } => value.hd_path(),
CAP26Path::Account { value } => value.hd_path(),
CAP26Path::Identity { value } => value.hd_path(),
CAP26Path::GetID { value } => value.hd_path(),
}
}
Expand All @@ -64,22 +64,22 @@ impl Derivation for CAP26Path {

fn scheme(&self) -> DerivationPathScheme {
match self {
CAP26Path::AccountPath { value } => value.scheme(),
CAP26Path::IdentityPath { value } => value.scheme(),
CAP26Path::Account { value } => value.scheme(),
CAP26Path::Identity { value } => value.scheme(),
CAP26Path::GetID { value } => value.scheme(),
}
}
}

impl From<AccountPath> for CAP26Path {
fn from(value: AccountPath) -> Self {
Self::AccountPath { value }
Self::Account { value }
}
}

impl From<IdentityPath> for CAP26Path {
fn from(value: IdentityPath) -> Self {
Self::IdentityPath { value }
Self::Identity { value }
}
}

Expand All @@ -101,13 +101,13 @@ impl HasPlaceholder for CAP26Path {

impl CAP26Path {
pub fn placeholder_account() -> Self {
Self::AccountPath {
Self::Account {
value: AccountPath::placeholder(),
}
}

pub fn placeholder_identity() -> Self {
Self::IdentityPath {
Self::Identity {
value: IdentityPath::placeholder(),
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ mod tests {
#[test]
fn into_from_account_path() {
assert_eq!(
CAP26Path::AccountPath {
CAP26Path::Account {
value: AccountPath::placeholder()
},
AccountPath::placeholder().into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl TryFrom<CAP26Path> for AccountPath {

fn try_from(value: CAP26Path) -> Result<Self, Self::Error> {
value
.as_account_path()
.as_account()
.ok_or(CommonError::ExpectedAccountPathButGotSomethingElse)
.cloned()
}
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Derivation for AccountPath {
}
fn derivation_path(&self) -> DerivationPath {
DerivationPath::CAP26 {
value: CAP26Path::AccountPath {
value: CAP26Path::Account {
value: self.clone(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl TryFrom<CAP26Path> for IdentityPath {

fn try_from(value: CAP26Path) -> Result<Self, Self::Error> {
value
.as_identity_path()
.as_identity()
.ok_or(CommonError::ExpectedIdentityPathButGotSomethingElse)
.cloned()
}
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Derivation for IdentityPath {

fn derivation_path(&self) -> DerivationPath {
DerivationPath::CAP26 {
value: CAP26Path::IdentityPath {
value: CAP26Path::Identity {
value: self.clone(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ mod tests {

#[test]
fn from_cap26() {
let derivation_path: DerivationPath = CAP26Path::AccountPath {
let derivation_path: DerivationPath = CAP26Path::Account {
value: AccountPath::placeholder(),
}
.into();
Expand All @@ -304,7 +304,7 @@ mod tests {
let path: DerivationPath = AccountPath::placeholder().into();
assert_eq!(
path.as_cap26().unwrap(),
&CAP26Path::AccountPath {
&CAP26Path::Account {
value: AccountPath::placeholder()
}
);
Expand Down
2 changes: 1 addition & 1 deletion profile/src/v100/entity/account/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ mod tests {
let new_third_party_dep = ThirdPartyDeposits::with_rule_and_lists(
DepositRule::DenyAll,
[excp1, excp2],
[DepositorAddress::ResourceAddress {
[DepositorAddress::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {
DepositRule::DenyAll,
Vec::from_iter([excp1, excp2]),
Vec::from_iter(
[DepositorAddress::ResourceAddress {
[DepositorAddress::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ use crate::prelude::*;
Ord,
uniffi::Enum,
)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "discriminator")]
pub enum DepositorAddress {
ResourceAddress { value: ResourceAddress },
NonFungibleGlobalID { value: NonFungibleGlobalId },
#[serde(rename = "resourceAddress")]
Resource { value: ResourceAddress },
#[serde(rename = "nonFungibleGlobalID")]
NFGlobalID { value: NonFungibleGlobalId },
}

#[cfg(test)]
Expand All @@ -26,7 +27,7 @@ mod tests {
#[test]
fn json_decode_deny_all_with_exceptions() {
let model =
DepositorAddress::ResourceAddress {
DepositorAddress::Resource {
value: "resource_rdx1tkk83magp3gjyxrpskfsqwkg4g949rmcjee4tu2xmw93ltw2cz94sq"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod tests {
DepositRule::AcceptKnown,
BTreeSet::from_iter([excp1, excp2]),
BTreeSet::from_iter(
[DepositorAddress::NonFungibleGlobalID { value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>".parse().unwrap()}],
[DepositorAddress::NFGlobalID { value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>".parse().unwrap()}],
),
);

Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
)
.unwrap();

let depositor = DepositorAddress::NonFungibleGlobalID {
let depositor = DepositorAddress::NFGlobalID {
value: "resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha:<foobar>"
.parse()
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl HierarchicalDeterministicFactorInstance {
match &self.derivation_path() {
DerivationPath::CAP26 { value } => match value {
CAP26Path::GetID { value: _ } => None,
CAP26Path::IdentityPath { value } => Some(value.key_kind()),
CAP26Path::AccountPath { value } => Some(value.key_kind()),
CAP26Path::Identity { value } => Some(value.key_kind()),
CAP26Path::Account { value } => Some(value.key_kind()),
},
DerivationPath::BIP44Like { value: _ } => None,
}
Expand Down
25 changes: 25 additions & 0 deletions profile/tests/uniffi/bindings/test_account_address.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import radix.wallet.kit.*

fun testAddress() {
val bech32 = "account_rdx129qdd2yp9vs8jkkn2uwn6sw0ejwmcwr3r4c3usr2hp0nau67m2kzdm"
val key = newEd25519PublicKeyFromHex(
hex = "3e9b96a2a863f1be4658ea66aa0584d2a8847d4c0f658b20e62e3594d994d73d"
)

val address0 = newAccountAddressFrom(
publicKey = PublicKey.Ed25519(value = key),
networkId = NetworkId.MAINNET
)
assert(address0.address == bech32)

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

fun test() {
testAddress()
}

test()
32 changes: 32 additions & 0 deletions profile/tests/uniffi/bindings/test_app_preferences.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import radix.wallet.kit.*

val AppPreferences.Companion.placeholder
get() = newAppPreferencesPlaceholder()

val AppPreferences.Companion.placeholderOther
get() = newAppPreferencesPlaceholderOther()

fun test_equals() {
val a = AppPreferences.placeholder
val b = AppPreferences.placeholderOther

// TODO will change these when HexCoded32Bytes is represented with a list of bytes
//assert(a == AppPreferences.placeholder)
assert(a != b)
//assert(b == AppPreferences.placeholderOther)
}

fun test_hashCode() {
val a = AppPreferences.placeholder
val b = AppPreferences.placeholderOther
assert(setOf(a, a).size == 1)
assert(setOf(b, b).size == 1)
assert(setOf(a, b, b, a).size == 2)
}

fun test() {
test_equals()
test_hashCode()
}

test()
32 changes: 32 additions & 0 deletions profile/tests/uniffi/bindings/test_factor_sources.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import radix.wallet.kit.*

val placeholder: List<FactorSource>
get() = newFactorSourcesPlaceholder()

val placeholderOther: List<FactorSource>
get() = newFactorSourcesPlaceholderOther()

fun test_equals() {
val a = placeholder
val b = placeholderOther

// TODO will change these when HexCoded32Bytes is represented with a list of bytes
//assert(a == placeholder)
assert(a != b)
//assert(b == placeholderOther)
}

fun test_hashCode() {
val a = placeholder
val b = placeholderOther
assert(setOf(a, a).size == 1)
assert(setOf(b, b).size == 1)
assert(setOf(a, b, b, a).size == 2)
}

fun test() {
test_equals()
test_hashCode()
}

test()
39 changes: 39 additions & 0 deletions profile/tests/uniffi/bindings/test_gateways.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import radix.wallet.kit.*

val Gateways.Companion.placeholder
get() = newGatewaysPlaceholder()

val Gateways.Companion.placeholderOther
get() = newGatewaysPlaceholderOther()

fun test_equals() {
val a = Gateways.placeholder
val b = Gateways.placeholderOther

assert(a == Gateways.placeholder)
assert(a != b)
assert(b == Gateways.placeholderOther)
}

fun test_hashCode() {
val a = Gateways.placeholder
val b = Gateways.placeholderOther
assert(setOf(a, a).size == 1)
assert(setOf(b, b).size == 1)
assert(setOf(a, b, b, a).size == 2)
}

fun test_new() {
val mainnet = gatewayMainnet()
assert(mainnet == gatewayMainnet())
val gateways = newGateways(current = mainnet)
assert(gateways.current.network.id == NetworkId.MAINNET)
}

fun test() {
test_equals()
test_hashCode()
test_new()
}

test()
32 changes: 32 additions & 0 deletions profile/tests/uniffi/bindings/test_header.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import radix.wallet.kit.*

val Header.Companion.placeholder
get() = newHeaderPlaceholder()

val Header.Companion.placeholderOther
get() = newHeaderPlaceholderOther()

fun test_equals() {
val a = Header.placeholder
val b = Header.placeholderOther

assert(a == Header.placeholder)
assert(a != b)
assert(b == Header.placeholderOther)
}

fun test_hashCode() {
val a = Header.placeholder
val b = Header.placeholderOther

assert(setOf(a, a).size == 1)
assert(setOf(b, b).size == 1)
assert(setOf(a, b, b, a).size == 2)
}

fun test() {
test_equals()
test_hashCode()
}

test()
Loading

0 comments on commit 3f59042

Please sign in to comment.