Separate mock/wrapper macros from methods
kadenzipfel opened this issue · comments
atm some of the contracts contain the mock logic used for testing directly in the contract. this decreases readability and we should instead use a consistent pattern for separating the mocks from the actual methods. the pattern used here is imo ideal: https://github.com/pentagonxyz/huff-lib/blob/main/src/data-structures/mocks/InstantiatedHashmap.huff
Maybe the best way around this would be to introduce a with_code
function on HuffDeployer that adds a huff code string to the source file and returns an instance of HuffDeployer that you can chain like:
let hmap = HashMap(
HuffDeployer.with_code("
#define macro MAIN() = takes(0) returns(0) {
...
}
").deploy("data-structures/Hashmap.huff")
);
TBH, we should refactor the deploy_with_args
function to also allow chaining like this with a with_args
function:
let hmap = HashMap(
HuffDeployer.with_code("
#define macro MAIN() = takes(0) returns(0) {
...
}
")
.with_args(bytes.concat(abi.encode(address(0))))
.deploy("data-structures/Hashmap.huff")
);
If others think this is a good pattern, can split out into another issue cc @clabby @JetJadeja
Maybe the best way around this would be to introduce a
with_code
function on HuffDeployer that adds a huff code string to the source file and returns an instance of HuffDeployer that you can chain like:let hmap = HashMap( HuffDeployer.with_code(" #define macro MAIN() = takes(0) returns(0) { ... } ").deploy("data-structures/Hashmap.huff") );
TBH, we should refactor the
deploy_with_args
function to also allow chaining like this with awith_args
function:let hmap = HashMap( HuffDeployer.with_code(" #define macro MAIN() = takes(0) returns(0) { ... } ") .with_args(bytes.concat(abi.encode(address(0)))) .deploy("data-structures/Hashmap.huff") );
If others think this is a good pattern, can split out into another issue cc @clabby @JetJadeja
I do like this pattern- for it personally if y'all want to add it 😄
With the newest features in foundry x huff, this should be straight-forward to implement.
Done