Skip to content

Commit

Permalink
test(refactor): periphery tests to use Bulloak
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Aug 28, 2024
1 parent 5eb674a commit 8fd9d8c
Show file tree
Hide file tree
Showing 37 changed files with 241 additions and 280 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ jobs:
lint:
uses: "sablier-labs/reusable-workflows/.github/workflows/forge-lint.yml@main"

bulloak:
needs: ["lint"]
uses: "sablier-labs/reusable-workflows/.github/workflows/bulloak-check.yml@main"
with:
skip-modifiers: true
tree-path: "test/periphery"

build:
uses: "sablier-labs/reusable-workflows/.github/workflows/forge-build.yml@main"

Expand Down Expand Up @@ -63,4 +70,4 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: "sablier-labs/reusable-workflows/.github/workflows/forge-coverage.yml@main"
with:
match-path: "test/{core,periphery}/{integration,unit}/**/*.sol"
match-path: "test/{core,periphery}/{integration,unit}/**/*.sol"
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithDurationsLD_Integration_Test is Periphery_Test {
batchLockup.createWithDurationsLD(lockupDynamic, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithDurations() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithDurationsLD.t.sol
├── when the batch size is zero
CreateWithDurationsLD_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with durations
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithDurationsLL_Integration_Test is Periphery_Test {
batchLockup.createWithDurationsLL(lockupLinear, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithDurations() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithDurationsLL.t.sol
├── when the batch size is zero
CreateWithDurationsLL_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with durations
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithDurationsLT_Integration_Test is Periphery_Test {
batchLockup.createWithDurationsLT(lockupTranched, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithDurations() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithDurationsLT.t.sol
├── when the batch size is zero
CreateWithDurationsLT_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with durations
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithTimestampsLD_Integration_Test is Periphery_Test {
batchLockup.createWithTimestampsLD(lockupDynamic, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithTimestamps() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithTimestampsLD.t.sol
├── when the batch size is zero
CreateWithTimestampsLD_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with timestamps
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithTimestampsLL_Integration_Test is Periphery_Test {
batchLockup.createWithTimestampsLL(lockupLinear, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithTimestamps() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithTimestampsLL.t.sol
├── when the batch size is zero
CreateWithTimestampsLL_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with timestamps
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ contract CreateWithTimestampsLT_Integration_Test is Periphery_Test {
batchLockup.createWithTimestampsLT(lockupTranched, dai, batchParams);
}

modifier whenBatchSizeNotZero() {
_;
}

function test_BatchCreateWithTimestamps() external whenBatchSizeNotZero {
function test_WhenBatchSizeNotZero() external {
// Asset flow: Sender → batchLockup → SablierLockup
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
expectCallToTransferFrom({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
createWithTimestampsLT.t.sol
├── when the batch size is zero
CreateWithTimestampsLT_Integration_Test
├── when batch size zero
│ └── it should revert
└── when the batch size is not zero
└── when batch size not zero
├── it should create a batch of streams with timestamps
└── it should perform the ERC-20 transfers
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MerkleBase } from "src/periphery/types/DataTypes.sol";
import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";

contract CreateMerkleInstant_Integration_Test is MerkleCampaign_Integration_Test {
function test_RevertWhen_CampaignNameTooLong() external {
function test_RevertWhen_CampaignNameExceeds32Bytes() external {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
uint256 aggregateAmount = defaults.AGGREGATE_AMOUNT();
uint256 recipientCount = defaults.RECIPIENT_COUNT();
Expand All @@ -28,12 +28,12 @@ contract CreateMerkleInstant_Integration_Test is MerkleCampaign_Integration_Test
});
}

modifier whenCampaignNameNotTooLong() {
modifier whenCampaignNameNotExceeds32Bytes() {
_;
}

/// @dev This test works because a default MerkleInstant contract is deployed in {Integration_Test.setUp}
function test_RevertGiven_CreatedAlready() external whenCampaignNameNotTooLong {
function test_RevertGiven_CampaignAlreadyExists() external whenCampaignNameNotExceeds32Bytes {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
uint256 aggregateAmount = defaults.AGGREGATE_AMOUNT();
uint256 recipientCount = defaults.RECIPIENT_COUNT();
Expand All @@ -47,17 +47,12 @@ contract CreateMerkleInstant_Integration_Test is MerkleCampaign_Integration_Test
});
}

modifier givenNotCreatedAlready() {
_;
}

function testFuzz_CreateMerkleInstant(
function test_GivenCampaignDoesNotExist(
address admin,
uint40 expiration
)
external
whenCampaignNameNotTooLong
givenNotCreatedAlready
whenCampaignNameNotExceeds32Bytes
{
vm.assume(admin != users.admin);
address expectedMerkleInstant = computeMerkleInstantAddress(admin, expiration);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
createMerkleInstant.t.sol
├── when the campaign name is too long
CreateMerkleInstant_Integration_Test
├── when campaign name exceeds 32 bytes
│ └── it should revert
└── when the campaign name is not too long
├── given the campaign has been created already
└── when campaign name not exceeds 32 bytes
├── given campaign already exists
│ └── it should revert
└── given the campaign has not been created already
└── given campaign does not exist
├── it should create the campaign
└── it should emit a {CreateMerkleInstant} event
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MerkleBase, MerkleLL } from "src/periphery/types/DataTypes.sol";
import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";

contract CreateMerkleLL_Integration_Test is MerkleCampaign_Integration_Test {
function test_RevertWhen_CampaignNameTooLong() external {
function test_RevertWhen_CampaignNameExceeds32Bytes() external {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
bool cancelable = defaults.CANCELABLE();
bool transferable = defaults.TRANSFERABLE();
Expand All @@ -35,12 +35,12 @@ contract CreateMerkleLL_Integration_Test is MerkleCampaign_Integration_Test {
});
}

modifier whenCampaignNameNotTooLong() {
modifier whenCampaignNameNotExceeds32Bytes() {
_;
}

/// @dev This test works because a default MerkleLL contract is deployed in {Integration_Test.setUp}
function test_RevertGiven_CreatedAlready() external whenCampaignNameNotTooLong {
function test_RevertGiven_CampaignAlreadyExists() external whenCampaignNameNotExceeds32Bytes {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
bool cancelable = defaults.CANCELABLE();
bool transferable = defaults.TRANSFERABLE();
Expand All @@ -61,17 +61,12 @@ contract CreateMerkleLL_Integration_Test is MerkleCampaign_Integration_Test {
});
}

modifier givenNotCreatedAlready() {
_;
}

function testFuzz_CreateMerkleLL(
function test_GivenCampaignDoesNotExist(
address admin,
uint40 expiration
)
external
whenCampaignNameNotTooLong
givenNotCreatedAlready
whenCampaignNameNotExceeds32Bytes
{
vm.assume(admin != users.admin);
address expectedLL = computeMerkleLLAddress(admin, expiration);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
createMerkleLL.t.sol
├── when the campaign name is too long
CreateMerkleLL_Integration_Test
├── when campaign name exceeds 32 bytes
│ └── it should revert
└── when the campaign name is not too long
├── given the campaign has been created already
└── when campaign name not exceeds 32 bytes
├── given campaign already exists
│ └── it should revert
└── given the campaign has not been created already
└── given campaign does not exist
├── it should create the campaign
└── it should emit a {CreateMerkleLL} event
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MerkleBase, MerkleLT } from "src/periphery/types/DataTypes.sol";
import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";

contract CreateMerkleLT_Integration_Test is MerkleCampaign_Integration_Test {
function test_RevertWhen_CampaignNameTooLong() external {
function test_RevertWhen_CampaignNameExceeds32Bytes() external {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
bool cancelable = defaults.CANCELABLE();
bool transferable = defaults.TRANSFERABLE();
Expand Down Expand Up @@ -37,12 +37,12 @@ contract CreateMerkleLT_Integration_Test is MerkleCampaign_Integration_Test {
);
}

modifier whenCampaignNameNotTooLong() {
modifier whenCampaignNameNotExceeds32Bytes() {
_;
}

/// @dev This test works because a default MerkleLT contract is deployed in {Integration_Test.setUp}
function test_RevertGiven_CreatedAlready() external whenCampaignNameNotTooLong {
function test_RevertGiven_CampaignAlreadyExists() external whenCampaignNameNotExceeds32Bytes {
MerkleBase.ConstructorParams memory baseParams = defaults.baseParams();
bool cancelable = defaults.CANCELABLE();
bool transferable = defaults.TRANSFERABLE();
Expand All @@ -65,17 +65,12 @@ contract CreateMerkleLT_Integration_Test is MerkleCampaign_Integration_Test {
);
}

modifier givenNotCreatedAlready() {
_;
}

function testFuzz_CreateMerkleLT(
function test_GivenCampaignDoesNotExist(
address admin,
uint40 expiration
)
external
whenCampaignNameNotTooLong
givenNotCreatedAlready
whenCampaignNameNotExceeds32Bytes
{
vm.assume(admin != users.admin);
address expectedLT = computeMerkleLTAddress(admin, expiration);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
createMerkleLT.t.sol
├── when the campaign name is too long
CreateMerkleLT_Integration_Test
├── when campaign name exceeds 32 bytes
│ └── it should revert
└── when the campaign name is not too long
├── given the campaign has been created already
└── when campaign name not exceeds 32 bytes
├── given campaign already exists
│ └── it should revert
└── given the campaign has not been created already
└── given campaign does not exist
├── it should create the campaign
└── it should emit a {CreateMerkleLT} event
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ import { MerkleLT } from "src/periphery/types/DataTypes.sol";
import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";

contract IsPercentagesSum100_Integration_Test is MerkleCampaign_Integration_Test {
function test_RevertWhen_SumOverflow() public {
function test_RevertWhen_PercentagesSumOverflows() public {
MerkleLT.TrancheWithPercentage[] memory tranches = defaults.tranchesWithPercentages();
tranches[0].unlockPercentage = MAX_UD2x18;

vm.expectRevert();
merkleFactory.isPercentagesSum100(tranches);
}

modifier whenSumDoesNotOverflow() {
modifier whenPercentagesSumNotOverflow() {
_;
}

modifier whenTotalPercentageNotOneHundred() {
modifier whenPercentagesSumIsNot100Pct() {
_;
}

function test_TotalPercentageLessThanOneHundred()
function test_WhenPercentagesSumLessThan100Pct()
external
view
whenSumDoesNotOverflow
whenTotalPercentageNotOneHundred
whenPercentagesSumNotOverflow
whenPercentagesSumIsNot100Pct
{
MerkleLT.TrancheWithPercentage[] memory tranchesWithPercentages = defaults.tranchesWithPercentages();
tranchesWithPercentages[0].unlockPercentage = ud2x18(0.05e18);
Expand All @@ -37,11 +37,11 @@ contract IsPercentagesSum100_Integration_Test is MerkleCampaign_Integration_Test
assertFalse(merkleFactory.isPercentagesSum100(tranchesWithPercentages), "isPercentagesSum100");
}

function test_TotalPercentageGreaterThanOneHundred()
function test_WhenPercentagesSumGreaterThan100Pct()
external
view
whenSumDoesNotOverflow
whenTotalPercentageNotOneHundred
whenPercentagesSumNotOverflow
whenPercentagesSumIsNot100Pct
{
MerkleLT.TrancheWithPercentage[] memory tranchesWithPercentages = defaults.tranchesWithPercentages();
tranchesWithPercentages[0].unlockPercentage = ud2x18(0.5e18);
Expand All @@ -50,11 +50,7 @@ contract IsPercentagesSum100_Integration_Test is MerkleCampaign_Integration_Test
assertFalse(merkleFactory.isPercentagesSum100(tranchesWithPercentages), "isPercentagesSum100");
}

modifier whenTotalPercentageOneHundred() {
_;
}

function test_IsPercentagesSum100() external view whenSumDoesNotOverflow whenTotalPercentageOneHundred {
function test_WhenPercentagesSumIs100Pct() external view whenPercentagesSumNotOverflow {
assertTrue(merkleFactory.isPercentagesSum100(defaults.tranchesWithPercentages()), "isPercentagesSum100");
}
}
Loading

0 comments on commit 8fd9d8c

Please sign in to comment.