frangio / hardhat-exposed

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

Error when converting `storage` struct return values to `memory` #20

Closed ItsNickBarry closed 1 year ago

ItsNickBarry commented 1 year ago

Given this contract:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { EnumerableSet } from '../../utils/EnumerableSet.sol';

library AccessControlStorage {
    struct RoleData {
        EnumerableSet.AddressSet members;
        bytes32 adminRole;
    }

    struct Layout {
        mapping(bytes32 => RoleData) roles;
    }

    bytes32 internal constant DEFAULT_ADMIN_ROLE = 0x00;

    bytes32 internal constant STORAGE_SLOT =
        keccak256('solidstate.contracts.storage.AccessControl');

    function layout() internal pure returns (Layout storage l) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            l.slot := slot
        }
    }
}

The generated code yields this error on compilation:

TypeError: Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
  --> contracts-exposed/access/access_control/AccessControlStorage.sol:21:47:
   |
21 |     function $layout() external pure returns (AccessControlStorage.Layout memory) {
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error HH600: Compilation failed

This is of course due to fundamental limitations of storage types, and I don't intend to test the layout function. Would it be possible to simply skip functions that return storage types?

frangio commented 1 year ago

Fixed in 0.2.13. (https://github.com/frangio/hardhat-exposed/commit/f4b0aedbe1b6f633a086a52a062d83c42f330d3f)