Skip to content

Commit

Permalink
test: dry-ify the merkle tests (#1009)
Browse files Browse the repository at this point in the history
test: polish shared tests
  • Loading branch information
smol-ninja authored Aug 12, 2024
1 parent 14b48a6 commit 9c8ff1f
Show file tree
Hide file tree
Showing 46 changed files with 416 additions and 524 deletions.
4 changes: 4 additions & 0 deletions test/periphery/Periphery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { SablierMerkleLT } from "src/periphery/SablierMerkleLT.sol";
import { Base_Test } from "../Base.t.sol";

contract Periphery_Test is Base_Test {
function setUp() public virtual override {
Base_Test.setUp();
}

/*//////////////////////////////////////////////////////////////////////////
MERKLE-BASE
//////////////////////////////////////////////////////////////////////////*/
Expand Down
2 changes: 1 addition & 1 deletion test/periphery/fork/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract contract Fork_Test is Periphery_Test, Merkle {
vm.createSelectFork({ blockNumber: 20_339_512, urlOrAlias: "mainnet" });

// Set up the parent test contract.
super.setUp();
Periphery_Test.setUp();

// Load the external dependencies.
loadDependencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithDurationsLD_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithDurationsLL_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithDurationsLT_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithTimestampsLD_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithTimestampsLL_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Periphery_Test } from "../../../Periphery.t.sol";

contract CreateWithTimestampsLT_Integration_Test is Periphery_Test {
function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();
resetPrank({ msgSender: users.sender });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import { ISablierMerkleLT } from "src/periphery/interfaces/ISablierMerkleLT.sol"
import { Periphery_Test } from "../../Periphery.t.sol";

abstract contract MerkleCampaign_Integration_Test is Periphery_Test {
/*//////////////////////////////////////////////////////////////////////////
SET-UP FUNCTION
//////////////////////////////////////////////////////////////////////////*/

function setUp() public virtual override {
super.setUp();
Periphery_Test.setUp();

// Make Alice the caller.
resetPrank(users.alice);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;

import { ISablierMerkleBase } from "src/periphery/interfaces/ISablierMerkleBase.sol";

import { Clawback_Integration_Test } from "../shared/clawback/clawback.t.sol";
import { GetFirstClaimTime_Integration_Test } from "../shared/get-first-claim-time/getFirstClaimTime.t.sol";
import { HasClaimed_Integration_Test } from "../shared/has-claimed/hasClaimed.t.sol";
import { HasExpired_Integration_Test } from "../shared/has-expired/hasExpired.t.sol";
import { MerkleCampaign_Integration_Shared_Test } from "../shared/MerkleCampaign.t.sol";

/*//////////////////////////////////////////////////////////////////////////
NON-SHARED TESTS
//////////////////////////////////////////////////////////////////////////*/

abstract contract MerkleInstant_Integration_Shared_Test is MerkleCampaign_Integration_Shared_Test {
function setUp() public virtual override {
MerkleCampaign_Integration_Shared_Test.setUp();

// Cast the {merkleInstant} contract as {ISablierMerkleBase}
merkleBase = ISablierMerkleBase(merkleInstant);
}
}

/*//////////////////////////////////////////////////////////////////////////
SHARED TESTS
//////////////////////////////////////////////////////////////////////////*/

contract Clawback_MerkleLInstant_Integration_Test is
Clawback_Integration_Test,
MerkleInstant_Integration_Shared_Test
{
modifier afterFirstClaim() override {
// Make the first claim to set `_firstClaimTime`.
claimInstant();
_;
}

function setUp() public override(Clawback_Integration_Test, MerkleInstant_Integration_Shared_Test) {
Clawback_Integration_Test.setUp();
MerkleInstant_Integration_Shared_Test.setUp();
}
}

contract GetFirstClaimTime_MerkleLInstant_Integration_Test is
GetFirstClaimTime_Integration_Test,
MerkleInstant_Integration_Shared_Test
{
modifier afterFirstClaim() override {
// Make the first claim to set `_firstClaimTime`.
claimInstant();
_;
}

function setUp() public override(GetFirstClaimTime_Integration_Test, MerkleInstant_Integration_Shared_Test) {
GetFirstClaimTime_Integration_Test.setUp();
MerkleInstant_Integration_Shared_Test.setUp();
}
}

contract HasClaimed_MerkleLInstant_Integration_Test is
HasClaimed_Integration_Test,
MerkleInstant_Integration_Shared_Test
{
modifier givenRecipientHasClaimed() override {
// Make the first claim to set `_firstClaimTime`.
claimInstant();
_;
}

function setUp() public override(HasClaimed_Integration_Test, MerkleInstant_Integration_Shared_Test) {
HasClaimed_Integration_Test.setUp();
MerkleInstant_Integration_Shared_Test.setUp();
}
}

contract HasExpired_MerkleLInstant_Integration_Test is
HasExpired_Integration_Test,
MerkleInstant_Integration_Shared_Test
{
modifier createMerkleCampaignWithZeroExpiry() override {
campaignWithZeroExpiry = ISablierMerkleBase(createMerkleInstant({ expiration: 0 }));
_;
}

function setUp() public override(HasExpired_Integration_Test, MerkleInstant_Integration_Shared_Test) {
HasExpired_Integration_Test.setUp();
MerkleInstant_Integration_Shared_Test.setUp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Errors } from "src/periphery/libraries/Errors.sol";

import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";

contract Claim_Integration_Test is MerkleCampaign_Integration_Test {
contract Claim_MerkleInstant_Integration_Test is MerkleCampaign_Integration_Test {
function test_RevertGiven_CampaignExpired() external {
uint40 expiration = defaults.EXPIRATION();
uint256 warpTime = expiration + 1 seconds;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.22 <0.9.0;

import { SablierMerkleInstant } from "src/periphery/SablierMerkleInstant.sol";

import { MerkleCampaign_Integration_Test } from "../../MerkleCampaign.t.sol";
import { MerkleCampaign_Integration_Test } from "../MerkleCampaign.t.sol";

contract Constructor_MerkleInstant_Integration_Test is MerkleCampaign_Integration_Test {
/// @dev Needed to prevent "Stack too deep" error
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9c8ff1f

Please sign in to comment.