diff --git a/Cargo.lock b/Cargo.lock index 29b26e7d5..98420b928 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1078,7 +1078,7 @@ dependencies = [ [[package]] name = "diesel-wasm-sqlite" version = "0.0.1" -source = "git+https://github.com/xmtp/libxmtp?branch=wasm-backend#05ab48f5ad21591e51adfef33a58762eb8b06e80" +source = "git+https://github.com/xmtp/libxmtp?branch=wasm-backend#9f4ffe40850c21a012f50ff953ced140e5f441a1" dependencies = [ "diesel", "diesel_derives 2.2.2", @@ -2021,7 +2021,7 @@ version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" dependencies = [ - "gloo-timers", + "gloo-timers 0.2.6", "send_wrapper 0.4.0", ] @@ -2110,6 +2110,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "group" version = "0.12.1" @@ -2746,9 +2756,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -3023,6 +3033,16 @@ dependencies = [ "unicase", ] +[[package]] +name = "minicov" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" +dependencies = [ + "cc", + "walkdir", +] + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -5941,11 +5961,12 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "serde", "serde_json", "wasm-bindgen-macro", @@ -5953,9 +5974,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -5968,9 +5989,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -5980,9 +6001,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5990,9 +6011,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -6003,18 +6024,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-bindgen-test" -version = "0.3.42" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" +checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" dependencies = [ "console_error_panic_hook", "js-sys", + "minicov", "scoped-tls", "wasm-bindgen", "wasm-bindgen-futures", @@ -6023,9 +6045,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.42" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" dependencies = [ "proc-macro2", "quote", @@ -6373,6 +6395,7 @@ dependencies = [ "tokio", "tokio-stream", "tracing", + "wasm-bindgen-test", "xmtp_proto", ] @@ -6431,13 +6454,13 @@ version = "0.0.1" dependencies = [ "async-trait", "chrono", - "ctor", "ed25519", "ed25519-dalek", "ethers", "ethers-core", "futures", "getrandom", + "gloo-timers 0.3.0", "hex", "log", "openmls", @@ -6454,6 +6477,7 @@ dependencies = [ "tokio", "tracing", "url", + "wasm-bindgen-test", "xmtp_cryptography", "xmtp_proto", "xmtp_v2", diff --git a/Cargo.toml b/Cargo.toml index 343c83205..a952a6c0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/bindings_wasm/Cargo.toml b/bindings_wasm/Cargo.toml index eeb652421..6370a473d 100644 --- a/bindings_wasm/Cargo.toml +++ b/bindings_wasm/Cargo.toml @@ -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" } diff --git a/xmtp_api_http/Cargo.toml b/xmtp_api_http/Cargo.toml index 13852a3dc..e60ad0bab 100644 --- a/xmtp_api_http/Cargo.toml +++ b/xmtp_api_http/Cargo.toml @@ -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" + diff --git a/xmtp_api_http/src/lib.rs b/xmtp_api_http/src/lib.rs index aa6fca4b4..8e4852861 100755 --- a/xmtp_api_http/src/lib.rs +++ b/xmtp_api_http/src/lib.rs @@ -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 diff --git a/xmtp_id/Cargo.toml b/xmtp_id/Cargo.toml index 5b5f8257c..05fbfb215 100644 --- a/xmtp_id/Cargo.toml +++ b/xmtp_id/Cargo.toml @@ -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 = [] diff --git a/xmtp_id/src/associations/builder.rs b/xmtp_id/src/associations/builder.rs index f53ef247b..5b6d5cdad 100644 --- a/xmtp_id/src/associations/builder.rs +++ b/xmtp_id/src/associations/builder.rs @@ -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 @@ -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, @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/xmtp_id/src/associations/member.rs b/xmtp_id/src/associations/member.rs index 44a31cde9..68e6fd184 100644 --- a/xmtp_id/src/associations/member.rs +++ b/xmtp_id/src/associations/member.rs @@ -99,7 +99,7 @@ impl PartialEq for Member { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use crate::associations::test_utils; use super::*; @@ -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()); diff --git a/xmtp_id/src/associations/mod.rs b/xmtp_id/src/associations/mod.rs index 198a84a26..6787537f7 100644 --- a/xmtp_id/src/associations/mod.rs +++ b/xmtp_id/src/associations/mod.rs @@ -1,10 +1,10 @@ mod association_log; pub mod builder; mod hashes; -mod member; -mod serialization; +pub(super) mod member; +pub(super) mod serialization; pub mod signature; -mod state; +pub(super) mod state; #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; pub mod unsigned_actions; @@ -104,7 +104,7 @@ pub mod test_defaults { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use self::test_utils::{rand_string, rand_vec, MockSignature}; use super::*; @@ -141,7 +141,8 @@ mod tests { .unwrap() } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn test_create_inbox() { let create_request = CreateInbox::default(); let inbox_id = generate_inbox_id(&create_request.account_address, &create_request.nonce); @@ -155,7 +156,8 @@ mod tests { assert!(existing_entity.identifier.eq(&account_address.into())); } - #[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_separately() { let initial_state = new_test_inbox().await; let inbox_id = initial_state.inbox_id().clone(); @@ -190,7 +192,8 @@ mod tests { assert_eq!(new_member.added_by_entity, Some(first_member)); } - #[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_together() { let create_action = CreateInbox::default(); let account_address = create_action.account_address.clone(); @@ -227,7 +230,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_from_legacy_key() { let member_identifier: MemberIdentifier = rand_string().into(); let create_action = CreateInbox { @@ -268,7 +272,8 @@ mod tests { assert!(matches!(update_result, Err(AssociationError::Replay))); } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn add_wallet_from_installation_key() { let initial_state = new_test_inbox_with_installation().await; let inbox_id = initial_state.inbox_id().clone(); @@ -305,7 +310,8 @@ mod tests { assert_eq!(new_state.members().len(), 3); } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn reject_invalid_signature_on_create() { let bad_signature = MockSignature::new_boxed(false, rand_string().into(), SignatureKind::Erc191, None); @@ -326,7 +332,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 reject_invalid_signature_on_update() { let initial_state = new_test_inbox().await; let inbox_id = initial_state.inbox_id().clone(); @@ -370,7 +377,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 reject_if_signer_not_existing_member() { let create_inbox = CreateInbox::default(); let inbox_id = generate_inbox_id(&create_inbox.account_address, &create_inbox.nonce); @@ -398,7 +406,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 reject_if_installation_adding_installation() { let existing_state = new_test_inbox_with_installation().await; let inbox_id = existing_state.inbox_id().clone(); @@ -436,7 +445,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 revoke() { let initial_state = new_test_inbox_with_installation().await; let inbox_id = initial_state.inbox_id().clone(); @@ -465,7 +475,8 @@ mod tests { assert!(new_state.get(&installation_id).is_none()); } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn revoke_children() { let initial_state = new_test_inbox_with_installation().await; let inbox_id = initial_state.inbox_id().clone(); @@ -514,7 +525,8 @@ mod tests { assert_eq!(new_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 revoke_and_re_add() { let initial_state = new_test_inbox().await; let wallet_address = initial_state @@ -589,7 +601,8 @@ mod tests { assert_eq!(state_after_re_add.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 change_recovery_address() { let initial_state = new_test_inbox_with_installation().await; let inbox_id = initial_state.inbox_id().clone(); diff --git a/xmtp_id/src/associations/serialization.rs b/xmtp_id/src/associations/serialization.rs index 1c5f21a00..d1d6f62dd 100644 --- a/xmtp_id/src/associations/serialization.rs +++ b/xmtp_id/src/associations/serialization.rs @@ -542,7 +542,7 @@ impl From for String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use crate::associations::{ hashes::generate_inbox_id, test_utils::{rand_string, rand_u64}, @@ -550,7 +550,8 @@ mod tests { use super::*; - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn test_round_trip() { let account_address = rand_string(); let nonce = rand_u64(); @@ -585,7 +586,8 @@ mod tests { assert_eq!(serialized_update, reserialized); } - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn test_accound_id() { // valid evm chain let text = "eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb".to_string(); diff --git a/xmtp_id/src/associations/signature.rs b/xmtp_id/src/associations/signature.rs index a92eef8a6..3ce0e9d8f 100644 --- a/xmtp_id/src/associations/signature.rs +++ b/xmtp_id/src/associations/signature.rs @@ -466,7 +466,7 @@ impl ValidatedLegacySignedPublicKey { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use crate::{ associations::{ @@ -484,7 +484,8 @@ mod tests { use xmtp_proto::xmtp::message_contents::SignedPublicKey as LegacySignedPublicKeyProto; use xmtp_v2::k256_helper::sign_sha256; - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn validate_good_key_round_trip() { let proto_bytes = vec![ 10, 79, 8, 192, 195, 165, 174, 203, 153, 231, 213, 23, 26, 67, 10, 65, 4, 216, 84, 174, @@ -507,7 +508,8 @@ mod tests { assert_eq!(validated_key.account_address(), account_address); } - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn validate_malformed_key() { let proto_bytes = vec![ 10, 79, 8, 192, 195, 165, 174, 203, 153, 231, 213, 23, 26, 67, 10, 65, 4, 216, 84, 174, @@ -527,7 +529,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 recover_signer_ecdsa() { let wallet: LocalWallet = LocalWallet::new(&mut rand::thread_rng()); let unsigned_action = UnsignedCreateInbox { @@ -547,7 +550,8 @@ mod tests { assert_eq!(expected, actual); } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn recover_signer_erc1271() { let wallet: LocalWallet = LocalWallet::new(&mut rand::thread_rng()); @@ -563,7 +567,8 @@ mod tests { assert_eq!(expected, actual); } - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn recover_signer_installation() { let signing_key: SigningKey = SigningKey::generate(&mut rand::thread_rng()); let verifying_key = signing_key.verifying_key(); @@ -588,7 +593,8 @@ mod tests { } // Test the happy path with LocalWallet & fail path with a secp256k1 signer. - #[tokio::test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn recover_signer_legacy() { let signature_text = "test_legacy_signature".to_string(); let account_address = "0x0bd00b21af9a2d538103c3aaf95cb507f8af1b28".to_string(); diff --git a/xmtp_id/src/associations/state.rs b/xmtp_id/src/associations/state.rs index 83cc8752e..0b03a9f87 100644 --- a/xmtp_id/src/associations/state.rs +++ b/xmtp_id/src/associations/state.rs @@ -178,12 +178,13 @@ impl AssociationState { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use crate::associations::test_utils::rand_string; use super::*; - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn can_add_remove() { let starting_state = AssociationState::new(rand_string(), 0); let new_entity = Member::default(); @@ -192,7 +193,8 @@ mod tests { assert!(starting_state.get(&new_entity.identifier).is_none()); } - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn can_diff() { let starting_state = AssociationState::new(rand_string(), 0); let entity_1 = Member::default(); diff --git a/xmtp_id/src/associations/unsigned_actions.rs b/xmtp_id/src/associations/unsigned_actions.rs index 4c89e2d31..193a0f5f8 100644 --- a/xmtp_id/src/associations/unsigned_actions.rs +++ b/xmtp_id/src/associations/unsigned_actions.rs @@ -138,12 +138,13 @@ fn pretty_timestamp(ns_date: u64) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use crate::associations::hashes::generate_inbox_id; use super::*; - #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] + #[cfg_attr(not(target_arch = "wasm32"), test)] fn create_signatures() { let account_address = "0x123".to_string(); let client_timestamp_ns: u64 = 12; diff --git a/xmtp_id/src/lib.rs b/xmtp_id/src/lib.rs index a186ec8db..cbeffbec9 100644 --- a/xmtp_id/src/lib.rs +++ b/xmtp_id/src/lib.rs @@ -69,9 +69,11 @@ impl InboxOwner for LocalWallet { #[cfg(test)] mod tests { use super::*; - use crate::scw_verifier::tests::with_smart_contracts; use ethers::contract::abigen; + #[cfg(target_arch = "wasm32")] + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker); + abigen!( CoinbaseSmartWallet, "artifact/CoinbaseSmartWallet.json", @@ -84,8 +86,11 @@ mod tests { derives(serde::Serialize, serde::Deserialize) ); - #[tokio::test] + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] + #[cfg(not(target_arch = "wasm32"))] async fn test_is_smart_contract() { + use crate::scw_verifier::tests::with_smart_contracts; + with_smart_contracts(|anvil, _provider, _client, smart_contracts| async move { let deployer: LocalWallet = anvil.keys()[0].clone().into(); let factory = smart_contracts.coinbase_smart_wallet_factory(); @@ -100,4 +105,18 @@ mod tests { }) .await; } + + // re-export tests since all wasm-bindgen tests need to be at the root + #[cfg(target_arch = "wasm32")] + mod wasm { + pub use crate::associations::builder::tests::*; + pub use crate::associations::member::tests::*; + pub use crate::associations::serialization::tests::*; + pub use crate::associations::signature::tests::*; + pub use crate::associations::state::tests::*; + pub use crate::associations::tests::*; + pub use crate::associations::unsigned_actions::tests::*; + // skipping b/c Anvil cant be used in WASM + // pub use crate::scw_verifier::tests::*; + } } diff --git a/xmtp_id/src/scw_verifier.rs b/xmtp_id/src/scw_verifier.rs index bde5ce5ea..4f64d6a63 100644 --- a/xmtp_id/src/scw_verifier.rs +++ b/xmtp_id/src/scw_verifier.rs @@ -98,8 +98,8 @@ impl SmartContractWalletVerifier { } } -#[cfg(test)] -pub mod tests { +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) mod tests { use crate::is_smart_contract; use super::*; diff --git a/xmtp_mls/src/groups/subscriptions.rs b/xmtp_mls/src/groups/subscriptions.rs index f686e4d11..d53dc0f80 100644 --- a/xmtp_mls/src/groups/subscriptions.rs +++ b/xmtp_mls/src/groups/subscriptions.rs @@ -336,7 +336,7 @@ mod tests { // just to make sure stream is started let _ = start_rx.await; // Adding in a sleep, since the HTTP API client may acknowledge requests before they are ready - tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; + crate::sleep(tokio::time::Duration::from_millis(100)).await; amal_group .add_members_by_inbox_id(&amal, vec![bola.inbox_id()]) diff --git a/xmtp_mls/src/lib.rs b/xmtp_mls/src/lib.rs index c9e57b794..3deb63fba 100644 --- a/xmtp_mls/src/lib.rs +++ b/xmtp_mls/src/lib.rs @@ -105,6 +105,16 @@ where tokio::task::spawn(future) } +#[cfg(target_arch = "wasm32")] +async fn sleep(duration: std::time::Duration) { + gloo_timers::future::TimeoutFuture::new(duration.as_millis()).await; +} + +#[cfg(not(target_arch = "wasm32"))] +async fn sleep(duration: std::time::Duration) { + tokio::time::sleep(duration).await +} + #[cfg(test)] mod tests { use log::LevelFilter; diff --git a/xmtp_mls/src/retry.rs b/xmtp_mls/src/retry.rs index a80a571f0..aa981599b 100644 --- a/xmtp_mls/src/retry.rs +++ b/xmtp_mls/src/retry.rs @@ -251,7 +251,7 @@ macro_rules! retry_async { if (&e).is_retryable() && attempts < $retry.retries() { log::warn!("retrying function that failed with error={}", e.to_string()); attempts += 1; - tokio::time::sleep($retry.duration(attempts)).await; + crate::sleep($retry.duration(attempts)).await; } else { log::info!("error is not retryable. {:?}", e); break Err(e); @@ -372,7 +372,7 @@ mod tests { return Ok(()); } // do some work - tokio::time::sleep(std::time::Duration::from_nanos(100)).await; + crate::sleep(std::time::Duration::from_nanos(100)).await; Err(SomeError::ARetryableError) } @@ -397,7 +397,7 @@ mod tests { } *data += 1; // do some work - tokio::time::sleep(std::time::Duration::from_nanos(100)).await; + crate::sleep(std::time::Duration::from_nanos(100)).await; Err(SomeError::ARetryableError) } diff --git a/xmtp_mls/src/subscriptions.rs b/xmtp_mls/src/subscriptions.rs index 2d1e4c5e6..4be9673c9 100644 --- a/xmtp_mls/src/subscriptions.rs +++ b/xmtp_mls/src/subscriptions.rs @@ -496,7 +496,7 @@ mod tests { .add_members_by_inbox_id(&bo, vec![caro.inbox_id()]) .await .unwrap(); - tokio::time::sleep(std::time::Duration::from_millis(100)).await; + crate::sleep(std::time::Duration::from_millis(100)).await; let messages: Arc>> = Arc::new(Mutex::new(Vec::new())); let messages_clone = messages.clone(); @@ -643,7 +643,7 @@ mod tests { .send_message("should not show up".as_bytes(), &alix) .await .unwrap(); - tokio::time::sleep(std::time::Duration::from_millis(100)).await; + crate::sleep(std::time::Duration::from_millis(100)).await; let messages = messages.lock(); assert_eq!(messages.len(), 5); @@ -684,7 +684,7 @@ mod tests { .send_message(b"spam", &alix_pointer) .await .unwrap(); - tokio::time::sleep(std::time::Duration::from_micros(200)).await; + crate::sleep(std::time::Duration::from_micros(200)).await; } });