Skip to content

Commit

Permalink
Add more tests for nonstandard orders (#54)
Browse files Browse the repository at this point in the history
* Add tests with orders with no inputs

* comments
  • Loading branch information
zhongeric authored Feb 8, 2024
1 parent 9aa45d8 commit 58eec8c
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions test/foundry-tests/reactors/RelayOrderReactorTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ contract RelayOrderReactorTest is GasSnapshot, Test, PermitSignature, DeployPerm
assertEq(tokenIn.balanceOf(address(filler)), 250000000000000000);
}

function test_execute_noInputs() public {
Input[] memory inputs = new Input[](0);
OrderInfo memory orderInfo =
OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 1000);
RelayOrder memory order = RelayOrderBuilder.init(orderInfo, inputs).withEndTime(block.timestamp + 1000);

SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.expectEmit(true, true, true, true, address(reactor));
emit Fill(order.hash(), address(filler), swapper, order.info.nonce);
// should be fillable
vm.prank(filler);
reactor.execute(signedOrder, filler);
}

function test_multicall_execute_noDecay() public {
tokenIn.mint(address(swapper), ONE * 100);
// First order.
Expand Down Expand Up @@ -157,7 +173,6 @@ contract RelayOrderReactorTest is GasSnapshot, Test, PermitSignature, DeployPerm
SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.prank(filler);
vm.expectRevert(ReactorErrors.InvalidReactor.selector);
reactor.execute(signedOrder, filler);
}
Expand All @@ -171,7 +186,21 @@ contract RelayOrderReactorTest is GasSnapshot, Test, PermitSignature, DeployPerm
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.warp(deadline + 1);
vm.prank(filler);
vm.expectRevert(abi.encodeWithSelector(SignatureExpired.selector, deadline));
reactor.execute(signedOrder, filler);
}

function test_execute_reverts_NoInputsSignatureExpired() public {
uint256 deadline = block.timestamp + 10;
Input[] memory inputs = new Input[](0);
RelayOrder memory order = RelayOrderBuilder.initDefault(tokenIn, address(reactor), swapper);
order.inputs = inputs;
order.info = order.info.withDeadline(deadline);

SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.warp(deadline + 1);
vm.expectRevert(abi.encodeWithSelector(SignatureExpired.selector, deadline));
reactor.execute(signedOrder, filler);
}
Expand Down Expand Up @@ -212,7 +241,6 @@ contract RelayOrderReactorTest is GasSnapshot, Test, PermitSignature, DeployPerm
SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.prank(filler);
vm.expectRevert(ReactorErrors.EndTimeBeforeStartTime.selector);
reactor.execute(signedOrder, filler);
}
Expand All @@ -224,7 +252,6 @@ contract RelayOrderReactorTest is GasSnapshot, Test, PermitSignature, DeployPerm
SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));

vm.prank(filler);
vm.expectRevert(ReactorErrors.DeadlineBeforeEndTime.selector);
reactor.execute(signedOrder, filler);
}
Expand Down

0 comments on commit 58eec8c

Please sign in to comment.