Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to test wasm and fixes a few linter errors #10

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

s0l0ist
Copy link
Contributor

@s0l0ist s0l0ist commented Mar 2, 2024

This library can be compiled to WASM, but supporting testing for that target doesn't work out of the box. This PR addresses that.

While testing wasm, the compiler reported a few linter errors and would fail to compile (due to the project config). I've fixed them:

  • Unnecessary qualified TryFrom
  • Recommended to use serde-wasm-bindgen

How to test WASM

Install wasm-pack

Run the test command. I'm using the --release flag for speed and opting to use node (which expects a node to be in the environment). Running in the browser can be configured with more code changes, but using node should be sufficient for local testing. Unfortunately, the wasm target only works with the rust or crypto feature as gmp or openssl do not support wasm targets:

  • wasm-pack test --node --release --no-default-features --features wasm,rust
  • wasm-pack test --node --release --no-default-features --features wasm,crypto or the shorter command wasm-pack test --node --release --features wasm

Results:

[INFO]: ⬇️  Installing wasm-bindgen...
    Finished release [optimized] target(s) in 0.04s
     Running unittests src/lib.rs (target/wasm32-unknown-unknown/release/deps/libpaillier-db39394c44027fb1.wasm)
no tests to run!
     Running tests/paillier.rs (target/wasm32-unknown-unknown/release/deps/paillier-965e043a1c0af98c.wasm)
Set timeout to 20 seconds...
running 7 tests                                   

test paillier::test_all ... ok
test paillier::test_proof ... ok
test paillier::test_bytes ... ok
test paillier::test_serialization ... ok
test paillier::test_mul ... ok
test paillier::test_add ... ok
test paillier::test_encrypt ... ok

test result: ok. 7 passed; 0 failed; 0 ignored; 0 filtered out

@s0l0ist s0l0ist changed the title Adds the ability to test wasm and fixes a few linter errors Add the ability to test wasm and fixes a few linter errors Mar 2, 2024
@mikelodder7
Copy link
Owner

The faster/slower is a little misleading. crypto backend is all constant time vs rust which is not. If you are managing secrets its preferred to use crypto as your backend. However, since this is all browser based it might not make much of a difference. Thanks for the PR. reviewing

@mikelodder7 mikelodder7 merged commit af50481 into mikelodder7:main Mar 4, 2024
1 check failed
@s0l0ist
Copy link
Contributor Author

s0l0ist commented Mar 5, 2024

Understood, I've removed the verbiage from the PR body for future readers. What I was trying to say is that enabling the crypto feature runs slower than the rust feature when running the tests for the WASM target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants