huff-language / huffmate

A library of modern, hyper-optimized, and extensible Huff contracts with extensive testing and documentation built by Huff maintainers.

Home Page:https://github.com/pentagonxyz/huffmate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Separate mock/wrapper macros from methods

kadenzipfel opened this issue · comments

commented

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 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

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