Skip to content

Commit

Permalink
chore(webtransport): Add interop-tests support with wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Jun 12, 2023
1 parent 1cc6656 commit 05bf0d3
Show file tree
Hide file tree
Showing 9 changed files with 1,616 additions and 292 deletions.
857 changes: 824 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 48 additions & 4 deletions interop-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,60 @@ version = "0.1.0"
publish = false
license = "MIT"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = "1"
either = "1.8.0"
env_logger = "0.10.0"
futures = "0.3.28"
libp2p = { path = "../libp2p", features = ["websocket", "yamux", "tcp", "tokio", "ping", "noise", "tls", "dns", "rsa", "macros"] }
log = "0.4"
serde = { version = "1", features = ["derive"] }
rand = "0.8.5"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
libp2p = { path = "../libp2p", features = [
"ping",
"noise",
"tls",
"rsa",
"macros",
"websocket",
"tokio",
"yamux",
"tcp",
"dns",
] }
libp2p-quic = { workspace = true, features = ["tokio"] }
libp2p-webrtc = { workspace = true, features = ["tokio"] }
libp2p-mplex = { path = "../muxers/mplex" }
log = "0.4"
rand = "0.8.5"
redis = { version = "0.23.0", default-features = false, features = ["tokio-comp"] }
redis = { version = "0.23.0", default-features = false, features = [
"tokio-comp",
] }
tokio = { version = "1.28.2", features = ["full"] }
# for redis proxy
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
axum = "0.6"
tower-http = { version = "0.4", features = ["cors", "fs", "trace"] }
thirtyfour = "0.31"

[target.'cfg(target_arch = "wasm32")'.dependencies]
libp2p = { path = "../libp2p", features = [
"ping",
"noise",
"tls",
"rsa",
"macros",
"webtransport-websys",
"wasm-bindgen",
"wasm-ext",
] }
wasm-bindgen = { version = "0.2" }
wasm-bindgen-futures = { version = "0.4" }
wasm-logger = { version = "0.2.0" }
wasm-timer = { version = "0.2.5" }
gloo-timers = { version = "0.2.6" }
reqwest = { version = "0.11", features = ["json"] }
console_error_panic_hook = { version = "0.1.7" }
2 changes: 1 addition & 1 deletion interop-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /workspace
ADD . .
RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build --release --package interop-tests
cargo build --release --package interop-tests --bin ping

RUN --mount=type=cache,target=./target \
mv ./target/release/ping /usr/local/bin/testplan
Expand Down
33 changes: 33 additions & 0 deletions interop-tests/Dockerfile.chromium
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM rust:1.67.0 as builder

# Run with access to the target cache to speed up builds
WORKDIR /workspace
ADD . .

RUN rustup target add wasm32-unknown-unknown

RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install wasm-pack@0.11.1 --locked

RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/registry \
wasm-pack build --target web interop-tests

RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build --release --package interop-tests --bin wasm_ping

RUN --mount=type=cache,target=./target \
mv ./target/release/wasm_ping /usr/local/bin/testplan
RUN --mount=type=cache,target=./target \
mv ./interop-tests/pkg /usr/local/share/testplan-pkg

FROM selenium/standalone-chrome:112.0
COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan
COPY --from=builder /usr/local/share/testplan-pkg /usr/local/share/testplan-pkg

ENV RUST_BACKTRACE=1
ENV wasm_pkg_dir="/usr/local/share/testplan-pkg"
ENV proxy_addr="127.0.0.1:6378"

ENTRYPOINT ["testplan"]
16 changes: 14 additions & 2 deletions interop-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ can dial/listen for ourselves we can do the following:

1. Start redis (needed by the tests): `docker run --rm -it -p 6379:6379
redis/redis-stack`.
2. In one terminal run the dialer: `REDIS_ADDR=localhost:6379 ip="0.0.0.0"
2. In one terminal run the dialer: `redis_addr=localhost:6379 ip="0.0.0.0"
transport=quic-v1 security=quic muxer=quic is_dialer="true" cargo run --bin ping`
3. In another terminal, run the listener: `REDIS_ADDR=localhost:6379
3. In another terminal, run the listener: `redis_addr=localhost:6379
ip="0.0.0.0" transport=quic-v1 security=quic muxer=quic is_dialer="false" cargo run --bin ping`


To test the interop with other versions do something similar, except replace one
of these nodes with the other version's interop test.

# Running this test with webtransport dialer in browser

To run the webtransport test from within the browser, you'll need the
`chromedriver` in your `$PATH`, compatible with your Chrome browser.
Firefox is not yet supported as it doesn't support all required features yet
(in v114 there is no support for certhashes).

2.
- Build the wasm package: `wasm-pack build --target web`
- Run the dialer pointing it to the built package: `redis_addr=127.0.0.1:6379 proxy_addr=127.0.0.1:6378
ip=0.0.0.0 transport=webtransport is_dialer=true wasm_pkg_dir=pkg cargo run --bin wasm_ping`

# Running all interop tests locally with Compose

To run this test against all released libp2p versions you'll need to have the
Expand Down
Loading

0 comments on commit 05bf0d3

Please sign in to comment.