Skip to content

Commit

Permalink
Check for invalid params with condenser
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Jan 17, 2024
1 parent 35292ee commit b7a394c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
22 changes: 18 additions & 4 deletions test/AuctionHouse/sendPayout.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ contract SendPayoutTest is Test, Permit2User {
// ========== Derivative flow ========== //

// [ ] given the base token is a derivative
// [ ] given a condenser is set
// [ ] given the derivative parameters are invalid
// [ ] it reverts
// [X] given a condenser is set
// [X] given the derivative parameters are invalid
// [X] it reverts
// [X] it uses the condenser to determine derivative parameters
// [ ] given a condenser is not set
// [ ] given the derivative is wrapped
Expand Down Expand Up @@ -294,7 +294,7 @@ contract SendPayoutTest is Test, Permit2User {
}

modifier givenDerivativeParamsAreInvalid() {
derivativeParams = abi.encode(0);
derivativeParams = abi.encode("one", "two", uint256(2));
routingParams.derivativeParams = derivativeParams;
_;
}
Expand Down Expand Up @@ -352,6 +352,20 @@ contract SendPayoutTest is Test, Permit2User {
);
}

function test_derivative_condenser_invalidParams_reverts()
public
givenAuctionHasDerivative
givenDerivativeHasCondenser
givenDerivativeParamsAreInvalid
{
// Expect revert while decoding parameters
vm.expectRevert();

// Call
vm.prank(USER);
auctionHouse.sendPayout(lotId, RECIPIENT, payoutAmount, routingParams, auctionOutput);
}

function test_derivative_condenser()
public
givenAuctionHasDerivative
Expand Down
6 changes: 4 additions & 2 deletions test/modules/Condenser/MockCondenserModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ contract MockCondenserModule is CondenserModule {
abi.decode(auctionOutput_, (MockAtomicAuctionModule.Output));

// Get derivative params
(uint256 derivativeTokenId) = abi.decode(derivativeConfig_, (uint256));
if (derivativeConfig_.length != 64) revert("");
MockDerivativeModule.Params memory originalDerivativeParams =
abi.decode(derivativeConfig_, (MockDerivativeModule.Params));

MockDerivativeModule.Params memory derivativeParams = MockDerivativeModule.Params({
tokenId: derivativeTokenId,
tokenId: originalDerivativeParams.tokenId,
multiplier: auctionOutput.multiplier
});

Expand Down
4 changes: 4 additions & 0 deletions test/modules/Derivative/MockDerivativeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {DerivativeModule} from "src/modules/Derivative.sol";

import {MockERC6909} from "solmate/test/utils/mocks/MockERC6909.sol";

import {console2} from "forge-std/console2.sol";

contract MockDerivativeModule is DerivativeModule {
bool internal validateFails;
MockERC6909 internal derivativeToken;
Expand Down Expand Up @@ -41,6 +43,8 @@ contract MockDerivativeModule is DerivativeModule {
uint256 amount_,
bool wrapped_
) external virtual override returns (uint256, address, uint256) {
if (params_.length != 64) revert("");

// TODO wrapping
Params memory params = abi.decode(params_, (Params));

Expand Down

0 comments on commit b7a394c

Please sign in to comment.