bitcoindevkit / bdk

A modern, lightweight, descriptor-based wallet library written in Rust!
Other
860 stars 307 forks source link

Tests fail to compile for WASM target #175

Open justinmoon opened 3 years ago

justinmoon commented 3 years ago

Observed this testing out #174. Seems like the socks crate isn't compatible with WASM?? Our CI doesn't seems to experience this because it just runs cargo check and not cargo test.

$ cargo test --target wasm32-unknown-unknown --features cli-utils,esplora --no-default-features
   Compiling socks v0.3.2
   Compiling url v1.7.2
   Compiling url v2.2.0
   Compiling js-sys v0.3.45
   Compiling getrandom v0.1.15
   Compiling bitcoincore-rpc-json v0.12.0
   Compiling miniscript v2.0.0 (https://github.com/MagicalBitcoin/rust-miniscript?rev=dfc53201aa5796b6bf3b5a40581d192abaa84133#dfc53201)
   Compiling futures v0.3.8
error[E0599]: no method named `writev` found for struct `std::net::UdpSocket` in the current scope
   --> /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socks-0.3.2/src/v5.rs:392:21
    |
392 |         self.socket.writev([&header[..len + 3], buf])
    |                     ^^^^^^ method not found in `std::net::UdpSocket`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
note: `writev::WritevExt` defines an item `writev`, perhaps you need to implement it
   --> /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socks-0.3.2/src/writev.rs:4:1
    |
4   | pub trait WritevExt {
    | ^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `readv` found for struct `std::net::UdpSocket` in the current scope
   --> /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socks-0.3.2/src/v5.rs:398:31
    |
398 |         let len = self.socket.readv([&mut header, buf])?;
    |                               ^^^^^ method not found in `std::net::UdpSocket`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
note: `writev::WritevExt` defines an item `readv`, perhaps you need to implement it
   --> /home/justin/.cargo/registry/src/github.com-1ecc6299db9ec823/socks-0.3.2/src/writev.rs:4:1
    |
4   | pub trait WritevExt {
    | ^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `socks`.

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
afilini commented 3 years ago

I think this is because the tests depend on our testutils crate, which itself depends on electrum-client to interact with the electrum server while the end to end tests are running. Things like waiting for the electrum server to index a transaction before moving forward, or waiting for the chaintip to update.

I guess we could use conditional compilation to exclude some parts when running under wasm32, but I haven't bothered doing that yet because it's not that easy to run the tests on a non-native platform: I think the output of cargo test would be a wasm32 binary somewhere in ./target/wasm32-unknown-unknown, and then you would have to write a js wrapper to load that in a browser to actually run the test, you can't just run that from your command line unfortunately.