-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
319 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/callbacks/liquidity/BaselineV2/Allowlist/BaselineAllowlistTest.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.19; | ||
|
||
// Test scaffolding | ||
import {BaselineAxisLaunchTest} from | ||
"test/callbacks/liquidity/BaselineV2/BaselineAxisLaunchTest.sol"; | ||
|
||
// Axis | ||
import {BALwithAllowlist} from "src/callbacks/liquidity/BaselineV2/BALwithAllowlist.sol"; | ||
|
||
contract BaselineAllowlistTest is BaselineAxisLaunchTest { | ||
uint256 internal constant _BUYER_LIMIT = 5e18; | ||
|
||
// ========== MODIFIERS ========== // | ||
|
||
modifier givenCallbackIsCreated() override { | ||
// Get the salt | ||
bytes memory args = | ||
abi.encode(address(_auctionHouse), _BASELINE_KERNEL, _BASELINE_QUOTE_TOKEN, _OWNER); | ||
bytes32 salt = _getTestSalt("BaselineAllowlist", type(BALwithAllowlist).creationCode, args); | ||
|
||
// Required for CREATE2 address to work correctly. doesn't do anything in a test | ||
// Source: https://github.com/foundry-rs/foundry/issues/6402 | ||
vm.startBroadcast(); | ||
_dtl = new BALwithAllowlist{salt: salt}( | ||
address(_auctionHouse), _BASELINE_KERNEL, _BASELINE_QUOTE_TOKEN, _OWNER | ||
); | ||
vm.stopBroadcast(); | ||
|
||
_dtlAddress = address(_dtl); | ||
|
||
// Call configureDependencies to set everything that's needed | ||
_mockBaselineGetModuleForKeycode(); | ||
_dtl.configureDependencies(); | ||
_; | ||
} | ||
|
||
modifier givenAllowlistParams(bytes32 merkleRoot_) { | ||
_createData.allowlistParams = abi.encode(merkleRoot_); | ||
_; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
test/callbacks/liquidity/BaselineV2/Allowlist/onBid.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.19; | ||
|
||
import {BaselineAllowlistTest} from | ||
"test/callbacks/liquidity/BaselineV2/Allowlist/BaselineAllowlistTest.sol"; | ||
|
||
import {BaseCallback} from "src/callbacks/BaseCallback.sol"; | ||
import {BALwithAllowlist} from "src/callbacks/liquidity/BaselineV2/BALwithAllowlist.sol"; | ||
|
||
contract BaselineAllowlistOnBidTest is BaselineAllowlistTest { | ||
// Use the @openzeppelin/merkle-tree package or the scripts in axis-utils to generate the merkle tree | ||
|
||
// Values: | ||
// 0x0000000000000000000000000000000000000004 | ||
// 0x0000000000000000000000000000000000000005 | ||
bytes32 internal constant _MERKLE_ROOT = | ||
0xc92348ba87c65979cc4f264810321a35efa64e795075908af2c507a22d4da472; | ||
bytes32 internal constant _BUYER_MERKLE_PROOF = | ||
0x16db2e4b9f8dc120de98f8491964203ba76de27b27b29c2d25f85a325cd37477; | ||
bytes32 internal constant _NOT_SELLER_MERKLE_PROOF = | ||
0xc167b0e3c82238f4f2d1a50a8b3a44f96311d77b148c30dc0ef863e1a060dcb6; | ||
|
||
bytes32[] internal _proof; | ||
|
||
uint64 internal constant _BID_ID = 1; | ||
|
||
// ========== MODIFIER ========== // | ||
|
||
modifier givenMerkleProof(bytes32 merkleProof_) { | ||
bytes32[] memory proof = new bytes32[](1); | ||
proof[0] = merkleProof_; | ||
|
||
_proof = proof; | ||
_; | ||
} | ||
|
||
function _onBid(uint256 bidAmount_) internal { | ||
// Call the callback | ||
vm.prank(address(_auctionHouse)); | ||
_dtl.onBid(_lotId, _BID_ID, _BUYER, bidAmount_, abi.encode(_proof)); | ||
} | ||
|
||
// ========== TESTS ========== // | ||
|
||
// [X] when the allowlist parameters are in an incorrect format | ||
// [X] it reverts | ||
// [X] when the merkle proof is invalid | ||
// [X] it reverts | ||
// [X] when the buyer is not in the merkle tree | ||
// [X] it reverts | ||
// [X] it succeeds | ||
|
||
function test_parametersInvalid_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
{ | ||
// Expect revert | ||
vm.expectRevert(); | ||
|
||
// Call the callback with an invalid parameter format | ||
vm.prank(address(_auctionHouse)); | ||
_dtl.onBid(_lotId, _BID_ID, _BUYER, 5e18, abi.encode(uint256(20), bytes("something"))); | ||
} | ||
|
||
function test_merkleProofInvalid_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
givenMerkleProof(_NOT_SELLER_MERKLE_PROOF) | ||
{ | ||
// Expect revert | ||
bytes memory err = abi.encodeWithSelector(BaseCallback.Callback_NotAuthorized.selector); | ||
vm.expectRevert(err); | ||
|
||
// Call the callback with an invalid merkle proof | ||
_onBid(5e18); | ||
} | ||
|
||
function test_buyerNotInMerkleTree_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
givenMerkleProof(_BUYER_MERKLE_PROOF) | ||
{ | ||
// Expect revert | ||
bytes memory err = abi.encodeWithSelector(BaseCallback.Callback_NotAuthorized.selector); | ||
vm.expectRevert(err); | ||
|
||
// Call the callback | ||
vm.prank(address(_auctionHouse)); | ||
_dtl.onBid(_lotId, _BID_ID, address(0x55), 5e18, abi.encode(_proof)); | ||
} | ||
|
||
function test_success(uint256 bidAmount_) | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
givenMerkleProof(_BUYER_MERKLE_PROOF) | ||
{ | ||
// Call the callback | ||
_onBid(bidAmount_); | ||
|
||
// Does not revert | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
test/callbacks/liquidity/BaselineV2/Allowlist/onCreate.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.19; | ||
|
||
import {BaselineAllowlistTest} from | ||
"test/callbacks/liquidity/BaselineV2/Allowlist/BaselineAllowlistTest.sol"; | ||
|
||
import {BaseCallback} from "src/callbacks/BaseCallback.sol"; | ||
import {BALwithAllowlist} from "src/callbacks/liquidity/BaselineV2/BALwithAllowlist.sol"; | ||
|
||
contract BaselineAllowlistOnCreateTest is BaselineAllowlistTest { | ||
/// @dev This doesn't need to be valid at the moment | ||
bytes32 internal constant _MERKLE_ROOT = | ||
0x1234567890123456789012345678901234567890123456789012345678901234; | ||
|
||
// ========== TESTS ========== // | ||
|
||
// [X] when the allowlist parameters are in an incorrect format | ||
// [X] it reverts | ||
// [X] it decodes and stores the merkle root | ||
|
||
function test_allowlistParamsIncorrect_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
{ | ||
// Set the allowlist parameters to be an incorrect format | ||
_createData.allowlistParams = abi.encode(uint256(20), bytes32("hello"), uint256(10)); | ||
|
||
// Expect revert | ||
bytes memory err = abi.encodeWithSelector(BaseCallback.Callback_InvalidParams.selector); | ||
vm.expectRevert(err); | ||
|
||
// Call the callback | ||
_onCreate(); | ||
} | ||
|
||
function test_success() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
{ | ||
// Call the callback | ||
_onCreate(); | ||
|
||
// Check the merkle root is stored | ||
assertEq(BALwithAllowlist(address(_dtl)).merkleRoot(), _MERKLE_ROOT, "merkle root"); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
test/callbacks/liquidity/BaselineV2/Allowlist/setMerkleRoot.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.19; | ||
|
||
import {BaselineAllowlistTest} from | ||
"test/callbacks/liquidity/BaselineV2/Allowlist/BaselineAllowlistTest.sol"; | ||
|
||
import {BaseCallback} from "src/callbacks/BaseCallback.sol"; | ||
import {BALwithAllowlist} from "src/callbacks/liquidity/BaselineV2/BALwithAllowlist.sol"; | ||
|
||
contract BaselineAllowlistSetMerkleRootTest is BaselineAllowlistTest { | ||
/// @dev This doesn't need to be valid at the moment | ||
bytes32 internal constant _MERKLE_ROOT = | ||
0x1234567890123456789012345678901234567890123456789012345678901234; | ||
bytes32 internal constant _NEW_MERKLE_ROOT = | ||
0x1234567890123456789012345678901234567890123456789012345678901234; | ||
|
||
function _setMerkleRoot() internal { | ||
vm.prank(_OWNER); | ||
BALwithAllowlist(address(_dtl)).setMerkleRoot(_NEW_MERKLE_ROOT); | ||
} | ||
|
||
// ========== TESTS ========== // | ||
|
||
// [X] when the caller is not the owner | ||
// [X] it reverts | ||
// [X] when the auction has not been registered | ||
// [X] it reverts | ||
// [X] when the auction has been completed | ||
// [X] it reverts | ||
// [X] the merkle root is updated and an event is emitted | ||
|
||
function test_notOwner_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
{ | ||
// Expect revert | ||
vm.expectRevert("UNAUTHORIZED"); | ||
|
||
// Call the callback | ||
BALwithAllowlist(address(_dtl)).setMerkleRoot(_NEW_MERKLE_ROOT); | ||
} | ||
|
||
function test_auctionNotRegistered_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
{ | ||
// Expect revert | ||
bytes memory err = abi.encodeWithSelector(BALwithAllowlist.Callback_InvalidState.selector); | ||
vm.expectRevert(err); | ||
|
||
// Call the callback | ||
_setMerkleRoot(); | ||
} | ||
|
||
function test_auctionCompleted_reverts() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
givenAddressHasQuoteTokenBalance(_dtlAddress, _PROCEEDS_AMOUNT) | ||
givenAddressHasBaseTokenBalance(_dtlAddress, _REFUND_AMOUNT) | ||
givenOnSettle | ||
{ | ||
// Expect revert | ||
bytes memory err = abi.encodeWithSelector(BALwithAllowlist.Callback_InvalidState.selector); | ||
vm.expectRevert(err); | ||
|
||
// Call the callback | ||
_setMerkleRoot(); | ||
} | ||
|
||
function test_success() | ||
public | ||
givenBPoolIsCreated | ||
givenCallbackIsCreated | ||
givenAuctionIsCreated | ||
givenAllowlistParams(_MERKLE_ROOT) | ||
givenOnCreate | ||
{ | ||
// Call the callback | ||
_setMerkleRoot(); | ||
|
||
// Check the merkle root is updated | ||
assertEq(BALwithAllowlist(address(_dtl)).merkleRoot(), _NEW_MERKLE_ROOT, "merkle root"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.