Skip to content

Commit e4ad4f9

Browse files
test: use mainnet addresses in fork tests (#1165)
* test: use mainnet address in fork testing * script: fix run modifiers * test: generate token holder locally in fork tests * refactor: rename script file names chore: use shorter version as amount * test: use shorter form to represent large number --------- Co-authored-by: Andrei Vlad Birgaoanu <andreivladbrg@gmail.com>
1 parent 835cac3 commit e4ad4f9

18 files changed

Lines changed: 60 additions & 61 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BaseScript } from "./Base.s.sol";
77

88
contract DeployBatchLockup is BaseScript {
99
/// @dev Deploy via Forge.
10-
function run() public virtual broadcast returns (SablierBatchLockup batchLockup) {
10+
function run() public broadcast returns (SablierBatchLockup batchLockup) {
1111
batchLockup = new SablierBatchLockup();
1212
}
1313
}

script/DeployDeterministicBatchLockup.t.sol renamed to script/DeployDeterministicBatchLockup.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BaseScript } from "./Base.s.sol";
77

88
contract DeployDeterministicBatchLockup is BaseScript {
99
/// @dev Deploy via Forge.
10-
function run() public virtual broadcast returns (SablierBatchLockup batchLockup) {
10+
function run() public broadcast returns (SablierBatchLockup batchLockup) {
1111
batchLockup = new SablierBatchLockup{ salt: SALT }();
1212
}
1313
}

‎script/DeployDeterministicLockup.s.sol‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ contract DeployDeterministicLockup is BaseScript {
1313
ILockupNFTDescriptor nftDescriptor
1414
)
1515
public
16-
virtual
1716
broadcast
1817
returns (SablierLockup lockup)
1918
{

‎script/DeployDeterministicNFTDescriptor.s.sol‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BaseScript } from "./Base.s.sol";
88
/// @dev Deploys {LockupNFTDescriptor} at a deterministic address across chains.
99
/// @dev Reverts if the contract has already been deployed.
1010
contract DeployDeterministicNFTDescriptor is BaseScript {
11-
function run() public virtual broadcast returns (LockupNFTDescriptor nftDescriptor) {
11+
function run() public broadcast returns (LockupNFTDescriptor nftDescriptor) {
1212
nftDescriptor = new LockupNFTDescriptor{ salt: SALT }();
1313
}
1414
}

‎script/DeployDeterministicProtocol.s.sol‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ contract DeployDeterministicProtocol is BaseScript {
1212
/// @dev Deploys the protocol with the admin set in `adminMap`.
1313
function run()
1414
public
15-
virtual
16-
broadcast
1715
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
1816
{
1917
address initialAdmin = adminMap[block.chainid];
@@ -22,7 +20,7 @@ contract DeployDeterministicProtocol is BaseScript {
2220

2321
/// @dev Deploys the protocol with the given `initialAdmin`.
2422
function run(address initialAdmin)
25-
internal
23+
public
2624
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
2725
{
2826
(nftDescriptor, lockup, batchLockup) = _run(initialAdmin);
@@ -31,6 +29,7 @@ contract DeployDeterministicProtocol is BaseScript {
3129
/// @dev Common logic for the run functions.
3230
function _run(address initialAdmin)
3331
internal
32+
broadcast
3433
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
3534
{
3635
batchLockup = new SablierBatchLockup{ salt: SALT }();

‎script/DeployLockup.s.sol‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ contract DeployLockup is BaseScript {
1313
ILockupNFTDescriptor nftDescriptor
1414
)
1515
public
16-
virtual
1716
broadcast
1817
returns (SablierLockup lockup)
1918
{

‎script/DeployNFTDescriptor.s.sol‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BaseScript } from "./Base.s.sol";
77

88
/// @notice Deploys {LockupNFTDescriptor} contract.
99
contract DeployNFTDescriptor is BaseScript {
10-
function run() public virtual broadcast returns (LockupNFTDescriptor nftDescriptor) {
10+
function run() public broadcast returns (LockupNFTDescriptor nftDescriptor) {
1111
nftDescriptor = new LockupNFTDescriptor();
1212
}
1313
}

‎script/DeployProtocol.s.sol‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ contract DeployProtocol is BaseScript {
1212
/// @dev Deploys the protocol with the admin set in `adminMap`.
1313
function run()
1414
public
15-
virtual
16-
broadcast
1715
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
1816
{
1917
address initialAdmin = adminMap[block.chainid];
@@ -22,7 +20,7 @@ contract DeployProtocol is BaseScript {
2220

2321
/// @dev Deploys the protocol with the given `initialAdmin`.
2422
function run(address initialAdmin)
25-
internal
23+
public
2624
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
2725
{
2826
(nftDescriptor, lockup, batchLockup) = _run(initialAdmin);
@@ -31,6 +29,7 @@ contract DeployProtocol is BaseScript {
3129
/// @dev Common logic for the run functions.
3230
function _run(address initialAdmin)
3331
internal
32+
broadcast
3433
returns (LockupNFTDescriptor nftDescriptor, SablierLockup lockup, SablierBatchLockup batchLockup)
3534
{
3635
batchLockup = new SablierBatchLockup();

‎script/GenerateSVG.s.sol‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract GenerateSVG is BaseScript, LockupNFTDescriptor {
2626
uint256 duration
2727
)
2828
public
29-
virtual
29+
view
3030
returns (string memory svg)
3131
{
3232
svg = NFTSVG.generateSVG(

‎tests/fork/Fork.t.sol‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ pragma solidity >=0.8.22 <0.9.0;
33

44
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
55
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import { ILockupNFTDescriptor } from "src/interfaces/ILockupNFTDescriptor.sol";
7+
import { ISablierBatchLockup } from "src/interfaces/ISablierBatchLockup.sol";
8+
import { ISablierLockup } from "src/interfaces/ISablierLockup.sol";
9+
610
import { Base_Test } from "./../Base.t.sol";
711

812
/// @notice Common logic needed by all fork tests.
@@ -12,16 +16,15 @@ abstract contract Fork_Test is Base_Test {
1216
//////////////////////////////////////////////////////////////////////////*/
1317

1418
IERC20 internal immutable FORK_TOKEN;
15-
address internal immutable FORK_TOKEN_HOLDER;
19+
address internal forkTokenHolder;
1620
uint256 internal initialHolderBalance;
1721

1822
/*//////////////////////////////////////////////////////////////////////////
1923
CONSTRUCTOR
2024
//////////////////////////////////////////////////////////////////////////*/
2125

22-
constructor(IERC20 forkToken, address forkTokenHolder) {
26+
constructor(IERC20 forkToken) {
2327
FORK_TOKEN = forkToken;
24-
FORK_TOKEN_HOLDER = forkTokenHolder;
2528
}
2629

2730
/*//////////////////////////////////////////////////////////////////////////
@@ -30,19 +33,24 @@ abstract contract Fork_Test is Base_Test {
3033

3134
function setUp() public virtual override {
3235
// Fork Ethereum Mainnet at a specific block number.
33-
vm.createSelectFork({ blockNumber: 20_428_723, urlOrAlias: "mainnet" });
36+
vm.createSelectFork({ blockNumber: 21_719_029, urlOrAlias: "mainnet" });
37+
38+
// Load deployed addresses from Ethereum mainnet.
39+
batchLockup = ISablierBatchLockup(0x3F6E8a8Cffe377c4649aCeB01e6F20c60fAA356c);
40+
nftDescriptor = ILockupNFTDescriptor(0xA9dC6878C979B5cc1d98a1803F0664ad725A1f56);
41+
lockup = ISablierLockup(0x7C01AA3783577E15fD7e272443D44B92d5b21056);
3442

35-
// The base is set up after the fork is selected so that the base test contracts are deployed on the fork.
36-
Base_Test.setUp();
43+
// Create a custom user for this test suite.
44+
forkTokenHolder = payable(makeAddr(string.concat(IERC20Metadata(address(FORK_TOKEN)).symbol(), "_HOLDER")));
3745

38-
// Label the contracts.
46+
// Label the addresses.
3947
labelContracts();
4048

41-
// Make the forked token holder the caller in this test suite.
42-
resetPrank({ msgSender: FORK_TOKEN_HOLDER });
49+
// Deal token balance to the user.
50+
initialHolderBalance = 1e7 * 10 ** IERC20Metadata(address(FORK_TOKEN)).decimals();
51+
deal({ token: address(FORK_TOKEN), to: forkTokenHolder, give: initialHolderBalance });
4352

44-
// Query the initial balance of the forked token holder.
45-
initialHolderBalance = FORK_TOKEN.balanceOf(FORK_TOKEN_HOLDER);
53+
resetPrank({ msgSender: forkTokenHolder });
4654
}
4755

4856
/*//////////////////////////////////////////////////////////////////////////
@@ -56,7 +64,7 @@ abstract contract Fork_Test is Base_Test {
5664

5765
// The goal is to not have overlapping users because the forked token balance tests would fail otherwise.
5866
vm.assume(sender != recipient && sender != broker && recipient != broker);
59-
vm.assume(sender != FORK_TOKEN_HOLDER && recipient != FORK_TOKEN_HOLDER && broker != FORK_TOKEN_HOLDER);
67+
vm.assume(sender != forkTokenHolder && recipient != forkTokenHolder && broker != forkTokenHolder);
6068
vm.assume(sender != lockupContract && recipient != lockupContract && broker != lockupContract);
6169

6270
// Avoid users blacklisted by USDC or USDT.
@@ -65,9 +73,9 @@ abstract contract Fork_Test is Base_Test {
6573
assumeNoBlacklisted(address(FORK_TOKEN), broker);
6674
}
6775

68-
/// @dev Labels the most relevant contracts.
76+
/// @dev Labels the most relevant addresses.
6977
function labelContracts() internal {
7078
vm.label({ account: address(FORK_TOKEN), newLabel: IERC20Metadata(address(FORK_TOKEN)).symbol() });
71-
vm.label({ account: FORK_TOKEN_HOLDER, newLabel: "FORK_TOKEN_HOLDER" });
79+
vm.label({ account: forkTokenHolder, newLabel: "Fork Token Holder" });
7280
}
7381
}

0 commit comments

Comments
 (0)