Skip to content

Commit

Permalink
creating script to run and build /examples with wasmcov
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmncos committed Aug 5, 2024
1 parent 82feaae commit 7d3f7f7
Show file tree
Hide file tree
Showing 34 changed files with 90 additions and 5 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
RUSTFLAGS: '-C link-arg=-s'
run: bash ./build_wasm_test_all.sh
1 change: 1 addition & 0 deletions examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk" }
wasmcov = "0.2"

[dev-dependencies]
near-workspaces = "0.11.0"
Expand Down
3 changes: 3 additions & 0 deletions examples/adder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ mod tests {
Ok(())
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
23 changes: 23 additions & 0 deletions examples/build_wasm_test_all.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/callback-results/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk" }
wasmcov = "0.2"

[dev-dependencies]
near-workspaces = "0.11.0"
Expand Down
3 changes: 3 additions & 0 deletions examples/callback-results/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ mod tests {
Ok(())
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/cross-contract-calls/high-level/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../../near-sdk" , features = ["default", "unit-testing"] }
wasmcov = "0.2"
3 changes: 3 additions & 0 deletions examples/cross-contract-calls/high-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ impl CrossContract {
result
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/cross-contract-calls/low-level/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../../near-sdk" , features = ["default", "unit-testing"] }
wasmcov = "0.2"
3 changes: 3 additions & 0 deletions examples/cross-contract-calls/low-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ impl CrossContract {
env::value_return(&serde_json::to_vec(&(cur * n)).unwrap());
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/factory-contract/high-level/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/factory-contract/high-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ impl FactoryContract {
}
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/factory-contract/low-level/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/factory-contract/low-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ impl FactoryContract {
};
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/fungible-token/ft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/fungible-token/ft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
1 change: 1 addition & 0 deletions examples/fungible-token/test-contract-defi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/fungible-token/test-contract-defi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ impl ValueReturnTrait for DeFi {
PromiseOrValue::Value(amount.into())
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/lockable-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk", features = ["legacy"] }
wasmcov = "0.2"

[dev-dependencies]
anyhow = "1.0"
Expand Down
3 changes: 3 additions & 0 deletions examples/lockable-fungible-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,6 @@ mod tests {
contract.lock(carol(), U128(lock_amount)).unwrap_err();
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/mission-control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 3 additions & 0 deletions examples/mission-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ mod asset;
mod macros;
mod mission_control;
mod rate;

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/non-fungible-token/nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/non-fungible-token/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/non-fungible-token/test-approval-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ impl ValueReturnTrait for ApprovalReceiver {
PromiseOrValue::Value(msg)
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/non-fungible-token/test-token-receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions examples/non-fungible-token/test-token-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ impl ValueReturnTrait for TokenReceiver {
PromiseOrValue::Value(return_it)
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/status-message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 3 additions & 0 deletions examples/status-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
1 change: 1 addition & 0 deletions examples/test-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk" }
wasmcov = "0.2"

[profile.release]
codegen-units = 1
Expand Down
3 changes: 3 additions & 0 deletions examples/test-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ mod tests {
contract.test_panic_macro();
}
}

#[cfg(target_family = "wasm")]
wasmcov::near::add_coverage!();
1 change: 1 addition & 0 deletions examples/versioned/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/versioned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();

0 comments on commit 7d3f7f7

Please sign in to comment.