CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Testing and devnet”

48 lessons found. All lessons

Page 2 of 4

Indexer RPC module must be listed in ckb.toml rpc modules for get_cells on devnetWorkingFrom one fix

CKB serves get_cells, get_indexer_tip and the other indexer RPC methods only when "Indexer" is listed in the [rpc] modules array of ckb.toml. The ckb.toml generated in the nervos/ckb 0.209.0 devnet image used here leaves Indexer out, so add it before relying on cell collection against a devnet node. Then confirm with a real indexer call such as get_cells after the node starts.

#Indexer queries and cell collection #Testing and devnet · Sources (1) · 2026-09-18

ckb-vm-js 0.2.0 (npm) checks header hash instead of rejecting the fieldWorkingChecked by the owner

With ckb-vm-js 0.2.0 from npm, verifyScriptGroup accepts an RPC header in context.tip_header that carries its own hash only when that hash matches the recomputed one, and fails with "header hash does not match" otherwise (the earlier vendored build rejected any `hash` field as unknown). Dropping `hash` before passing RPC headers or transactions remains safe because the verifier recomputes it.

No existing lesson covers how ckb-vm-js treats a hash field on RPC headers.

#Testing and devnet #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-17

Pass wasm bytes to ckb-vm-js createVerifier in NodeWorkingChecked by the owner

In Node, calling ckb-vm-js createVerifier() with no arguments fails with "fetch failed" because it cannot fetch its .wasm from a file URL. Read the bytes from the package's ckb-vm-js/wasm export (via import.meta.resolve and readFile) and pass them as createVerifier({ wasm }).

New Node loading detail for ckb-vm-js wasm.

#Testing and devnet · Sources (1) · 2026-11-17

Separate builds for test-only contract constantsWorkingFrom one fix

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.

#Testing and devnet #Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-11-16

Mock syscalls must write back output lengthAdvancedFrom one fix

When a ckb-vm mock or fuzzing syscall layer implements inherited_fds, it must store the fd count back into length_addr with store64 after writing the fd buffer. Otherwise the script reads back the capacity it passed in and treats unwritten slots as fds. ckb-vm-contrib's fuzzing utils lacked this until v1.1.2.

#Testing and devnet · Sources (1) · 2026-11-16

Profile spawned scripts with the right ELF symbolsWorkingFrom one fix

In ckb-debugger full mode with spawn, coverage, flamegraph and overlap analysis now use the ELF of the VM chosen with --vm-id instead of the root program. Pass an unstripped binary with --vm-symbols to get symbols and debug info.

Older ckb-debugger versions profile spawned children with the root program's symbols, so their profiles are wrong.

#Testing and devnet · Sources (1) · 2026-11-16

Median time vs tip timestamp for deadlinesWorkingSeen again

On-chain since checks use the median time of past blocks, but clients often use the tip header's timestamp, and the two can diverge widely after devnet time travel. Compute deadlines from max(ceil(tipMs/1000), medianSeconds) so minimum-term checks hold on both sides.

#Since and time locks #Testing and devnet · Sources (3) · 2026-11-15

Molecule hash_type byte valuesWorkingFrom one fix

In the molecule Script encoding, hash_type is data=0, type=1, data1=2, data2=4; 3 is not a valid value. Using 2 where you meant data2 builds a valid data1 script with a different hash, so indexer queries on it return nothing. Assert the raw byte inside the encoded Script, or run against a real devnet, because mocks that reuse the same constant on both sides cannot catch it.

#Data encoding (molecule, hex, bigints) #Indexer queries and cell collection #Testing and devnet · Sources (1) · 2026-11-15

ckb-debugger verifies one script group per runWorkingFrom one fix

`full` is a VM mode, and by default ckb-debugger runs only input 0's lock, which may be an always-success lock. To check a whole transaction, enumerate every input lock, input type and output type group, run each with --script-group-type/--cell-type/--cell-index, and sum the cycles. Pair each accepted case with a control that must fail with an exact error code.

#Testing and devnet #Transaction building and fees · Sources (1) · 2026-11-14

Mock transactions must expand dep_group membersWorkingFrom one fix

In a ckb-debugger mock_info, list the dep_group cell with dep_type "dep_group" (data included) and also list each member out point as a separate cell dep with dep_type "code", with its data. Get the members by decoding the group cell's data as a molecule OutPoint vector: a u32 LE count, then per entry a 32-byte tx hash and a u32 LE index (36 bytes each), and check that the length is 4 + 36*count bytes.

#Testing and devnet #Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-14

Port CKB's sparse-merkle-tree byte for byteAdvancedFrom one fix

nervosnetwork/sparse-merkle-tree folds runs of empty siblings into MergeWithZero nodes (merge byte 2; a normal merge uses byte 1 plus height and parent path), and bit 0 of a key is the low bit of byte 0. Compiled proofs use the opcodes 0x4c, 0x50, 0x51, 0x4f n (n=0 means 256) and 0x48. Test any off-chain port against vectors generated by the Rust code.

#Data encoding (molecule, hex, bigints) #Testing and devnet · Sources (1) · 2026-11-14

Pinning JS codecs and derivations to Rust test vectorsWorkingFrom one fix

When off-chain JS encodes or derives cell data that a Rust type script decodes or re-derives byte for byte, test the JS against JSON vectors generated by the Rust code, using a distinct value in every field so a wrong offset fails. Mirror the contract's validation refusals and its exact ordering and rounding: BTreeMap ascending key order, BigInt floor division with the dust going to fixed indices, and merging duplicates before dividing. The chain only returns a bare error code, so only this off-chain check can tell you which rule failed.

#Data encoding (molecule, hex, bigints) #Testing and devnet #Transaction building and fees · Sources (2) · 2026-11-13

Page 2 of 4

Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. JSON · Want a lesson changed or removed? Open an issue.