Skip to content

Commit

Permalink
test: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Mar 11, 2024
1 parent e7e1913 commit e8293fe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
30 changes: 30 additions & 0 deletions test/forge/BaseBundlerEnshrinedLocalTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {BaseBundler} from "src/mocks/bundlers/BaseBundlerMock.sol";

import "./helpers/LocalTest.sol";

contract BaseBundlerLocalEnshrinedTest is BaseBundler, LocalTest {
function checkInitiator(address expectedInitiator) public payable protected {
require(initiator() == expectedInitiator, "unexpected initiator");
}

function revertWith(string memory data) public payable protected {
revert(data);
}

function testMulticallShouldSetTheRightInitiator(address caller) public {
bundle.push(abi.encodeCall(this.checkInitiator, (caller)));

vm.prank(caller);
this.multicall(bundle);
}

function testMulticallShouldPassRevertData(string memory data) public {
bundle.push(abi.encodeCall(this.revertWith, (data)));

vm.expectRevert(bytes(data));
this.multicall(bundle);
}
}
24 changes: 0 additions & 24 deletions test/forge/BaseBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,3 @@ contract BaseBundlerLocalTest is LocalTest {
bundler.multicall(bundle);
}
}

contract BaseBundlerLocalEnshrinedTest is BaseBundler, LocalTest {
function checkInitiator(address expectedInitiator) public payable protected {
require(initiator() == expectedInitiator, "unexpected initiator");
}

function revertWith(string memory data) public payable protected {
revert(data);
}

function testMulticallShouldSetTheRightInitiator(address caller) public {
bundle.push(abi.encodeCall(this.checkInitiator, (caller)));

vm.prank(caller);
this.multicall(bundle);
}

function testMulticallShouldPassRevertData(string memory data) public {
bundle.push(abi.encodeCall(this.revertWith, (data)));

vm.expectRevert(bytes(data));
this.multicall(bundle);
}
}
16 changes: 13 additions & 3 deletions test/forge/SelectorClashTest.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import "../../src/interfaces/IWNative.sol";
import "../../lib/morpho-blue/src/interfaces/IMorpho.sol";
import "../../lib/universal-rewards-distributor/src/interfaces/IUniversalRewardsDistributor.sol";
import "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";
import "../../lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";
import "../../lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
import "../../lib/universal-rewards-distributor/src/interfaces/IUniversalRewardsDistributor.sol";

// The bundler can do call to arbitrary contracts, we make sure no selectors clash by inheriting all the interfaces in
// one single contract.
abstract contract SelectorClashTest is IMorpho, IUniversalRewardsDistributor, IERC4626, IERC20Permit, ERC20Wrapper {
abstract contract SelectorClashTest is
IMorpho,
IUniversalRewardsDistributor,
IERC4626,
IERC20Permit,
ERC20Wrapper,
IWNative
{
// Overrides of functions that are present in multiple interfaces contract ("acknowledged clashes").
function setOwner(address) public override(IMorphoBase, IUniversalRewardsDistributorBase) {}
function owner() public view override(IMorphoBase, IUniversalRewardsDistributorBase) returns (address) {}
function DOMAIN_SEPARATOR() public view override(IMorphoBase, IERC20Permit) returns (bytes32) {}
function approve(address, uint256) public view override(IWNative, IERC20, ERC20) returns (bool) {}
function transferFrom(address, address, uint256) public view override(IWNative, IERC20, ERC20) returns (bool) {}
}

// An example to be convinced that it is actually checking that there is no clash (to uncomment and try to compile).
Expand Down

0 comments on commit e8293fe

Please sign in to comment.