bugc: Add behavioral test helper for end-to-end bytecode validation#183
bugc: Add behavioral test helper for end-to-end bytecode validation#183
Conversation
Add executeProgram() helper that compiles BUG source, deploys bytecode via @ethdebug/evm Executor, optionally calls with calldata, and returns results for direct assertion on storage and execution state — no pointer dereferencing needed. Tests cover: constructor storage init, runtime storage modification, multiple calls, for loops, conditionals, bare return (STOP), and compilation failure. Internal function calls are skipped (known stack underflow issue).
Self-reviewDesign decisions:
Known limitation discovered:
Test patterns established:
|
gnidan
left a comment
There was a problem hiding this comment.
Style review — overall this is clean and well-structured. A few notes:
Source string indentation: The existing tests in this package (e.g., integration.test.ts) use flush-left source strings inside template literals:
const source = `name Minimal;
storage {
[0] value: uint256;
}
code {
value = 1;
}`;The new file indents every source string by 8 spaces inside the test body. Not a hard rule, but matching the existing convention keeps things consistent. (The skipped test also has 10-space indentation instead of 8 — inconsistent within the file itself.)
JSDoc on the helper: The file-level docblock and per-function docblocks (/** Compile BUG source, deploy... */) are heavier than the rest of the codebase for test helpers. The function signature executeProgram(source, options) is self-documenting. The interface field comments (/** Whether deployment succeeded */) are similarly obvious from the field names. Consider trimming to just the file-level comment or removing entirely.
readUint256 is exported but unused — none of the tests use it. If it's anticipatory, that's fine for a test helper, but worth noting.
Looks good otherwise: functional style (no class), clean interfaces, good test coverage across behavioral categories, double quotes, appropriate use of @ethdebug/evm Executor.
Copy returnValue via `new Uint8Array()` to avoid Uint8Array<ArrayBufferLike> vs Uint8Array<ArrayBuffer> mismatch in TS 5.7+ strict mode.
|
Summary
Adds a lightweight
executeProgram(source, opts)test helper that compiles BUG source, deploys bytecode via@ethdebug/evmExecutor, optionally calls with calldata, and returns execution results for direct assertion — no pointer dereferencing needed.This decouples bytecode correctness testing from debug info correctness, making it easy to write focused behavioral tests.
Helper (
test/evm/behavioral.ts):executeProgram(source, { calldata?, value?, optimizationLevel? })→{ deployed, callSuccess, returnValue, getStorage(), executor }readUint256(returnValue, wordOffset)for parsing return dataTests (
src/evmgen/behavioral.test.ts) — 8 passing, 1 skipped: