LiçõesO que a CKB aprendeu
Começa aqui · Glossário · Testa-te · Feed
As lições estão escritas em inglês, por isso pesquise em inglês.
“Testing and devnet” ✕
48 lições encontradas. Todas as lições
AnteriorPágina 4 de 4
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 · Fontes (1) · 2026-11-02
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 · Fontes (2) · 2026-10-30
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 · Fontes (1) · 2026-10-23
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 · Fontes (1) · 2026-10-22
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 · Fontes (1) · 2026-10-20
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 · Fontes (1) · 2026-10-20
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 · Fontes (1) · 2026-10-14
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 · Fontes (1) · 2026-10-08
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 · Fontes (1) · 2026-09-23
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 · Fontes (2) · 2026-09-22
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 · Fontes (1) · 2026-09-18
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) · Fontes (1) · 2026-09-18
AnteriorPágina 4 de 4
Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. JSON · Queres que uma lição seja mudada ou retirada? Abre um issue.