Skip to content

Commit f807502

Browse files
authored
Merge pull request #482 from OsejiFabian/feat/cargo-testutils-feature-flag
feat(contracts): add testutils Cargo feature flag
2 parents 66864ca + dadacda commit f807502

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

.github/workflows/contracts-ci.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,28 @@ jobs:
5858

5959
- name: Run contract tests
6060
working-directory: contracts
61-
run: cargo test
61+
run: cargo test --features testutils
6262

63-
- name: Build WASM release binary
63+
- name: Build WASM release binary (no testutils)
6464
working-directory: contracts
65-
run: cargo build --target wasm32-unknown-unknown --release
65+
run: cargo build --target wasm32-unknown-unknown --release --no-default-features
66+
67+
- name: Verify testutils excluded from release binary
68+
working-directory: contracts
69+
run: |
70+
WASM_FILE=$(find target/wasm32-unknown-unknown/release -name "*.wasm" | head -1)
71+
if [ -z "$WASM_FILE" ]; then
72+
echo "ERROR: No WASM file found." >&2
73+
exit 1
74+
fi
75+
# Confirm the strings "testutils" or "register_stellar_asset" do not
76+
# appear in the release binary (they would only be present if test
77+
# utilities were compiled in).
78+
if strings "$WASM_FILE" | grep -qE "testutils|register_stellar_asset"; then
79+
echo "ERROR: Release binary contains test utility symbols. Ensure testutils feature is excluded from release builds." >&2
80+
exit 1
81+
fi
82+
echo "✅ Release binary does not contain test utility symbols."
6683
6784
- name: Report WASM binary size
6885
working-directory: contracts

contracts/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ edition = "2021"
66
[lib]
77
crate-type = ["cdylib"]
88

9+
# Feature flags
10+
# ------------
11+
# `testutils` – enables soroban-sdk's test helpers (mock ledger, StellarAssetClient,
12+
# Address::generate, etc.). This feature MUST NOT be enabled for production/release
13+
# WASM builds; it is only activated during `cargo test` (via dev-dependencies) and
14+
# when explicitly requested with `--features testutils`.
15+
[features]
16+
testutils = ["soroban-sdk/testutils"]
17+
918
[dependencies]
1019
soroban-sdk = "21.0.0"
1120

contracts/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,5 +821,4 @@ fn read_campaign(env: &Env, campaign_id: u64) -> Campaign {
821821
.get(&DataKey::Campaign(campaign_id))
822822
.unwrap_or_else(|| panic!("campaign not found"))
823823
}
824-
#[cfg(test)]
825-
mod test;
824+

0 commit comments

Comments
 (0)