Skip to content

Commit 8b8e482

Browse files
Run more tests in wasm
Instead of repeating ourselves in defining one big test for the wasm target, we can override the `test` attribute with the `wasm-bindgen-test` one and therefore automatically run all (supported) tests in wasm. Unfortunately, wasm doesn't support catching panics yet which means we have to disable the `test_panic_raw_ctx` test.
1 parent 3151352 commit 8b8e482

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

src/ecdh.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ mod tests {
168168
use super::SharedSecret;
169169
use super::super::Secp256k1;
170170

171+
#[cfg(target_arch = "wasm32")]
172+
use wasm_bindgen_test::wasm_bindgen_test as test;
173+
171174
#[test]
172175
fn ecdh() {
173176
let s = Secp256k1::signing_only();

src/key.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ mod test {
429429
use std::iter;
430430
use std::str::FromStr;
431431

432+
#[cfg(target_arch = "wasm32")]
433+
use wasm_bindgen_test::wasm_bindgen_test as test;
434+
432435
macro_rules! hex {
433436
($hex:expr) => ({
434437
let mut result = vec![0; $hex.len() / 2];

src/lib.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub use secp256k1_sys as ffi;
133133
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
134134
#[cfg(any(test, feature = "rand"))] use rand::Rng;
135135
#[cfg(any(test, feature = "std"))] extern crate core;
136+
#[cfg(all(test, target_arch = "wasm32"))] extern crate wasm_bindgen_test;
136137

137138
use core::{fmt, ptr, str};
138139

@@ -770,6 +771,9 @@ mod tests {
770771
use ffi::{self, types::AlignedType};
771772
use context::*;
772773

774+
#[cfg(target_arch = "wasm32")]
775+
use wasm_bindgen_test::wasm_bindgen_test as test;
776+
773777
macro_rules! hex {
774778
($hex:expr) => ({
775779
let mut result = vec![0; $hex.len() / 2];
@@ -831,6 +835,7 @@ mod tests {
831835
drop(ctx_full);drop(ctx_sign);drop(ctx_vrfy);
832836
}
833837

838+
#[cfg(not(target_arch = "wasm32"))]
834839
#[test]
835840
#[should_panic]
836841
fn test_panic_raw_ctx() {
@@ -1125,33 +1130,6 @@ mod tests {
11251130
assert!(SECP256K1.verify(&msg, &sig, &pk).is_ok());
11261131
}
11271132

1128-
// For WASM, just run through our general tests in this file all at once.
1129-
#[cfg(target_arch = "wasm32")]
1130-
extern crate wasm_bindgen_test;
1131-
#[cfg(target_arch = "wasm32")]
1132-
use self::wasm_bindgen_test::*;
1133-
#[cfg(target_arch = "wasm32")]
1134-
#[wasm_bindgen_test]
1135-
fn stuff() {
1136-
test_manual_create_destroy();
1137-
test_raw_ctx();
1138-
// Note that, sadly, WASM doesn't currently properly unwind panics, so use of the library
1139-
// via unsafe primitives may cause abort() instead of catch-able panics.
1140-
/*assert!(std::panic::catch_unwind(|| {
1141-
test_panic_raw_ctx();
1142-
}).is_err());*/
1143-
test_preallocation();
1144-
capabilities();
1145-
signature_serialize_roundtrip();
1146-
signature_display();
1147-
signature_lax_der();
1148-
sign_and_verify();
1149-
sign_and_verify_extreme();
1150-
sign_and_verify_fail();
1151-
test_bad_slice();
1152-
test_low_s();
1153-
}
1154-
11551133
#[cfg(feature = "bitcoin_hashes")]
11561134
#[test]
11571135
fn test_from_hash() {

src/recovery.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ mod tests {
199199
use super::super::{Secp256k1, Message};
200200
use super::super::Error::{IncorrectSignature, InvalidSignature};
201201

202+
#[cfg(target_arch = "wasm32")]
203+
use wasm_bindgen_test::wasm_bindgen_test as test;
204+
202205
#[test]
203206
fn capabilities() {
204207
let sign = Secp256k1::signing_only();

src/schnorrsig.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ mod tests {
500500
use std::iter;
501501
use std::str::FromStr;
502502

503+
#[cfg(target_arch = "wasm32")]
504+
use wasm_bindgen_test::wasm_bindgen_test as test;
505+
503506
macro_rules! hex_32 {
504507
($hex:expr) => {{
505508
let mut result = [0; 32];

0 commit comments

Comments
 (0)