Skip to content

Commit

Permalink
Validation for hooks and allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Jan 10, 2024
1 parent 3692eb1 commit a5b39d7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/bases/Auctioneer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ abstract contract Auctioneer is WithModules {
/// - Validation for the auction parameters fails
/// - The module for the optional specified derivative type is not installed
/// - Validation for the optional specified derivative type fails
/// - Validation for the optional allowlist fails
/// - The module for the optional specified condenser type is not installed
/// - Registration for the optional allowlist fails
/// - The optional specified hooks contract is not a contract
/// - The condenser module is not installed or is sunset
///
/// @param routing_ Routing information for the auction lot
/// @param params_ Auction parameters for the auction lot
Expand Down Expand Up @@ -150,7 +151,6 @@ abstract contract Auctioneer is WithModules {
routing.owner = msg.sender;
routing.baseToken = routing_.baseToken;
routing.quoteToken = routing_.quoteToken;
routing.hooks = routing_.hooks;

// Derivative
if (fromKeycode(routing_.derivativeType) != bytes5("")) {
Expand Down Expand Up @@ -197,13 +197,27 @@ abstract contract Auctioneer is WithModules {

// If allowlist is being used, validate the allowlist data and register the auction on the allowlist
if (address(routing_.allowlist) != address(0)) {
// TODO validation
// TODO registration with allowlist
// Check that it is a contract
// It is assumed that the user will do validation of the allowlist
if (address(routing_.allowlist).code.length == 0) revert InvalidParams();

// Register with the allowlist
routing_.allowlist.register(lotId, routing_.allowlistParams);

// Store allowlist information
routing.allowlist = routing_.allowlist;
}

// If hooks are being used, validate the hooks data
if (address(routing_.hooks) != address(0)) {
// Check that it is a contract
// It is assumed that the user will do validation of the hooks
if (address(routing_.hooks).code.length == 0) revert InvalidParams();

// Store hooks information
routing.hooks = routing_.hooks;
}

emit AuctionCreated(lotId, address(routing.baseToken), address(routing.quoteToken));
}

Expand Down
44 changes: 42 additions & 2 deletions test/AuctionHouse/auction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ contract AuctionTest is Test {
// Won't revert
}

// [ ] allowlist
// [ ] reverts when allowlist validation fails
// [X] allowlist
// [X] reverts when the allowlist address is not a contract
// [X] reverts when allowlist validation fails
// [X] sets the allowlist on the auction lot

function test_success_allowlistIsSet() external whenAuctionModuleIsInstalled {
Expand All @@ -416,11 +417,50 @@ contract AuctionTest is Test {
(,,,,, IAllowlist lotAllowlist,,,) = auctionHouse.lotRouting(lotId);

assertEq(address(lotAllowlist), address(mockAllowlist), "allowlist mismatch");

// Check that it has been registered with the allowlist
uint256[] memory registeredIds = mockAllowlist.getRegisteredIds();
assertEq(registeredIds.length, 1, "registered ids length mismatch");
assertEq(registeredIds[0], lotId, "registered id mismatch");
}

function testReverts_whenAllowlistIsNotContract() external whenAuctionModuleIsInstalled {
// Update routing params
routingParams.allowlist = IAllowlist(address(0x10));

// Expect revert
bytes memory err = abi.encodeWithSelector(Auctioneer.InvalidParams.selector);
vm.expectRevert(err);

auctionHouse.auction(routingParams, auctionParams);
}

function testReverts_whenAllowlistValidationFails() external whenAuctionModuleIsInstalled {
// Update routing params
routingParams.allowlist = mockAllowlist;

// Expect revert
mockAllowlist.setRegisterReverts(true);
vm.expectRevert("MockAllowlist: register reverted");

auctionHouse.auction(routingParams, auctionParams);
}

// [X] hooks
// [X] reverts when the hooks address is not a contract
// [X] sets the hooks on the auction lot

function testReverts_whenHooksIsNotContract() external whenAuctionModuleIsInstalled {
// Update routing params
routingParams.hooks = IHooks(address(0x10));

// Expect revert
bytes memory err = abi.encodeWithSelector(Auctioneer.InvalidParams.selector);
vm.expectRevert(err);

auctionHouse.auction(routingParams, auctionParams);
}

function test_success_hooksIsSet() external whenAuctionModuleIsInstalled {
// Update routing params
routingParams.hooks = mockHook;
Expand Down
20 changes: 19 additions & 1 deletion test/modules/Auction/MockAllowlist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity 0.8.19;
import {IAllowlist} from "src/bases/Auctioneer.sol";

contract MockAllowlist is IAllowlist {
bool registerReverts = false;

uint256[] public registeredIds;

function isAllowed(
address user_,
bytes calldata proof_
Expand All @@ -17,5 +21,19 @@ contract MockAllowlist is IAllowlist {

function register(bytes calldata params_) external override {}

function register(uint256 id_, bytes calldata params_) external override {}
function register(uint256 id_, bytes calldata params_) external override {
if (registerReverts) {
revert("MockAllowlist: register reverted");
}

registeredIds.push(id_);
}

function setRegisterReverts(bool registerReverts_) external {
registerReverts = registerReverts_;
}

function getRegisteredIds() external view returns (uint256[] memory) {
return registeredIds;
}
}

0 comments on commit a5b39d7

Please sign in to comment.