refactor(basics): replace hand-rolled byte packing with kit codecs - #677
refactor(basics): replace hand-rolled byte packing with kit codecs#677amilz wants to merge 1 commit into
Conversation
Greptile SummaryThis PR replaces manual TypeScript byte packing and account decoding in the basics examples with
Confidence Score: 4/5The code refactor is behaviorally sound, but the pull request must not merge until its commit is signed and verifiably attributed. The examined codec layouts match their on-chain instruction and account formats, while the head commit lacks the verified signature required by the repository owner. Files Needing Attention: Pull request commit metadata; no source file requires a behavioral correction. Important Files Changed
|
What changed
Replaced hand-rolled instruction/account byte packing in the
basics/TypeScript tests with@solana/kitcodecs, matching the pattern already used bytokens/transfer-tokens/pinocchio/tests/test.ts.Out goes
Buffer.alloc+writeUInt8/writeUInt32LE/writeBigUInt64LE,Buffer.concat,DataView.setBigUint64, and manual fixed-width string padding/trimming. In comegetStructEncoder/getStructDecodercomposed fromgetU8,getU32,getU64,getArray, andfixEncoderSize/fixDecoderSizeovergetUtf8.Where a test read its own program's account data by byte offset, it now decodes through a
getStructDecoderthat mirrors the on-chain layout (favorites,realloc,account-data,program-derived-addresses,close-account).basics/counter/nativeadditionally drops thebn.js/@types/bn.jsdependencies —deserializeCounterAccountnow returns a nativebigintviagetU64Decoder(), andtests/counter.test.tscompares againstbigintliterals. Lockfile regenerated.Files
basics/transfer-sol/pinocchio/tests/test.tsbasics/transfer-sol/asm/tests/instruction.tsbasics/pda-rent-payer/pinocchio/tests/test.tsbasics/program-derived-addresses/pinocchio/tests/test.tsbasics/processing-instructions/pinocchio/tests/test.tsbasics/favorites/pinocchio/tests/test.tsbasics/realloc/pinocchio/tests/realloc.test.tsbasics/account-data/pinocchio/tests/index.test.tsbasics/close-account/pinocchio/tests/close-account.test.tsbasics/counter/native/ts/accounts/counter.tsbasics/counter/native/tests/counter.test.tsbasics/counter/native/package.json+pnpm-lock.yamlTest evidence
npx tsc --noEmitclean in every touched package, andpnpm build-and-test(cargo build-sbf+ mocha) green:basics/transfer-sol/pinocchiobasics/pda-rent-payer/pinocchiobasics/program-derived-addresses/pinocchiobasics/processing-instructions/pinocchiobasics/favorites/pinocchiobasics/realloc/pinocchiobasics/account-data/pinocchiobasics/close-account/pinocchiobasics/counter/nativebasics/transfer-sol/asmbasics/transfer-sol/asmbuilds withsbpf, which is not available in this environment (cargo install sbpffails to compile), so its suite could not be executed. The change there is a one-line swap ofnew DataView(...).setBigUint64(0, lamports, true)forgetU64Encoder().encode(lamports)— byte-identical little-endian u64 — and it typechecks clean.prettier --checkpasses on all touched files.Part of DEV-838