Skip to content

expectRevert fails when returning a struct #2454

Closed
@k-g-j

Description

@k-g-j

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

33dbaa5 2022-07-23T00:08:24.676044Z

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

My team and I are having an issue where tests expect a revert with the onlyOwner modifier reason and the logs show the call reverting with the expected reason, but the test fails. If you remove the reason in the expectRevert the test fails, but with onlyOwner modifier reason. We debugged the test and found that the issue occurs when returning the metadata struct. If we just return the address of the deployed vault from the deployVaultV1 function, the test passes as it is written with the expected revert reason. When we also try to return the metadata in the function, the test fails and reverts without reason.

Failing Test Logs
1

function being tested from the factory contract

  function deployVaultV1(
    VaultParams memory _vaultParams,
    uint256 _type,
    bool _enabled,
    address _stakingAddress,
    address _submitter,
    string memory _metadataCID,
    address[8] memory _swapTokenAddresses,
    address _swapAddress,
    uint256 _exchange
  ) external onlyOwner returns (VaultMetadata memory, address) {
    Vault vault = new Vault(
      _vaultParams.token,
      _vaultParams.yearnRegistry,
      _vaultParams.contractRegistry,
      _vaultParams.staking,
      _vaultParams.feeStructure
    );
    VaultMetadata memory metadata = VaultMetadata({
      vaultAddress: address(vault),
      vaultType: _type,
      enabled: _enabled,
      stakingAddress: _stakingAddress,
      submitter: _submitter,
      metadataCID: _metadataCID,
      swapTokenAddresses: _swapTokenAddresses,
      swapAddress: _swapAddress,
      exchange: _exchange
    });
    emit VaultV1Deployment(address(vault));
    return (metadata, address(vault));
  }

expectRevert onlyOwner test (passes if deploy function modified to only return vault address, fails, and reverts without reason when the function is as written and returning the vault address and metadata struct)

  function test__deployVaultV1NotOwnerReverts() public {
    vm.expectRevert("Only the contract owner may perform this action");
    (VaultMetadata memory metadata, address vault) = vaultsV1Factory.deployVaultV1(
      vaultParams,
      1,
      true,
      address(0x1111),
      vaultsV1ControllerOwner,
      "someCID",
      swapTokenAddresses,
      address(0x2222),
      1
    );
    assertEq(vault, address(0), "vault deployment failed");
    assertEq(metadata.vaultAddress, address(0), "metadata not constructed");
  }

Factory contract
Factory test contract

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions