Skip to content

Commit

Permalink
porting xmtp_id tests to wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Sep 4, 2024
1 parent ece65fa commit a784ebc
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 77 deletions.
66 changes: 45 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ tracing-subscriber = "0.3"
diesel = { version = "2.2", default-features = false }
diesel-wasm-sqlite = "0.0.1"
diesel_migrations = { version = "2.2", default-features = false }
wasm-bindgen-test = "0.3"
gloo-timers = "0.3"

# Internal Crate Dependencies
xmtp_cryptography = { path = "xmtp_cryptography" }
Expand Down
2 changes: 1 addition & 1 deletion bindings_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
js-sys = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = "0.2.91"
wasm-bindgen = "0.2.93"
wasm-bindgen-futures = "0.4.41"
xmtp_api_http = { path = "../xmtp_api_http" }
xmtp_cryptography = { path = "../xmtp_cryptography" }
Expand Down
7 changes: 6 additions & 1 deletion xmtp_api_http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ tokio-stream = { version = "0.1", default-features = false }
tracing.workspace = true
xmtp_proto = { path = "../xmtp_proto", features = ["proto_full"] }

[dev-dependencies]
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
tokio = { workspace = true, features = ["macros", "time"] }
wasm-bindgen-test.workspace = true

[profile.release]
opt-level = "s"

5 changes: 4 additions & 1 deletion xmtp_api_http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,16 @@ impl XmtpIdentityClient for XmtpHttpApiClient {
// tests
#[cfg(test)]
mod tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker);
use xmtp_proto::xmtp::mls::api::v1::KeyPackageUpload;

use crate::constants::ApiUrls;

use super::*;

#[tokio::test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_upload_key_package() {
let client = XmtpHttpApiClient::new(ApiUrls::LOCAL_ADDRESS.to_string()).unwrap();
let result = client
Expand Down
6 changes: 4 additions & 2 deletions xmtp_id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ openmls = { workspace = true, features = ["js"] }
openmls.workspace = true

[dev-dependencies]
ctor = "0.2.5"
ed25519-dalek = { workspace = true, features = ["digest"] }
futures = "0.3"
regex = "1.10"
tokio = { workspace = true, features = ["macros", "time"] }
xmtp_v2 = { path = "../xmtp_v2" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test.workspace = true
gloo-timers.workspace = true

[features]
test-utils = []
16 changes: 10 additions & 6 deletions xmtp_id/src/associations/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{
UnsignedChangeRecoveryAddress, UnsignedCreateInbox, UnsignedIdentityUpdate,
UnsignedRevokeAssociation,
},
Action, IdentityUpdate, MemberIdentifier, MemberKind, SignatureError,
Action, IdentityUpdate, MemberIdentifier, MemberKind, Signature, SignatureError,
};

/// The SignatureField is used to map the signatures from a [SignatureRequest] back to the correct
Expand Down Expand Up @@ -363,7 +363,7 @@ fn get_signature_text(
}

#[cfg(test)]
mod tests {
pub(crate) mod tests {
use crate::associations::{
get_state,
hashes::generate_inbox_id,
Expand Down Expand Up @@ -394,7 +394,8 @@ mod tests {
}
}

#[tokio::test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn create_inbox() {
let account_address = "account_address".to_string();
let nonce = 0;
Expand All @@ -414,7 +415,8 @@ mod tests {
.expect("should be valid");
}

#[tokio::test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn create_and_add_identity() {
let account_address = "account_address".to_string();
let nonce = 0;
Expand All @@ -439,7 +441,8 @@ mod tests {
assert_eq!(state.members().len(), 2);
}

#[tokio::test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn create_and_revoke() {
let account_address = "account_address".to_string();
let nonce = 0;
Expand All @@ -464,7 +467,8 @@ mod tests {
assert_eq!(state.members().len(), 0);
}

#[tokio::test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn attempt_adding_unknown_signer() {
let account_address = "account_address".to_string();
let nonce = 0;
Expand Down
5 changes: 3 additions & 2 deletions xmtp_id/src/associations/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl PartialEq<MemberIdentifier> for Member {
}

#[cfg(test)]
mod tests {
pub(crate) mod tests {
use crate::associations::test_utils;

use super::*;
Expand All @@ -122,7 +122,8 @@ mod tests {
}
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_identifier_comparisons() {
let address_1 = MemberIdentifier::Address("0x123".to_string());
let address_2 = MemberIdentifier::Address("0x456".to_string());
Expand Down
Loading

0 comments on commit a784ebc

Please sign in to comment.