Skip to content

Commit b31bf2f

Browse files
authored
Merge pull request #258 from thomaseizinger/better-wasm-tests
Run more tests in wasm
2 parents 2917de5 + 8b8e482 commit b31bf2f

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
@@ -173,6 +173,9 @@ mod tests {
173173
use super::SharedSecret;
174174
use super::super::Secp256k1;
175175

176+
#[cfg(target_arch = "wasm32")]
177+
use wasm_bindgen_test::wasm_bindgen_test as test;
178+
176179
#[test]
177180
fn ecdh() {
178181
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];
@@ -840,6 +844,7 @@ mod tests {
840844
drop(ctx_vrfy);
841845
}
842846

847+
#[cfg(not(target_arch = "wasm32"))]
843848
#[test]
844849
#[should_panic]
845850
fn test_panic_raw_ctx() {
@@ -1134,33 +1139,6 @@ mod tests {
11341139
assert!(SECP256K1.verify(&msg, &sig, &pk).is_ok());
11351140
}
11361141

1137-
// For WASM, just run through our general tests in this file all at once.
1138-
#[cfg(target_arch = "wasm32")]
1139-
extern crate wasm_bindgen_test;
1140-
#[cfg(target_arch = "wasm32")]
1141-
use self::wasm_bindgen_test::*;
1142-
#[cfg(target_arch = "wasm32")]
1143-
#[wasm_bindgen_test]
1144-
fn stuff() {
1145-
test_manual_create_destroy();
1146-
test_raw_ctx();
1147-
// Note that, sadly, WASM doesn't currently properly unwind panics, so use of the library
1148-
// via unsafe primitives may cause abort() instead of catch-able panics.
1149-
/*assert!(std::panic::catch_unwind(|| {
1150-
test_panic_raw_ctx();
1151-
}).is_err());*/
1152-
test_preallocation();
1153-
capabilities();
1154-
signature_serialize_roundtrip();
1155-
signature_display();
1156-
signature_lax_der();
1157-
sign_and_verify();
1158-
sign_and_verify_extreme();
1159-
sign_and_verify_fail();
1160-
test_bad_slice();
1161-
test_low_s();
1162-
}
1163-
11641142
#[cfg(feature = "bitcoin_hashes")]
11651143
#[test]
11661144
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)