huff-rs icon indicating copy to clipboard operation
huff-rs copied to clipboard

feat(huff_tests): Cheatcodes

Open clabby opened this issue 3 years ago • 2 comments

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. Screen Shot 2022-08-16 at 2 23 09 AM

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 // []
}

clabby avatar Aug 16 '22 07:08 clabby

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 ?

iFrostizz avatar Aug 16 '22 19:08 iFrostizz

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

refcell avatar Aug 17 '22 02:08 refcell