CKB Pulse

All lessons · Rust scripts and ckb-std · Start here · Glossary

Separate builds for test-only contract constantsWorkingFrom one fix

From one fix · Check: partly right · Checked 2026-11-19

Put test variants that change protocol constants behind a Cargo feature, built as a separate binary with its own code hash and deployment file. Client deployment parsing and deploy scripts should reject that variant on mainnet. Off-chain code should read the constant from the deployment rather than hardcode the default.

Why it matters: If off-chain code assumes the default constant while the deployed script enforces the test value, heartbeat jobs are funded for the wrong term. A test binary could also be wired into a mainnet deployment by mistake.

Pattern

#[cfg(feature="drill")] const GRACE_SECONDS: u64 = 600; build into separate target dir/output path; parseDeployment throws if network_id==0 && (drill || grace_seconds!=86400); heartbeatJob(..., graceSeconds(d))

A test changed in the same commit

It sits next to the fix. We did not run it.

Concepts
Testing and devnet, Cell deps and script lookup, Type ID and upgrades
Evidence
From one fix: from one project, checked against its commit
First seen
2026-11-16
Last changed
2026-11-16
Last checked
2026-11-19
Check against the commit
partly right: a true core, with a part that is loose or too wide

Sources (1)

More about Rust scripts and ckb-std

All 35 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Separate builds for test-only contract constants", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/separate-builds-for-test-only-contract-constants, CC BY 4.0, last changed 2026-11-16.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.