Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Jan 10, 2024
1 parent 4a32f16 commit 3692eb1
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 96 deletions.
34 changes: 33 additions & 1 deletion src/bases/Auctioneer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fromKeycode,
Keycode,
fromVeecode,
unwrapVeecode,
Veecode,
Module,
WithModules
Expand Down Expand Up @@ -171,10 +172,36 @@ abstract contract Auctioneer is WithModules {
routing.derivativeParams = routing_.derivativeParams;
}

// Condenser
{
// Get condenser reference
Veecode condenserRef = condensers[auctionRef][routing.derivativeReference];

// Check that the module for the condenser type is valid
if (fromVeecode(condenserRef) != bytes7(0)) {
CondenserModule condenserModule =
CondenserModule(_getModuleIfInstalled(condenserRef));

if (condenserModule.TYPE() != Module.Type.Condenser) {
revert InvalidModuleType(condenserRef);
}

// Check module status
(Keycode moduleKeycode,) = unwrapVeecode(condenserRef);
ModStatus memory status = getModuleStatus[moduleKeycode];
if (status.sunset == true) {
revert ModuleIsSunset(moduleKeycode);
}
}
}

// 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

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

emit AuctionCreated(lotId, address(routing.baseToken), address(routing.quoteToken));
Expand All @@ -188,8 +215,13 @@ abstract contract Auctioneer is WithModules {
///
/// @param lotId_ ID of the auction lot
function cancel(uint256 lotId_) external {
address lotOwner = lotRouting[lotId_].owner;

// Check that lot ID is valid
if (lotOwner == address(0)) revert InvalidLotId(lotId_);

// Check that caller is the auction owner
if (msg.sender != lotRouting[lotId_].owner) revert NotAuctionOwner(msg.sender);
if (msg.sender != lotOwner) revert NotAuctionOwner(msg.sender);

AuctionModule module = _getModuleForId(lotId_);

Expand Down
21 changes: 2 additions & 19 deletions test/AuctionHouse/auction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract AuctionTest is Test {
routingParams.auctionType = toKeycode("DERV");

bytes memory err = abi.encodeWithSelector(
Auctioneer.InvalidModuleType.selector, mockAuctionModule.VEECODE()
Auctioneer.InvalidModuleType.selector, mockDerivativeModule.VEECODE()
);
vm.expectRevert(err);

Expand Down Expand Up @@ -285,7 +285,7 @@ contract AuctionTest is Test {

// Expect revert
bytes memory err = abi.encodeWithSelector(
Auctioneer.InvalidModuleType.selector, mockDerivativeModule.VEECODE()
Auctioneer.InvalidModuleType.selector, mockAuctionModule.VEECODE()
);
vm.expectRevert(err);

Expand Down Expand Up @@ -365,26 +365,9 @@ contract AuctionTest is Test {

// [X] condenser
// [X] reverts when condenser type is sunset
// [X] reverts when condenser type is not installed
// [X] reverts when condenser type is not a condenser
// [X] reverts when compatibility check fails
// [X] sets the condenser on the auction lot

function testReverts_whenCondenserModuleNotInstalled()
external
whenAuctionModuleIsInstalled
whenDerivativeModuleIsInstalled
whenDerivativeTypeIsSet
whenCondenserIsMapped
{
// Expect revert
bytes memory err =
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("COND"), 0);
vm.expectRevert(err);

auctionHouse.auction(routingParams, auctionParams);
}

function testReverts_whenCondenserTypeIsSunset()
external
whenAuctionModuleIsInstalled
Expand Down
1 change: 1 addition & 0 deletions test/AuctionHouse/cancel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ contract CancelTest is Test {
bytes memory err = abi.encodeWithSelector(Auctioneer.InvalidLotId.selector, lotId);
vm.expectRevert(err);

vm.prank(auctionOwner);
auctionHouse.cancel(lotId);
}

Expand Down
121 changes: 45 additions & 76 deletions test/AuctionHouse/setCondenser.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ contract SetCondenserTest is Test {

address internal protocol = address(0x2);

Veecode internal auctionVeecode;
Veecode internal derivativeVeecode;
Veecode internal condenserVeecode;
Veecode internal blankVeecode;

function setUp() external {
baseToken = new MockERC20("Base Token", "BASE", 18);
quoteToken = new MockERC20("Quote Token", "QUOTE", 18);
Expand All @@ -47,6 +52,11 @@ contract SetCondenserTest is Test {
mockAuctionModule = new MockAuctionModule(address(auctionHouse));
mockDerivativeModule = new MockDerivativeModule(address(auctionHouse));
mockCondenserModule = new MockCondenserModule(address(auctionHouse));

auctionVeecode = mockAuctionModule.VEECODE();
derivativeVeecode = mockDerivativeModule.VEECODE();
condenserVeecode = mockCondenserModule.VEECODE();
blankVeecode = toVeecode("");
}

modifier whenAuctionModuleIsInstalled() {
Expand All @@ -64,14 +74,14 @@ contract SetCondenserTest is Test {
_;
}

// addCondenserLookup
// setCondenser
// [X] reverts if not the owner
// [X] reverts if auction keycode is 0
// [X] reverts if derivative keycode is 0
// [X] reverts if auction Veecode is 0
// [X] reverts if derivative Veecode is 0
// [X] reverts if auction module is not an auction
// [X] reverts if derivative module is not a derivative
// [X] reverts if condenser keycode is not 0 and condenser module is not a condenser
// [X] unsets if condenser keycode is 0
// [X] reverts if derivative Veecode is not a derivative
// [X] reverts if condenser Veecode is not 0 and condenser module is not a condenser
// [X] unsets if condenser Veecode is 0
// [X] sets the condenser lookup values

function testReverts_whenUnauthorized() external {
Expand All @@ -80,41 +90,29 @@ contract SetCondenserTest is Test {
vm.expectRevert("UNAUTHORIZED");

vm.prank(alice);
auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenAuctionKeycodeIsEmpty() external {
function testReverts_whenAuctionVeecodeIsEmpty() external {
bytes memory err = abi.encodeWithSelector(Auctioneer.InvalidParams.selector);
vm.expectRevert(err);

auctionHouse.setCondenser(
toVeecode(""), mockDerivativeModule.VEECODE(), mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(blankVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenDerivativeKeycodeIsEmpty() external {
function testReverts_whenDerivativeVeecodeIsEmpty() external {
bytes memory err = abi.encodeWithSelector(Auctioneer.InvalidParams.selector);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(), toVeecode(""), mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, blankVeecode, condenserVeecode);
}

function testReverts_whenAuctionModuleNotInstalled() external {
bytes memory err =
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("MOCK"), 0);
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("MOCK"), 1);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenAuctionTypeIncorrect()
Expand All @@ -123,28 +121,19 @@ contract SetCondenserTest is Test {
whenDerivativeModuleIsInstalled
whenCondenserModuleIsInstalled
{
bytes memory err = abi.encodeWithSelector(
Auctioneer.InvalidModuleType.selector, mockDerivativeModule.VEECODE()
);
bytes memory err =
abi.encodeWithSelector(Auctioneer.InvalidModuleType.selector, derivativeVeecode);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockDerivativeModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(derivativeVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenDerivativeModuleNotInstalled() external whenAuctionModuleIsInstalled {
bytes memory err =
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("DERV"), 0);
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("DERV"), 1);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenDerivativeTypeIncorrect()
Expand All @@ -153,14 +142,11 @@ contract SetCondenserTest is Test {
whenDerivativeModuleIsInstalled
whenCondenserModuleIsInstalled
{
bytes memory err = abi.encodeWithSelector(
Auctioneer.InvalidModuleType.selector, mockAuctionModule.VEECODE()
);
bytes memory err =
abi.encodeWithSelector(Auctioneer.InvalidModuleType.selector, auctionVeecode);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(), mockAuctionModule.VEECODE(), mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, auctionVeecode, condenserVeecode);
}

function testReverts_whenCondenserModuleNotInstalled()
Expand All @@ -169,14 +155,10 @@ contract SetCondenserTest is Test {
whenDerivativeModuleIsInstalled
{
bytes memory err =
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("COND"), 0);
abi.encodeWithSelector(WithModules.ModuleNotInstalled.selector, toKeycode("COND"), 1);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, condenserVeecode);
}

function testReverts_whenCondenserTypeIncorrect()
Expand All @@ -185,46 +167,33 @@ contract SetCondenserTest is Test {
whenDerivativeModuleIsInstalled
whenCondenserModuleIsInstalled
{
bytes memory err = abi.encodeWithSelector(
Auctioneer.InvalidModuleType.selector, mockDerivativeModule.VEECODE()
);
bytes memory err =
abi.encodeWithSelector(Auctioneer.InvalidModuleType.selector, derivativeVeecode);
vm.expectRevert(err);

auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockDerivativeModule.VEECODE()
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, derivativeVeecode);
}

function test_success_whenCondenserKeycodeIsEmpty()
function test_success_whenCondenserVeecodeIsEmpty()
external
whenAuctionModuleIsInstalled
whenDerivativeModuleIsInstalled
{
auctionHouse.setCondenser(
mockAuctionModule.VEECODE(), mockDerivativeModule.VEECODE(), toVeecode("")
);
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, blankVeecode);

Veecode condenserVeecode =
auctionHouse.condensers(mockAuctionModule.VEECODE(), mockDerivativeModule.VEECODE());
assertEq(fromVeecode(condenserVeecode), "");
Veecode veecode_ = auctionHouse.condensers(auctionVeecode, derivativeVeecode);
assertEq(fromVeecode(veecode_), "");
}

function test_success_whenCondenserKeycodeIsNotEmpty()
function test_success_whenCondenserVeecodeIsNotEmpty()
external
whenAuctionModuleIsInstalled
whenDerivativeModuleIsInstalled
whenCondenserModuleIsInstalled
{
auctionHouse.setCondenser(
mockAuctionModule.VEECODE(),
mockDerivativeModule.VEECODE(),
mockCondenserModule.VEECODE()
);

Veecode condenserVeecode =
auctionHouse.condensers(mockAuctionModule.VEECODE(), mockDerivativeModule.VEECODE());
assertEq(fromVeecode(condenserVeecode), fromVeecode(mockCondenserModule.VEECODE()));
auctionHouse.setCondenser(auctionVeecode, derivativeVeecode, condenserVeecode);

Veecode veecode_ = auctionHouse.condensers(auctionVeecode, derivativeVeecode);
assertEq(fromVeecode(veecode_), fromVeecode(condenserVeecode));
}
}
2 changes: 2 additions & 0 deletions test/modules/Derivative/MockDerivativeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ contract MockDerivativeModule is DerivativeModule {

function validate(bytes memory params_) external view virtual override returns (bool) {
if (validateFails) revert("validation error");

return true;
}

function setValidateFails(bool validateFails_) external {
Expand Down

0 comments on commit 3692eb1

Please sign in to comment.