huff-rs
huff-rs copied to clipboard
feat(huff_tests): Cheatcodes
Overview
Adds a new inspector to the test runner to detect calls to a cheatcode address. Cheatcodes can be invoked by sending a staticcall to 0x00000000000000000000000000000000bEefbabe with the following calldata layout:
╔═════════╦═══════════════╗
║ Offset ║ Value ║
╠═════════╬═══════════════╣
║ 0x00 ║ cheatcode_key ║
║ 0x20 ║ current_pc ║
║ 0x40... ║ args ║
╚═════════╩═══════════════╝
The first cheatcode is LOG, which allows logging stack items within Huff tests.

Will need to add a Huff tests cheatcode contract to Huffmate tomorrow:
#define macro LOG() = takes (1) {
// Input stack: [log_item]
pc // [pc, log_item]
0x01 // [log_cheatcode, pc, log_item]
0x00 mstore // [pc, log_item]
0x20 mstore // [log_item]
0x40 mstore // []
0x00 dup1 // [0x00, 0x00]
0x60 dup2 // [0x00, 0x60, 0x00, 0x00]
0x00000000000000000000000000000000bEefbabe
gas // [gas, beef_babe, 0x00, 0x60, 0x00, 0x00]
staticcall pop // []
}
That's amazing, I'm wondering if there shouldn't be a separate huff testing framework before testing gets too big, unless you wanna keep it lightweight! Are you counting gas for cheatcodes ?
That's amazing, I'm wondering if there shouldn't be a separate huff testing framework before testing gets too big, unless you wanna keep it lightweight! Are you counting gas for cheatcodes ?
Not a bad point - I think it might make sense to actually put all testing behind a testing feature flag maybe? wdyt @clabby