From 17832229442ed2f90b41f92a15a2c3d4388c6ecb Mon Sep 17 00:00:00 2001 From: Hsin-Wen Chang Date: Fri, 12 Nov 2021 08:00:48 +0800 Subject: [PATCH] test: #72 Implement wasm-bindgen-test --- Cargo.lock | 141 ++++++++++++++++++++++++++++++++++++ consensus/Cargo.toml | 1 + consensus/src/checkpoint.rs | 7 +- 3 files changed, 146 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7757ebc14..64b9063c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,12 @@ dependencies = [ "sha2", ] +[[package]] +name = "bumpalo" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" + [[package]] name = "byteorder" version = "1.4.3" @@ -147,6 +153,16 @@ dependencies = [ "vec_map", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -329,6 +345,15 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +[[package]] +name = "js-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -341,6 +366,15 @@ version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + [[package]] name = "mina-consensus" version = "0.1.0" @@ -350,6 +384,7 @@ dependencies = [ "mina-rs-base", "serde-bin-prot", "thiserror", + "wasm-bindgen-test", ] [[package]] @@ -540,6 +575,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + [[package]] name = "serde" version = "1.0.130" @@ -797,6 +838,106 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasm-bindgen" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "web-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index bbadf9951..a7128f54f 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -10,3 +10,4 @@ mina-crypto = { version = "0.1.0", path = "../crypto" } mina-rs-base = { version = "0.1.0", path = "../base" } serde-bin-prot = { git = "https://github.com/ChainSafe/serde-bin-prot", branch = "main" } thiserror = "1.0.24" +wasm-bindgen-test = "0.3.0" \ No newline at end of file diff --git a/consensus/src/checkpoint.rs b/consensus/src/checkpoint.rs index ac67b212b..f977a64dc 100644 --- a/consensus/src/checkpoint.rs +++ b/consensus/src/checkpoint.rs @@ -4,7 +4,7 @@ use crate::common::{Common, ProtocolStateChain}; use mina_crypto::hash::{Hashable, StateHash}; use mina_rs_base::protocol_state::ProtocolState; - +use wasm_bindgen_test::*; const slots_per_epoch: u32 = 7140; /// init_checkpoints initializes the checkpoints for the genesis block @@ -60,7 +60,7 @@ mod tests { use mina_rs_base::global_slot::GlobalSlot; use mina_rs_base::numbers::{GlobalSlotNumber, Length}; - #[test] + #[wasm_bindgen_test] fn test_init_checkpoints() { let mut genesis: ProtocolState = Default::default(); let state_hash = genesis.hash(); @@ -95,6 +95,7 @@ mod tests { ); } + #[wasm_bindgen_test] fn test_update_checkpoints() { let mut genesis: ProtocolState = Default::default(); let state_hash = genesis.hash(); @@ -148,6 +149,6 @@ mod tests { ); } - #[test] + #[wasm_bindgen_test] fn test_is_short_range() {} }