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.
This commit is contained in:
Thomas Eizinger 2020-12-22 10:27:55 +11:00
parent 3151352be6
commit 8b8e482f79
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
5 changed files with 17 additions and 27 deletions

View File

@ -168,6 +168,9 @@ mod tests {
use super::SharedSecret; use super::SharedSecret;
use super::super::Secp256k1; use super::super::Secp256k1;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test] #[test]
fn ecdh() { fn ecdh() {
let s = Secp256k1::signing_only(); let s = Secp256k1::signing_only();

View File

@ -429,6 +429,9 @@ mod test {
use std::iter; use std::iter;
use std::str::FromStr; use std::str::FromStr;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
macro_rules! hex { macro_rules! hex {
($hex:expr) => ({ ($hex:expr) => ({
let mut result = vec![0; $hex.len() / 2]; let mut result = vec![0; $hex.len() / 2];

View File

@ -133,6 +133,7 @@ pub use secp256k1_sys as ffi;
#[cfg(all(test, feature = "serde"))] extern crate serde_test; #[cfg(all(test, feature = "serde"))] extern crate serde_test;
#[cfg(any(test, feature = "rand"))] use rand::Rng; #[cfg(any(test, feature = "rand"))] use rand::Rng;
#[cfg(any(test, feature = "std"))] extern crate core; #[cfg(any(test, feature = "std"))] extern crate core;
#[cfg(all(test, target_arch = "wasm32"))] extern crate wasm_bindgen_test;
use core::{fmt, ptr, str}; use core::{fmt, ptr, str};
@ -770,6 +771,9 @@ mod tests {
use ffi::{self, types::AlignedType}; use ffi::{self, types::AlignedType};
use context::*; use context::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
macro_rules! hex { macro_rules! hex {
($hex:expr) => ({ ($hex:expr) => ({
let mut result = vec![0; $hex.len() / 2]; let mut result = vec![0; $hex.len() / 2];
@ -831,6 +835,7 @@ mod tests {
drop(ctx_full);drop(ctx_sign);drop(ctx_vrfy); drop(ctx_full);drop(ctx_sign);drop(ctx_vrfy);
} }
#[cfg(not(target_arch = "wasm32"))]
#[test] #[test]
#[should_panic] #[should_panic]
fn test_panic_raw_ctx() { fn test_panic_raw_ctx() {
@ -1125,33 +1130,6 @@ mod tests {
assert!(SECP256K1.verify(&msg, &sig, &pk).is_ok()); assert!(SECP256K1.verify(&msg, &sig, &pk).is_ok());
} }
// For WASM, just run through our general tests in this file all at once.
#[cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test;
#[cfg(target_arch = "wasm32")]
use self::wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_test]
fn stuff() {
test_manual_create_destroy();
test_raw_ctx();
// Note that, sadly, WASM doesn't currently properly unwind panics, so use of the library
// via unsafe primitives may cause abort() instead of catch-able panics.
/*assert!(std::panic::catch_unwind(|| {
test_panic_raw_ctx();
}).is_err());*/
test_preallocation();
capabilities();
signature_serialize_roundtrip();
signature_display();
signature_lax_der();
sign_and_verify();
sign_and_verify_extreme();
sign_and_verify_fail();
test_bad_slice();
test_low_s();
}
#[cfg(feature = "bitcoin_hashes")] #[cfg(feature = "bitcoin_hashes")]
#[test] #[test]
fn test_from_hash() { fn test_from_hash() {

View File

@ -199,6 +199,9 @@ mod tests {
use super::super::{Secp256k1, Message}; use super::super::{Secp256k1, Message};
use super::super::Error::{IncorrectSignature, InvalidSignature}; use super::super::Error::{IncorrectSignature, InvalidSignature};
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[test] #[test]
fn capabilities() { fn capabilities() {
let sign = Secp256k1::signing_only(); let sign = Secp256k1::signing_only();

View File

@ -500,6 +500,9 @@ mod tests {
use std::iter; use std::iter;
use std::str::FromStr; use std::str::FromStr;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
macro_rules! hex_32 { macro_rules! hex_32 {
($hex:expr) => {{ ($hex:expr) => {{
let mut result = [0; 32]; let mut result = [0; 32];