CKB Pulse

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.

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)

More about Developer tooling

All 35 in this topic

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.

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.