Todas as lições · Developer tooling · Começa aqui · Glossário
Pin JS cell data encoders and decoders to Rust generated vectorsPráticoDe uma correção
De uma correção · Verificação: certa · Verificada em 2026-11-19
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.
Porque importa: A JS codec checked only against its own expectations or a size check can read or write a neighbouring offset and still produce a plausible number of the right length, so the browser builds or reports cells the on chain script reads differently, and Number would silently round shannon amounts above 2^53.
Joined with toastmanAu/daowow@e08898943c.
Padrão
assert.strictEqual(got.minimumTickets, BigInt(f.minimum_tickets), "minimumTickets");Tirado do commit, encurtado.
Um teste mudou no mesmo commit
Está ao lado da correcção. Nós não o corremos.
- toastmanAu/daowow:
apps/web/test/codec.test.js - toastmanAu/daowow:
apps/web/test/entry-codec.test.js,crates/daowow-core/tests/gen_vectors.rs
- Conceitos
- Data encoding (molecule, hex, bigints), Testing and devnet
- Evidência
- De uma correção: de um projeto, verificada contra o commit
- Vista pela primeira vez
- 2026-09-18
- Última mudança
- 2026-09-22
- Última verificação
- 2026-11-19
- Verificação contra o commit
- certa: a lição sai do commit e continua a valer no código de hoje
Fontes (2)
- 2026-09-18 · toastmanAu/daowow · mais deste projeto
- 2026-09-22 · toastmanAu/daowow · mais deste projeto
Mais sobre 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
- Mirror on-chain rules off-chain with mutation tests
Manténs um projeto de onde esta lição veio? Confirma ou corrige
Citar esta lição
LusoCryptoLabs, "Pin JS cell data encoders and decoders to Rust generated vectors", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/pin-js-cell-data-encoders-and-decoders-to-rust-generated-vec, CC BY 4.0, last changed 2026-09-22.