Skip to content

Commit

Permalink
feat: refactor dutch reactor tests
Browse files Browse the repository at this point in the history
- Move common tests into a base test contract
- inherit it from Dutch and ExclusiveDutch (dutchv2 coming later)
- clean up test logic, use helpers and solarray
  • Loading branch information
marktoda committed Dec 19, 2023
1 parent 855b495 commit 99090c6
Show file tree
Hide file tree
Showing 8 changed files with 500 additions and 405 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/permit2"]
path = lib/permit2
url = https://github.com/Uniswap/permit2
[submodule "lib/solarray"]
path = lib/solarray
url = https://github.com/evmcheb/solarray
1 change: 1 addition & 0 deletions lib/solarray
Submodule solarray added at 0625e7
5 changes: 1 addition & 4 deletions src/reactors/ExclusiveDutchOrderReactor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ contract ExclusiveDutchOrderReactor is BaseReactor {
/// @notice thrown when an order's deadline is before its end time
error DeadlineBeforeEndTime();

/// @notice thrown when an order's end time is before its start time
error OrderEndTimeBeforeStartTime();

/// @notice thrown when an order's inputs and outputs both decay
error InputAndOutputDecay();

Expand Down Expand Up @@ -72,7 +69,7 @@ contract ExclusiveDutchOrderReactor is BaseReactor {
}

if (order.decayEndTime < order.decayStartTime) {
revert OrderEndTimeBeforeStartTime();
revert DutchDecayLib.EndTimeBeforeStartTime();
}

if (order.input.startAmount != order.input.endAmount) {
Expand Down
38 changes: 20 additions & 18 deletions test/base/BaseReactor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Test of a simple execute
function testBaseExecute() public {
function test_base_execute() public {
uint256 inputAmount = 1 ether;
uint256 outputAmount = 1 ether;
uint256 deadline = block.timestamp + 1000;
Expand Down Expand Up @@ -128,7 +128,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic execute test with protocol fee, checks balance before and after
function testBaseExecuteWithFee() public {
function test_base_executeWithFee() public {
uint256 inputAmount = 1 ether;
uint256 outputAmount = 1 ether;
uint256 deadline = block.timestamp + 1000;
Expand Down Expand Up @@ -175,7 +175,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic execute test for native currency, checks balance before and after
function testBaseExecuteNativeOutput() public {
function test_base_executeNativeOutput() public {
uint256 inputAmount = 1 ether;
uint256 outputAmount = 1 ether;
uint256 deadline = block.timestamp + 1000;
Expand Down Expand Up @@ -213,7 +213,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Execute test with a succeeding validation contract
function testBaseExecuteValidationContract() public {
function test_base_executeValidationContract() public {
uint256 inputAmount = 1 ether;
uint256 outputAmount = 1 ether;
uint256 deadline = block.timestamp + 1000;
Expand Down Expand Up @@ -258,7 +258,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer

/// @dev Basic batch execute test
// Two orders: (inputs = 1, outputs = 2), (inputs = 2, outputs = 4)
function testBaseExecuteBatch() public {
function test_base_executeBatch() public {
uint256 inputAmount = ONE;
uint256 outputAmount = 2 * inputAmount;

Expand Down Expand Up @@ -306,7 +306,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic batch execute test with native output
function testBaseExecuteBatchNativeOutput() public {
function test_base_executeBatchNativeOutput() public {
uint256 inputAmount = ONE;
uint256 outputAmount = 2 * inputAmount;

Expand Down Expand Up @@ -356,7 +356,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
/// @dev Execute batch with multiple outputs
/// Order 1: (inputs = 1, outputs = [2, 1]),
/// Order 2: (inputs = 2, outputs = [3])
function testBaseExecuteBatchMultipleOutputs() public {
function test_base_executeBatchMultipleOutputs() public {
uint256[] memory inputAmounts = ArrayBuilder.fill(1, ONE).push(2 * ONE);
uint256[] memory output1 = ArrayBuilder.fill(1, 2 * ONE).push(ONE);
uint256[] memory output2 = ArrayBuilder.fill(1, 3 * ONE);
Expand Down Expand Up @@ -408,7 +408,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
/// @dev Execute batch with multiple outputs
/// Order 1: (inputs = 1, outputs = [2, 1]),
/// Order 2: (inputs = 2, outputs = [3])
function testBaseExecuteBatchMultipleOutputsDifferentTokens() public {
function test_base_executeBatchMultipleOutputsDifferentTokens() public {
uint256[] memory output1 = ArrayBuilder.fill(1, 2 * ONE).push(ONE);
uint256[] memory output2 = ArrayBuilder.fill(1, 3 * ONE).push(ONE);

Expand Down Expand Up @@ -464,7 +464,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Base test preventing signatures from being reused
function testBaseExecuteSignatureReplay() public {
function test_base_executeSignatureReplay() public {
// Seed both swapper and fillContract with enough tokens
uint256 inputAmount = ONE;
uint256 outputAmount = ONE * 2;
Expand Down Expand Up @@ -512,7 +512,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Base test preventing nonce reuse
function testBaseNonceReuse() public {
function test_base_nonceReuse() public {
uint256 inputAmount = ONE;
uint256 outputAmount = ONE * 2;
tokenIn.mint(address(swapper), inputAmount * 100);
Expand Down Expand Up @@ -556,7 +556,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer

/// @dev Test executing two orders on two reactors at once
/// @dev executing the second order inside the callback of the first's execution
function testBaseExecuteTwoReactorsAtOnce() public {
function test_base_executeTwoReactorsAtOnce() public {
BaseReactor otherReactor = createReactor();
MockFillContractDoubleExecution doubleExecutionFillContract =
new MockFillContractDoubleExecution(address(reactor), address(otherReactor));
Expand Down Expand Up @@ -599,7 +599,9 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic execute test with protocol fee, checks balance before and after
function testBaseExecuteWithFee(uint128 inputAmount, uint128 outputAmount, uint256 deadline, uint8 feeBps) public {
function test_base_executeWithFee(uint128 inputAmount, uint128 outputAmount, uint256 deadline, uint8 feeBps)
public
{
vm.assume(deadline > block.timestamp);
vm.assume(feeBps <= 5);

Expand Down Expand Up @@ -642,7 +644,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic execute test, checks balance before and after
function testBaseExecute(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
function test_base_execute(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
vm.assume(deadline > block.timestamp);
// Seed both swapper and fillContract with enough tokens (important for dutch order)
tokenIn.mint(address(swapper), uint256(inputAmount) * 100);
Expand Down Expand Up @@ -679,7 +681,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Execute with a succeeding validation contract
function testBaseExecuteValidationContract(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
function test_base_executeValidationContract(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
vm.assume(deadline > block.timestamp);
// Seed both swapper and fillContract with enough tokens (important for dutch order)
tokenIn.mint(address(swapper), uint256(inputAmount) * 100);
Expand Down Expand Up @@ -718,7 +720,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Execute with a failing validation contract
function testBaseExecuteValidationContractFail(uint128 inputAmount, uint128 outputAmount, uint256 deadline)
function test_base_executeValidationContractFail(uint128 inputAmount, uint128 outputAmount, uint256 deadline)
public
{
vm.assume(deadline > block.timestamp);
Expand All @@ -745,7 +747,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Execute with an invalid reactor
function testBaseExecuteInvalidReactor(
function test_base_executeInvalidReactor(
address orderReactor,
uint128 inputAmount,
uint128 outputAmount,
Expand Down Expand Up @@ -775,7 +777,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Execute with a deadline already passed
function testBaseExecuteDeadlinePassed(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
function test_base_executeDeadlinePassed(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
vm.assume(deadline < block.timestamp);
// Seed both swapper and fillContract with enough tokens (important for dutch order)
tokenIn.mint(address(swapper), uint256(inputAmount) * 100);
Expand All @@ -800,7 +802,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
}

/// @dev Basic execute test for native currency, checks balance before and after
function testBaseExecuteNativeOutput(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
function test_base_executeNativeOutput(uint128 inputAmount, uint128 outputAmount, uint256 deadline) public {
vm.assume(deadline > block.timestamp);
// Seed both swapper and fillContract with enough tokens (important for dutch order)
tokenIn.mint(address(swapper), uint256(inputAmount) * 100);
Expand Down
Loading

0 comments on commit 99090c6

Please sign in to comment.