frangio / hardhat-exposed

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

Cannot rely on chained imports #19

Closed ItsNickBarry closed 1 year ago

ItsNickBarry commented 1 year ago

The SolidState library uses the convention of importing entities explicitly rather than entire files, in order to avoid polluting the global namespace:

import { ERC20BaseStorage } from './ERC20BaseStorage.sol';

This plugin doesn't account for that import style when generating code.

See these files:

  1. ECDSAMultisigWallet: https://github.com/solidstate-network/solidstate-solidity/blob/master/contracts/multisig/ECDSAMultisigWallet.sol
  2. ECDSAMultisigWalletInternal: https://github.com/solidstate-network/solidstate-solidity/blob/master/contracts/multisig/ECDSAMultisigWalletInternal.sol
  3. IECDSAMultisigWallet: https://github.com/solidstate-network/solidstate-solidity/blob/master/contracts/multisig/IECDSAMultisigWallet.sol
  4. IECDSAMultisigWalletInternal: https://github.com/solidstate-network/solidstate-solidity/blob/master/contracts/multisig/IECDSAMultisigWalletInternal.sol

File 1 inherits an internal function from file 2, which relies on a type defined in file 4. However, file 1 imports file 4 only indirectly, via file 3. This causes the generated "exposed" contract to fail compilation.

Can reproduce on the default branch of the SolidState repository.

frangio commented 1 year ago

I've published a partial fix for this issue that I believe should work for this particular example you brought up. But it will fail for a case with one more layer of indirection. Fixing that will require a bit more work.

ItsNickBarry commented 1 year ago

Thanks. That's probably sufficient for now. I believe the only case where I have that many orders of removal is that of the "Mock" contracts, but those would be replaced by this plugin anyway.

YamenMerhi commented 1 year ago

Experiencing the same issue, cannot find the import of EnumerableSet:

Screen Shot 2022-12-11 at 2 34 43 PM

frangio commented 1 year ago

Please try adding an explicit import for EnumerableSet as a workaround.

frangio commented 1 year ago

This should be fixed now in 0.3.11.