All lessons · Developer tooling · Start here · Glossary
Mirror on-chain rules off-chain with mutation testsWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
A CKB script that refuses a transaction returns only an error code that names no rule, so port the contract's witness decoders to JS with the same refusals (bad version, truncation, trailing bytes, count or size limits). Check that they round-trip bytes produced by the Rust code. Before signing, run a checker that re-derives the contract's rules from the finished transaction, and pin each rule with a mutation test that breaks one field of a valid transaction and expects that rule's named reason.
Why it matters: Without an off-chain mirror, a malformed witness or broken rule only shows up as an opaque script error code at submission, with no indication of which rule failed.
Pattern
decode(bytes) throws on cut-short / trailing bytes / bad version like the Rust decoder; tests do `breakIt(clone(tx)); assert reasons.some(r => /expected/.test(r))`A test changed in the same commit
It sits next to the fix. We did not run it.
- toastmanAu/daowow:
apps/web/test/entitlements.test.js,apps/web/test/payout-tx.test.js,apps/web/test/settlement-rules.test.js,tests/devnet/js_settlement.mjs,tests/devnet/js_settlement.py
- Concepts
- Testing and devnet, Data encoding (molecule, hex, bigints), Since and time locks
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-13
- Last changed
- 2026-11-13
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (1)
- 2026-11-13 · toastmanAu/daowow · more from this project
More about Developer tooling
- ckb-vm-js 0.2.0 (npm) checks header hash instead of rejecting the field
- Emit shannon u64 values as strings in cross-language test vectors
- Mock transactions must expand dep_group members
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Mirror on-chain rules off-chain with mutation tests", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/mirror-on-chain-rules-off-chain-with-mutation-tests, CC BY 4.0, last changed 2026-11-13.