Skip to content

Commit

Permalink
ci: add headless browser tests for wasm
Browse files Browse the repository at this point in the history
Squashed the following commits by @TalDerei:

  * update wasm readme and add action workflow file
  * trigger workflow on pull-request
  * add assertion check to wasm unit test
  * modify path in ci workflow
  * attemp to pass CI
  * add wasm-pack binary to workflow
  * attempt to run in headless browser mode
  * add firefox execution environment

We struggled a bit in getting the test to pass CI, but it was as simple
as ensuring that lfs=true on the repo checkout.
  • Loading branch information
TalDerei authored and conorsch committed Jan 23, 2024
1 parent 9a5bb7f commit f7d46e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ jobs:
- name: Load rust cache
uses: astriaorg/[email protected]

- name: build wasm32 target
run: cargo build --release --target wasm32-unknown-unknown
# TODO: consider failing on warnings here. A few dead-code
# warnings, leaving as-is because wasm is undergoing rapid dev
# in support of web extension.
working-directory: crates/wasm

# Download prebuilt binary for wasm-pack; faster than `cargo install`.
- uses: jetli/[email protected]
with:
version: 'latest'

# `wasm-pack build` will automatically compile to target wasm32-unknown-unknown,
# but we run it as a separate task to isolate potential failures in the build pipeline.
# Ensure that wasm crate builds cleanly. Is this superfluous, given `wasm-pack test` below?
- name: run wasm-pack build
run: wasm-pack build
working-directory: crates/wasm

# Download firefox
- uses: browser-actions/setup-firefox@v1
- run: firefox --version

- name: Run headless browser tests
run: wasm-pack test --headless --firefox -- --test test_build --target wasm32-unknown-unknown --release --features "mock-database"
working-directory: crates/wasm

# Always show the results of `cargo tree`, even if the tests failed, since that
# output will be immediately useful in debugging.
- name: display mio deps
Expand Down
9 changes: 9 additions & 0 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ wasm-pack build
```

Artifacts can be found in `pkg/`.

## Testing
The WASM crate incorperates a unit testing suite that leverages `wasm-bindgen-test` to simulate a sample spend transaction. For testing purposes, the suite mocks `indexDB` database calls in an interactive browser accessible at `http://127.0.0.1:8000`.

```
wasm-pack test --chrome -- --test test_build --target wasm32-unknown-unknown --release --features "mock-database"
```

The transaction outputs are accessible in the browser's developer console.
16 changes: 14 additions & 2 deletions crates/wasm/tests/test_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod tests {
use penumbra_tct::{structure::Hash, Forgotten};
use penumbra_transaction::{
plan::{ActionPlan, TransactionPlan},
Action,
Action, Transaction,
};
use penumbra_wasm::{
build::build_action,
Expand Down Expand Up @@ -478,7 +478,7 @@ mod tests {
}

// Deserialize actions.
let action_deserialized = serde_wasm_bindgen::to_value(&actions).unwrap();
let action_deserialized: JsValue = serde_wasm_bindgen::to_value(&actions).unwrap();

// Execute parallel spend transaction and generate proof.
let parallel_transaction = build_parallel(
Expand All @@ -499,5 +499,17 @@ mod tests {
)
.unwrap();
console_log!("Serial transaction is: {:?}", serial_transaction);

// Deserialize transactions and stringify actions in the transaction body into JSON
let serial_result: Transaction =
serde_wasm_bindgen::from_value(serial_transaction).unwrap();
let parallel_result: Transaction =
serde_wasm_bindgen::from_value(parallel_transaction).unwrap();
let serial_json = serde_json::to_string(&serial_result.transaction_body.actions).unwrap();
let parallel_json =
serde_json::to_string(&parallel_result.transaction_body.actions).unwrap();

// Perform assertion check
assert_eq!(serial_json, parallel_json);
}
}

0 comments on commit f7d46e3

Please sign in to comment.