frangio / hardhat-exposed

Automatically expose internal Solidity functions for smart contract testing.
82 stars 13 forks source link

Generate array of structs for library functions with storage pointer arguments #4

Closed frangio closed 2 years ago

frangio commented 2 years ago

If a library has functions with storage pointer arguments, we currently try to convert those to memory pointers, but that doesn't work well, for example mapping fields in a struct don't make sense in memory.

For every storage pointer to a type struct S we should generate a storage variable of type S[], and for each function that takes a storage pointer to S we should generate the exposed version with a number that will be used to index the array.

PaulRBerg commented 2 years ago

I just bumped into this problem after trying to use hardhat-exposed in my code base:

TypeError: Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
  --> contracts-exposed/core/balance-sheet/BalanceSheetV2.sol:10:59:
   |
10 |     function $vaults(address arg0) external view returns (SBalanceSheetV1.Vault memory) {

Thing is, I don't even need to expose this contract (BalanceSheetV2). So here's a feature request for you:

Let hardhat-exposed accept a list of contract names that are due to be excluded from being exposed. This list of contracts should be configurable in the Hardhat config file.

Side note: I thought that this might deserve its own separate GitHub issue - but @frangio I'll let you decide if you want to keep the convo going in this issue or not.

frangio commented 2 years ago

@paulrberg I had been thinking about that feature as well. I've published a new version with the ability to exclude files. Check it out:

https://github.com/frangio/hardhat-exposed/blob/6fecbe8385fa63b7dccd713c4d7405b3f3ec6f2f/hardhat.config.ts#L11

PaulRBerg commented 2 years ago

Haha so quick! Thanks.

whhsw commented 2 years ago

I am having the same issue. Though in my case, I still need the the file for testing. It's an internal data type that contains mapping struct, which can be storage only.
eg. MyStruct internal s; I am adding a local fix to exclude bunch of function name.

frangio commented 2 years ago

Forgot to close this but this feature was implemented in https://github.com/frangio/hardhat-exposed/commit/75673ee2d112a8238d54e5335832f417d70fba01.

@whhsw Can you open another issue about your problem? I'm not sure I understand.