diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 7b1ff82b2..cc0ad02c6 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -42,9 +42,7 @@ jobs: run: cargo +${{ matrix.toolchain }} install wasmcov - name: Add rust-src component run: rustup component add rust-src --toolchain ${{ matrix.toolchain }} - - name: Build + - name: Run script env: - RUSTFLAGS: '-C link-arg=-s ' - run: cargo +${{ matrix.toolchain }} wasmcov build -- -Z build-std --all --target wasm32-unknown-unknown --release - - name: Test - run: cargo wasmcov test -- --all ${{ matrix.features }} \ No newline at end of file + RUSTFLAGS: '-C link-arg=-s' + run: bash ./build_wasm_test_all.sh \ No newline at end of file diff --git a/examples/adder/Cargo.toml b/examples/adder/Cargo.toml index adb000042..12cb6b145 100644 --- a/examples/adder/Cargo.toml +++ b/examples/adder/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-workspaces = "0.11.0" diff --git a/examples/adder/src/lib.rs b/examples/adder/src/lib.rs index 079bcca8c..425f8370a 100644 --- a/examples/adder/src/lib.rs +++ b/examples/adder/src/lib.rs @@ -89,3 +89,6 @@ mod tests { Ok(()) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); \ No newline at end of file diff --git a/examples/build_wasm_test_all.sh b/examples/build_wasm_test_all.sh new file mode 100644 index 000000000..c2a1cce7d --- /dev/null +++ b/examples/build_wasm_test_all.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +BASE_DIR="./examples" + +for dir in "$BASE_DIR"/*; do + if [ -d "$dir" ]; then + cd "$dir" || exit + + echo "Building $dir" + + cargo nightly-aarch64-apple-darwin wasmcov build -- -Z build-std --all --target wasm32-unknown-unknown --release + + echo "Testing $dir" + + cargo +nightly-2024-05-01 test -- --workspace + + echo "Generating report" + + cargo +nightly-2024-05-01 wasmcov report + + cd - || exit + fi +done diff --git a/examples/callback-results/Cargo.toml b/examples/callback-results/Cargo.toml index 4c7d53234..0e824c69b 100644 --- a/examples/callback-results/Cargo.toml +++ b/examples/callback-results/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-workspaces = "0.11.0" diff --git a/examples/callback-results/src/lib.rs b/examples/callback-results/src/lib.rs index 1faa13e46..be25d5abc 100644 --- a/examples/callback-results/src/lib.rs +++ b/examples/callback-results/src/lib.rs @@ -123,3 +123,6 @@ mod tests { Ok(()) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); \ No newline at end of file diff --git a/examples/cross-contract-calls/high-level/Cargo.toml b/examples/cross-contract-calls/high-level/Cargo.toml index 9db83ff40..2da8e1d85 100644 --- a/examples/cross-contract-calls/high-level/Cargo.toml +++ b/examples/cross-contract-calls/high-level/Cargo.toml @@ -9,3 +9,4 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" , features = ["default", "unit-testing"] } +wasmcov = "0.2" \ No newline at end of file diff --git a/examples/cross-contract-calls/high-level/src/lib.rs b/examples/cross-contract-calls/high-level/src/lib.rs index 3f20bf058..2e3933aa8 100644 --- a/examples/cross-contract-calls/high-level/src/lib.rs +++ b/examples/cross-contract-calls/high-level/src/lib.rs @@ -30,3 +30,6 @@ impl CrossContract { result } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/cross-contract-calls/low-level/Cargo.toml b/examples/cross-contract-calls/low-level/Cargo.toml index f2e635e31..b13416dd2 100644 --- a/examples/cross-contract-calls/low-level/Cargo.toml +++ b/examples/cross-contract-calls/low-level/Cargo.toml @@ -9,3 +9,4 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" , features = ["default", "unit-testing"] } +wasmcov = "0.2" \ No newline at end of file diff --git a/examples/cross-contract-calls/low-level/src/lib.rs b/examples/cross-contract-calls/low-level/src/lib.rs index 0a5e1533b..3d06b9452 100644 --- a/examples/cross-contract-calls/low-level/src/lib.rs +++ b/examples/cross-contract-calls/low-level/src/lib.rs @@ -50,3 +50,6 @@ impl CrossContract { env::value_return(&serde_json::to_vec(&(cur * n)).unwrap()); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/factory-contract/high-level/Cargo.toml b/examples/factory-contract/high-level/Cargo.toml index 3225e6ce5..481d9868f 100644 --- a/examples/factory-contract/high-level/Cargo.toml +++ b/examples/factory-contract/high-level/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } diff --git a/examples/factory-contract/high-level/src/lib.rs b/examples/factory-contract/high-level/src/lib.rs index 7b1167ff6..0524000ce 100644 --- a/examples/factory-contract/high-level/src/lib.rs +++ b/examples/factory-contract/high-level/src/lib.rs @@ -50,3 +50,6 @@ impl FactoryContract { } } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/factory-contract/low-level/Cargo.toml b/examples/factory-contract/low-level/Cargo.toml index 2807fb8c2..6c48f29ac 100644 --- a/examples/factory-contract/low-level/Cargo.toml +++ b/examples/factory-contract/low-level/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } diff --git a/examples/factory-contract/low-level/src/lib.rs b/examples/factory-contract/low-level/src/lib.rs index d2bda474e..05c1f53fe 100644 --- a/examples/factory-contract/low-level/src/lib.rs +++ b/examples/factory-contract/low-level/src/lib.rs @@ -72,3 +72,6 @@ impl FactoryContract { }; } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/fungible-token/ft/Cargo.toml b/examples/fungible-token/ft/Cargo.toml index 652900622..2a07ecd0e 100644 --- a/examples/fungible-token/ft/Cargo.toml +++ b/examples/fungible-token/ft/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } \ No newline at end of file diff --git a/examples/fungible-token/ft/src/lib.rs b/examples/fungible-token/ft/src/lib.rs index a6be56935..5415f3748 100644 --- a/examples/fungible-token/ft/src/lib.rs +++ b/examples/fungible-token/ft/src/lib.rs @@ -248,3 +248,6 @@ mod tests { assert_eq!(contract.ft_balance_of(accounts(1)).0, transfer_amount); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/fungible-token/test-contract-defi/Cargo.toml b/examples/fungible-token/test-contract-defi/Cargo.toml index cc314dba7..b9a5d90bc 100644 --- a/examples/fungible-token/test-contract-defi/Cargo.toml +++ b/examples/fungible-token/test-contract-defi/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } \ No newline at end of file diff --git a/examples/fungible-token/test-contract-defi/src/lib.rs b/examples/fungible-token/test-contract-defi/src/lib.rs index 83671a1e8..59d347fdc 100644 --- a/examples/fungible-token/test-contract-defi/src/lib.rs +++ b/examples/fungible-token/test-contract-defi/src/lib.rs @@ -69,3 +69,6 @@ impl ValueReturnTrait for DeFi { PromiseOrValue::Value(amount.into()) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/lockable-fungible-token/Cargo.toml b/examples/lockable-fungible-token/Cargo.toml index 3a20a2d0c..60fe8f5dd 100644 --- a/examples/lockable-fungible-token/Cargo.toml +++ b/examples/lockable-fungible-token/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk", features = ["legacy"] } +wasmcov = "0.2" [dev-dependencies] anyhow = "1.0" diff --git a/examples/lockable-fungible-token/src/lib.rs b/examples/lockable-fungible-token/src/lib.rs index 824858dcf..8f37be68b 100644 --- a/examples/lockable-fungible-token/src/lib.rs +++ b/examples/lockable-fungible-token/src/lib.rs @@ -480,3 +480,6 @@ mod tests { contract.lock(carol(), U128(lock_amount)).unwrap_err(); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/mission-control/Cargo.toml b/examples/mission-control/Cargo.toml index d4f9d29b4..f93c82802 100644 --- a/examples/mission-control/Cargo.toml +++ b/examples/mission-control/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } diff --git a/examples/mission-control/src/lib.rs b/examples/mission-control/src/lib.rs index 61522e7bc..cbf0092d5 100644 --- a/examples/mission-control/src/lib.rs +++ b/examples/mission-control/src/lib.rs @@ -5,3 +5,6 @@ mod asset; mod macros; mod mission_control; mod rate; + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/non-fungible-token/nft/Cargo.toml b/examples/non-fungible-token/nft/Cargo.toml index 672e5e113..72ac5d4b9 100644 --- a/examples/non-fungible-token/nft/Cargo.toml +++ b/examples/non-fungible-token/nft/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } \ No newline at end of file diff --git a/examples/non-fungible-token/nft/src/lib.rs b/examples/non-fungible-token/nft/src/lib.rs index 33c0ce5fe..8acd1841c 100644 --- a/examples/non-fungible-token/nft/src/lib.rs +++ b/examples/non-fungible-token/nft/src/lib.rs @@ -436,3 +436,6 @@ mod tests { assert!(!contract.nft_is_approved(token_id.clone(), accounts(1), Some(1))); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/non-fungible-token/test-approval-receiver/Cargo.toml b/examples/non-fungible-token/test-approval-receiver/Cargo.toml index 7f9036e07..1642d1dee 100644 --- a/examples/non-fungible-token/test-approval-receiver/Cargo.toml +++ b/examples/non-fungible-token/test-approval-receiver/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } diff --git a/examples/non-fungible-token/test-approval-receiver/src/lib.rs b/examples/non-fungible-token/test-approval-receiver/src/lib.rs index 975e798e8..57404dbda 100644 --- a/examples/non-fungible-token/test-approval-receiver/src/lib.rs +++ b/examples/non-fungible-token/test-approval-receiver/src/lib.rs @@ -75,3 +75,6 @@ impl ValueReturnTrait for ApprovalReceiver { PromiseOrValue::Value(msg) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/non-fungible-token/test-token-receiver/Cargo.toml b/examples/non-fungible-token/test-token-receiver/Cargo.toml index 2a4eeaadf..345f4e78a 100644 --- a/examples/non-fungible-token/test-token-receiver/Cargo.toml +++ b/examples/non-fungible-token/test-token-receiver/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../../near-sdk", features = ["unit-testing"] } \ No newline at end of file diff --git a/examples/non-fungible-token/test-token-receiver/src/lib.rs b/examples/non-fungible-token/test-token-receiver/src/lib.rs index ccedf9884..1a159d3b2 100644 --- a/examples/non-fungible-token/test-token-receiver/src/lib.rs +++ b/examples/non-fungible-token/test-token-receiver/src/lib.rs @@ -86,3 +86,6 @@ impl ValueReturnTrait for TokenReceiver { PromiseOrValue::Value(return_it) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/status-message/Cargo.toml b/examples/status-message/Cargo.toml index e72a5ba0e..aa1a2db0a 100644 --- a/examples/status-message/Cargo.toml +++ b/examples/status-message/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +wasmcov = "0.2" [dev-dependencies] near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } diff --git a/examples/status-message/src/lib.rs b/examples/status-message/src/lib.rs index 142c68598..1c8c90044 100644 --- a/examples/status-message/src/lib.rs +++ b/examples/status-message/src/lib.rs @@ -71,3 +71,6 @@ mod tests { assert_eq!(get_logs(), vec!["get_status for account_id francis.near"]) } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/test-contract/Cargo.toml b/examples/test-contract/Cargo.toml index 423588334..5a80f18a3 100644 --- a/examples/test-contract/Cargo.toml +++ b/examples/test-contract/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +wasmcov = "0.2" [profile.release] codegen-units = 1 diff --git a/examples/test-contract/src/lib.rs b/examples/test-contract/src/lib.rs index 46444f9fc..a0522c5d0 100644 --- a/examples/test-contract/src/lib.rs +++ b/examples/test-contract/src/lib.rs @@ -45,3 +45,6 @@ mod tests { contract.test_panic_macro(); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!(); diff --git a/examples/versioned/Cargo.toml b/examples/versioned/Cargo.toml index 3f07f872f..b573f26a9 100644 --- a/examples/versioned/Cargo.toml +++ b/examples/versioned/Cargo.toml @@ -9,6 +9,7 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk", features = ["unstable", "unit-testing"] } +wasmcov = "0.2" [profile.release] codegen-units = 1 diff --git a/examples/versioned/src/lib.rs b/examples/versioned/src/lib.rs index 6739de4d2..d1fa5baa8 100644 --- a/examples/versioned/src/lib.rs +++ b/examples/versioned/src/lib.rs @@ -144,3 +144,6 @@ mod tests { assert_eq!(contract.get_deposit(&bob()), Some(&NearToken::from_yoctonear(8))); } } + +#[cfg(target_family = "wasm")] +wasmcov::near::add_coverage!();