From 1122896a70f55bbf8576ce613349a87f3508b0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Granh=C3=A3o?= <32176319+danielgranhao@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:12:13 +0100 Subject: [PATCH] Wasm: Run tests on node.js (#872) --- lib/core/Cargo.toml | 3 +- lib/core/Makefile | 28 +++++++++++++------ lib/core/src/chain_swap.rs | 2 +- lib/core/src/payjoin/network_fee.rs | 2 +- lib/core/src/payjoin/pset/tests.rs | 2 +- lib/core/src/payjoin/side_swap.rs | 2 +- lib/core/src/payjoin/utxo_select/tests.rs | 2 +- lib/core/src/persist/address.rs | 2 +- lib/core/src/persist/cache.rs | 2 +- lib/core/src/persist/chain.rs | 2 +- lib/core/src/persist/mod.rs | 2 +- lib/core/src/persist/receive.rs | 2 +- lib/core/src/persist/send.rs | 2 +- lib/core/src/receive_swap.rs | 2 +- .../tests/handle_chain_receive_swap_tests.rs | 2 +- ...le_chain_receive_swap_tests_integration.rs | 2 +- .../tests/handle_chain_send_swap_tests.rs | 2 +- ...andle_chain_send_swap_tests_integration.rs | 2 +- .../tests/handle_receive_swap_tests.rs | 2 +- .../handle_receive_swap_tests_integration.rs | 2 +- .../handlers/tests/handle_send_swap_tests.rs | 2 +- .../handle_send_swap_tests_integration.rs | 2 +- lib/core/src/sdk.rs | 2 +- lib/core/src/send_swap.rs | 2 +- lib/core/src/signer.rs | 2 +- lib/core/src/sync/mod.rs | 2 +- lib/core/src/utils.rs | 2 +- lib/core/src/wallet/mod.rs | 2 +- lib/core/tests/regtest/bitcoin.rs | 2 +- lib/core/tests/regtest/bolt11.rs | 2 +- lib/core/tests/regtest/liquid.rs | 2 +- 31 files changed, 50 insertions(+), 39 deletions(-) diff --git a/lib/core/Cargo.toml b/lib/core/Cargo.toml index a526dc3..fbac320 100644 --- a/lib/core/Cargo.toml +++ b/lib/core/Cargo.toml @@ -13,7 +13,8 @@ frb = ["dep:flutter_rust_bridge"] # Uniffi features required to build using cargo-lipo uniffi-25 = [] uniffi-28 = [] -regtest = [] # Enable regtest tests +regtest = [] # Enable regtest tests +browser-tests = [] # Enable browser wasm-pack tests test-utils = ["sdk-common/test-utils"] [lints] diff --git a/lib/core/Makefile b/lib/core/Makefile index afe4186..3fc79b9 100644 --- a/lib/core/Makefile +++ b/lib/core/Makefile @@ -37,27 +37,37 @@ regtest-stop: REGTEST_TESTS ?= regtest cargo-regtest-test: check-regtest - $(REGTEST_PREFIX) cargo test $(REGTEST_TESTS) --features "regtest" + $(REGTEST_PREFIX) cargo test $(REGTEST_TESTS) --features regtest wasm-clippy: $(CLANG_PREFIX) cargo clippy --all-targets --target=wasm32-unknown-unknown -- -D warnings BROWSER ?= firefox -wasm-test: - $(CLANG_PREFIX) wasm-pack test --headless --$(BROWSER) +wasm-test: test-browser test-node + +test-node: + $(CLANG_PREFIX) wasm-pack test --node + +test-browser: + $(CLANG_PREFIX) wasm-pack test --headless --$(BROWSER) --features browser-tests test-chrome: - BROWSER=chrome $(MAKE) wasm-test + BROWSER=chrome $(MAKE) test-browser test-safari: - BROWSER=safari $(MAKE) wasm-test + BROWSER=safari $(MAKE) test-browser -wasm-regtest-test: check-regtest - $(CLANG_PREFIX) $(REGTEST_PREFIX) WASM_BINDGEN_TEST_TIMEOUT=500 wasm-pack test --headless --$(BROWSER) --features regtest -- $(REGTEST_TESTS) +wasm-regtest-test: wasm-regtest-test-browser wasm-regtest-test-node + +wasm-regtest-test-node: check-regtest + $(CLANG_PREFIX) $(REGTEST_PREFIX) WASM_BINDGEN_TEST_TIMEOUT=500 wasm-pack test --node --features regtest -- $(REGTEST_TESTS) + +wasm-regtest-test-browser: check-regtest + $(CLANG_PREFIX) $(REGTEST_PREFIX) WASM_BINDGEN_TEST_TIMEOUT=500 wasm-pack test --headless --$(BROWSER) --features regtest,browser-tests -- $(REGTEST_TESTS) wasm-regtest-test-chrome: - BROWSER=chrome $(MAKE) wasm-regtest-test + BROWSER=chrome $(MAKE) wasm-regtest-test-browser wasm-regtest-test-safari: - BROWSER=safari $(MAKE) wasm-regtest-test + BROWSER=safari $(MAKE) wasm-regtest-test-browser diff --git a/lib/core/src/chain_swap.rs b/lib/core/src/chain_swap.rs index 7b5ca2c..d4e90a8 100644 --- a/lib/core/src/chain_swap.rs +++ b/lib/core/src/chain_swap.rs @@ -1520,7 +1520,7 @@ mod tests { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/payjoin/network_fee.rs b/lib/core/src/payjoin/network_fee.rs index ce2f796..45280f2 100644 --- a/lib/core/src/payjoin/network_fee.rs +++ b/lib/core/src/payjoin/network_fee.rs @@ -47,7 +47,7 @@ impl TxFee { mod tests { use super::*; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/payjoin/pset/tests.rs b/lib/core/src/payjoin/pset/tests.rs index 1942999..97be826 100644 --- a/lib/core/src/payjoin/pset/tests.rs +++ b/lib/core/src/payjoin/pset/tests.rs @@ -10,7 +10,7 @@ use std::str::FromStr; use crate::payjoin::pset::{construct_pset, ConstructPsetRequest, PsetInput, PsetOutput}; -#[cfg(all(target_family = "wasm", target_os = "unknown"))] +#[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); fn create_test_secret_key() -> SecretKey { diff --git a/lib/core/src/payjoin/side_swap.rs b/lib/core/src/payjoin/side_swap.rs index 76d4a6c..453055b 100644 --- a/lib/core/src/payjoin/side_swap.rs +++ b/lib/core/src/payjoin/side_swap.rs @@ -487,7 +487,7 @@ mod tests { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); fn create_sideswap_payjoin_service( diff --git a/lib/core/src/payjoin/utxo_select/tests.rs b/lib/core/src/payjoin/utxo_select/tests.rs index 19a8cdb..290abec 100644 --- a/lib/core/src/payjoin/utxo_select/tests.rs +++ b/lib/core/src/payjoin/utxo_select/tests.rs @@ -11,7 +11,7 @@ use crate::payjoin::{ }, }; -#[cfg(all(target_family = "wasm", target_os = "unknown"))] +#[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/persist/address.rs b/lib/core/src/persist/address.rs index 942cfbe..aea33a6 100644 --- a/lib/core/src/persist/address.rs +++ b/lib/core/src/persist/address.rs @@ -102,7 +102,7 @@ mod tests { use crate::test_utils::persist::create_persister; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/persist/cache.rs b/lib/core/src/persist/cache.rs index b07853c..a373e44 100644 --- a/lib/core/src/persist/cache.rs +++ b/lib/core/src/persist/cache.rs @@ -208,7 +208,7 @@ mod tests { use crate::test_utils::persist::create_persister; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/persist/chain.rs b/lib/core/src/persist/chain.rs index bcabd88..c038cb8 100644 --- a/lib/core/src/persist/chain.rs +++ b/lib/core/src/persist/chain.rs @@ -534,7 +534,7 @@ mod tests { use crate::test_utils::persist::create_persister; use anyhow::Result; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/persist/mod.rs b/lib/core/src/persist/mod.rs index edb354a..3e08877 100644 --- a/lib/core/src/persist/mod.rs +++ b/lib/core/src/persist/mod.rs @@ -1133,7 +1133,7 @@ mod tests { use super::{PaymentState, PaymentType}; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/persist/receive.rs b/lib/core/src/persist/receive.rs index d9dd914..563df9a 100644 --- a/lib/core/src/persist/receive.rs +++ b/lib/core/src/persist/receive.rs @@ -418,7 +418,7 @@ mod tests { use super::PaymentState; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/persist/send.rs b/lib/core/src/persist/send.rs index 856be90..293a995 100644 --- a/lib/core/src/persist/send.rs +++ b/lib/core/src/persist/send.rs @@ -429,7 +429,7 @@ mod tests { use super::PaymentState; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/receive_swap.rs b/lib/core/src/receive_swap.rs index 8fa62d1..41f521c 100644 --- a/lib/core/src/receive_swap.rs +++ b/lib/core/src/receive_swap.rs @@ -562,7 +562,7 @@ mod tests { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests.rs b/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests.rs index 2e3d96b..cad70c1 100644 --- a/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests.rs +++ b/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests.rs @@ -9,7 +9,7 @@ mod test { }; use boltz_client::boltz::PairLimits; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests_integration.rs b/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests_integration.rs index aefb850..9191094 100644 --- a/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests_integration.rs +++ b/lib/core/src/recover/handlers/tests/handle_chain_receive_swap_tests_integration.rs @@ -16,7 +16,7 @@ mod test { use sdk_common::utils::Arc; use std::{collections::HashMap, str::FromStr}; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests.rs b/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests.rs index 3db8272..27a8212 100644 --- a/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests.rs +++ b/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests.rs @@ -8,7 +8,7 @@ mod test { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests_integration.rs b/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests_integration.rs index c10903b..0ba546c 100644 --- a/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests_integration.rs +++ b/lib/core/src/recover/handlers/tests/handle_chain_send_swap_tests_integration.rs @@ -19,7 +19,7 @@ mod test { use std::{collections::HashMap, str::FromStr}; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_receive_swap_tests.rs b/lib/core/src/recover/handlers/tests/handle_receive_swap_tests.rs index c39fabb..22759af 100644 --- a/lib/core/src/recover/handlers/tests/handle_receive_swap_tests.rs +++ b/lib/core/src/recover/handlers/tests/handle_receive_swap_tests.rs @@ -7,7 +7,7 @@ mod test { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_receive_swap_tests_integration.rs b/lib/core/src/recover/handlers/tests/handle_receive_swap_tests_integration.rs index eac8a2a..fa10313 100644 --- a/lib/core/src/recover/handlers/tests/handle_receive_swap_tests_integration.rs +++ b/lib/core/src/recover/handlers/tests/handle_receive_swap_tests_integration.rs @@ -15,7 +15,7 @@ mod test { use sdk_common::utils::Arc; use std::{collections::HashMap, str::FromStr}; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_send_swap_tests.rs b/lib/core/src/recover/handlers/tests/handle_send_swap_tests.rs index b8bcc67..ca56e34 100644 --- a/lib/core/src/recover/handlers/tests/handle_send_swap_tests.rs +++ b/lib/core/src/recover/handlers/tests/handle_send_swap_tests.rs @@ -7,7 +7,7 @@ mod test { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/recover/handlers/tests/handle_send_swap_tests_integration.rs b/lib/core/src/recover/handlers/tests/handle_send_swap_tests_integration.rs index 128febd..3d68224 100644 --- a/lib/core/src/recover/handlers/tests/handle_send_swap_tests_integration.rs +++ b/lib/core/src/recover/handlers/tests/handle_send_swap_tests_integration.rs @@ -18,7 +18,7 @@ mod test { use std::collections::HashMap; use std::str::FromStr; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); /// Test recovery with a claim transaction and preimage diff --git a/lib/core/src/sdk.rs b/lib/core/src/sdk.rs index fa9d70a..4355ec3 100644 --- a/lib/core/src/sdk.rs +++ b/lib/core/src/sdk.rs @@ -4061,7 +4061,7 @@ mod tests { }; use paste::paste; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); struct NewSwapArgs { diff --git a/lib/core/src/send_swap.rs b/lib/core/src/send_swap.rs index 4603323..d3d4266 100644 --- a/lib/core/src/send_swap.rs +++ b/lib/core/src/send_swap.rs @@ -593,7 +593,7 @@ mod tests { }, }; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/signer.rs b/lib/core/src/signer.rs index bbf49bb..c940068 100644 --- a/lib/core/src/signer.rs +++ b/lib/core/src/signer.rs @@ -298,7 +298,7 @@ mod tests { }; use std::collections::BTreeMap; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); fn get_descriptor( diff --git a/lib/core/src/sync/mod.rs b/lib/core/src/sync/mod.rs index 9a9e768..8bfad60 100644 --- a/lib/core/src/sync/mod.rs +++ b/lib/core/src/sync/mod.rs @@ -569,7 +569,7 @@ mod tests { use super::model::{data::SyncData, Record, RecordType}; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/src/utils.rs b/lib/core/src/utils.rs index dc6c4c4..7ae6ae0 100644 --- a/lib/core/src/utils.rs +++ b/lib/core/src/utils.rs @@ -177,7 +177,7 @@ mod tests { use crate::error::PaymentError; use crate::utils::verify_payment_hash; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::test_all] diff --git a/lib/core/src/wallet/mod.rs b/lib/core/src/wallet/mod.rs index 8ebdde3..4d3fd9e 100644 --- a/lib/core/src/wallet/mod.rs +++ b/lib/core/src/wallet/mod.rs @@ -637,7 +637,7 @@ mod tests { use crate::wallet::LiquidOnchainWallet; use anyhow::Result; - #[cfg(all(target_family = "wasm", target_os = "unknown"))] + #[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/tests/regtest/bitcoin.rs b/lib/core/tests/regtest/bitcoin.rs index 8dd48c2..4f3df22 100644 --- a/lib/core/tests/regtest/bitcoin.rs +++ b/lib/core/tests/regtest/bitcoin.rs @@ -8,7 +8,7 @@ use serial_test::serial; use crate::regtest::{utils, SdkNodeHandle, TIMEOUT}; -#[cfg(all(target_family = "wasm", target_os = "unknown"))] +#[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/tests/regtest/bolt11.rs b/lib/core/tests/regtest/bolt11.rs index 76d7bf4..e99c69f 100644 --- a/lib/core/tests/regtest/bolt11.rs +++ b/lib/core/tests/regtest/bolt11.rs @@ -10,7 +10,7 @@ use crate::regtest::{ SdkNodeHandle, TIMEOUT, }; -#[cfg(all(target_family = "wasm", target_os = "unknown"))] +#[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all] diff --git a/lib/core/tests/regtest/liquid.rs b/lib/core/tests/regtest/liquid.rs index e3cdec3..c56ed93 100644 --- a/lib/core/tests/regtest/liquid.rs +++ b/lib/core/tests/regtest/liquid.rs @@ -6,7 +6,7 @@ use serial_test::serial; use crate::regtest::{utils, SdkNodeHandle, TIMEOUT}; -#[cfg(all(target_family = "wasm", target_os = "unknown"))] +#[cfg(feature = "browser-tests")] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); #[sdk_macros::async_test_all]