CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Testing and devnet”

48 lessons found. All lessons

Page 4 of 4

ckb-testtool runs scripts only, so node transaction verifiers must be added in testsWorkingFrom one fix

ckb-testtool's Context::verify_tx runs scripts only, so a test can pass with a transaction the node rejects. Build a Consensus from the bundled mainnet chain spec and run ckb-verification's NonContextualTransactionVerifier, CapacityVerifier and DaoScriptSizeVerifier, plus DaoCalculator::transaction_fee for DAO withdraw balance, and add your own checks for inputs below occupied capacity, a cell spent twice and a malformed since (time-dependent maturity can be skipped). Run these on rejected transactions too, so a rejection test fails only for the script rule it targets, or explicitly names the node rule it overlaps.

#Testing and devnet #Capacity and cell size · Sources (1) · 2026-11-02

get_transaction returns an object with a null transaction for rejected and unknown txsWorkingSeen again

The CKB node's get_transaction RPC does not return a null result for rejected or unknown hashes: it returns an object whose transaction field is null and whose tx_status.status is "rejected" (with tx_status.reason holding the rejection reason) or "unknown". Check res.transaction, not just res, before reading outputs, surface tx_status.reason to users, and make test mocks return this shape rather than result null.

Joined with toastmanAu/openswap@4dbe3232c3.

#Network and RPC reliability #Testing and devnet · Sources (2) · 2026-10-30

CCC custom client scripts must include AnyoneCanPay for SignerCkbPrivateKeyWorkingReproduced

On a devnet, if you construct a CCC client with a custom `scripts` map that overrides only `KnownScript.Secp256k1Blake160`, `SignerCkbPrivateKey` can still fail. This commit's comment says the signer also loads AnyoneCanPay metadata while classifying related locks, so it adds a `KnownScript.AnyoneCanPay` entry to the map even though no ACP input or cell dep is used.

#Cell deps and script lookup #Testing and devnet · Sources (1) · 2026-10-23

Headless EIP-6963 test wallet for driving the CCC connector in PlaywrightWorkingFrom one fix

To drive CCC's real EIP-6963 connector and EVM/Omnilock signing in headless Playwright, inject a minimal EIP-1193 provider with page.addInitScript passed as a string, because transpiled function sources carry helpers such as __name that the page lacks. The provider answers eth_requestAccounts, eth_accounts and personal_sign, stubs on and removeListener, and announces itself on eip6963:announceProvider, also whenever eip6963:requestProvider fires. Signing runs in Node through page.exposeFunction so the key never enters the page, and personal_sign must return r‖s‖v with v = 27 + recovery id; noble-curves 2.x sign with format "recovered" yields recovery‖r‖s, so reorder it with hexFrom(bytesConcat(recovered.slice(1, 65), [recovered[0] + 27])) and check it against ccc.verifyMessageEvmPersonal.

#Testing and devnet #Witnesses and signatures · Sources (1) · 2026-10-22

Keep other WitnessArgs fields when signing sighash_all in testsWorkingFrom one fix

When a test signer for the secp256k1 sighash_all lock fills the first witness of a script group, it should parse the existing WitnessArgs (for example one with data in output_type) and replace only the lock field: zeroed to 65 bytes while hashing, then set to the signature. Building a fresh WitnessArgs drops output_type or input_type data that a type script reads, and sighash_all hashes the whole first witness with only the lock zeroed, so those fields must already be in place when hashing.

#Witnesses and signatures #Testing and devnet · Sources (1) · 2026-10-20

Recognising a Nervos DAO deposit cell referenced as a stake cell depWorkingFrom one fix

A Nervos DAO deposit cell has the DAO type script (code hash 0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e, hash_type type, empty args) and 8 zero bytes of data; a withdrawing cell has the same type script but the deposit block number as data. A contract that accepts one as a cell dep must check code hash, hash_type, empty args and data == 8 zero bytes, since the DAO script does not run for a dep. For the same reason a ckb_testtool test can create such cells directly with the DAO type script and zero data, without deploying the DAO binary.

#Cell deps and script lookup #Testing and devnet · Sources (1) · 2026-10-20

Re-zero the witness lock before recomputing the sign message with getSignHashInfoWorkingReproduced

CCC's Transaction.getSignHashInfo hashes whatever is currently in the witness, so after a signature is filled in it no longer gives the signed message. To verify a signature (for example with ccc.recoverMessageSecp256k1), clone the tx and reset witness 0's lock to the zero placeholder of the same length that was used at signing time.

#Witnesses and signatures #Testing and devnet · Sources (1) · 2026-10-14

CKB node script debug logs may use ckb_script::verify target, not only ckb-scriptWorkingFrom one fix

When filtering a CKB node's run.log or log subscription for contract debug output (ckb_debug / debug! syscalls), records can come with target `ckb_script` or a `ckb_script::` submodule such as `ckb_script::verify` rather than the legacy `ckb-script` target. For those targets, match only messages containing `DEBUG OUTPUT:`, because the same target also emits ordinary verification lines.

#Testing and devnet · Sources (1) · 2026-10-08

Hand-rolled Script hash: hash_type byte mapping and molecule offsets, checked against CCCWorkingReproduced

If you serialise a CKB Script molecule yourself to compute its blake2b hash, use a 16 byte header (total size plus three u32 offsets 16, 48, 49) and map hash_type as data=0, type=1, data1=2, data2=4 (not 3). This commit cross checks the result against ccc.Script.from(...).hash() for all four hash types, and a single wrong offset or data2 mapped to 3 makes that test fail.

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

Pin JS cell data encoders and decoders to Rust generated vectorsWorkingFrom one fix

When JS code encodes or decodes CKB cell data or script args that an on chain Rust script parses, test it against vectors exported from the Rust crate's own encoder, not against the JS code's own expectations. Assert every decoded field and every encoded byte, because a length check cannot catch a shifted offset. Give each field a distinct non zero value so a one byte shift gives a visibly wrong result. Read u64 shannon fields as BigInt (DataView.getBigUint64) and reject data of the wrong length.

Joined with toastmanAu/daowow@e08898943c.

#Data encoding (molecule, hex, bigints) #Testing and devnet · Sources (2) · 2026-09-22

Never pass the terminal "0x" cursor back to indexer get_cellsWorkingFrom one fix

An exhausted indexer get_cells scan returns {objects: [], last_cursor: "0x"} (captured from a real node). The authors report that calling get_cells again with after = "0x" then returns nothing, even once matching cells exist, and a hand-written mock that never returned the real "0x" hid this for days. When paging, stop on an empty page before reading last_cursor, and never send or persist a "0x" cursor. Build paging tests from captured node responses, not hand-written mocks.

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

Emit shannon u64 values as strings in cross-language test vectorsWorkingFrom one fix

When generating JSON test vectors in Rust for JavaScript decoders of CKB cell data, emit u64 fields (such as shannon amounts) as strings, because JSON numbers are IEEE-754 doubles and values above 2^53 would be silently rounded. Use distinct, non-zero field values so a decoder reading the wrong offset gives a visibly wrong result.

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

Page 4 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.