Skip to content

Commit

Permalink
refactor: integration tests addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Nov 7, 2023
1 parent 76049b1 commit d6c6743
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
27 changes: 12 additions & 15 deletions test/helpers/Fixtures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,21 @@ contract Fixtures is StdCheats {
contract IntegrationFixtures is StdCheats, Test {
struct Env {
string RPC_URL;
string LIDO_LOCATOR_ADDRESS;
string WSTETH_ADDRESS;
}

address internal immutable LOCATOR_ADDRESS =
0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb;
address internal immutable WSTETH_ADDRESS =
0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;

function envVars() public returns (Env memory) {
Env memory env = Env(
vm.envOr("RPC_URL", string("")),
vm.envOr("LIDO_LOCATOR_ADDRESS", string("")),
vm.envOr("WSTETH_ADDRESS", string(""))
);
vm.skip(
keccak256(abi.encodePacked(env.RPC_URL)) ==
keccak256(abi.encodePacked("")) ||
keccak256(abi.encodePacked(env.LIDO_LOCATOR_ADDRESS)) ==
keccak256(abi.encodePacked("")) ||
keccak256(abi.encodePacked(env.WSTETH_ADDRESS)) ==
keccak256(abi.encodePacked(""))
);
Env memory env = Env(vm.envOr("RPC_URL", string("")));
vm.skip(_isEmpty(env.RPC_URL));
return env;
}

function _isEmpty(string memory s) internal pure returns (bool) {
return
keccak256(abi.encodePacked(s)) == keccak256(abi.encodePacked(""));
}
}
6 changes: 6 additions & 0 deletions test/helpers/Utilities.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ contract Utilities {
}
return (keys, signatures);
}

function checkChainId(uint256 chainId) public view {
if (chainId != block.chainid) {
revert("wrong chain id");
}
}
}
20 changes: 14 additions & 6 deletions test/integration/DepositInTokens.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
pragma solidity 0.8.21;

import "forge-std/Test.sol";

import { CSModule } from "../../src/CSModule.sol";
import { CSAccounting } from "../../src/CSAccounting.sol";
import { PermitHelper } from "../helpers/Permit.sol";
import { CommunityStakingModuleMock } from "../helpers/mocks/CommunityStakingModuleMock.sol";
import { IWstETH } from "../../src/interfaces/IWstETH.sol";
import { ILido } from "../../src/interfaces/ILido.sol";
import { ILidoLocator } from "../../src/interfaces/ILidoLocator.sol";
import "../helpers/Fixtures.sol";
import { Utilities } from "../helpers/Utilities.sol";
import { PermitHelper } from "../helpers/Permit.sol";
import { IntegrationFixtures } from "../helpers/Fixtures.sol";
import { CommunityStakingModuleMock } from "../helpers/mocks/CommunityStakingModuleMock.sol";

contract DepositIntegrationTest is Test, PermitHelper, IntegrationFixtures {
contract DepositIntegrationTest is
Test,
Utilities,
PermitHelper,
IntegrationFixtures
{
uint256 networkFork;

CommunityStakingModuleMock public csm;
Expand All @@ -32,11 +39,12 @@ contract DepositIntegrationTest is Test, PermitHelper, IntegrationFixtures {

networkFork = vm.createFork(env.RPC_URL);
vm.selectFork(networkFork);
checkChainId(1);

locator = ILidoLocator(vm.parseAddress(env.LIDO_LOCATOR_ADDRESS));
locator = ILidoLocator(LOCATOR_ADDRESS);
csm = new CommunityStakingModuleMock();

wstETH = IWstETH(vm.parseAddress(env.WSTETH_ADDRESS));
wstETH = IWstETH(WSTETH_ADDRESS);

userPrivateKey = 0xa11ce;
user = vm.addr(userPrivateKey);
Expand Down
10 changes: 6 additions & 4 deletions test/integration/StakingRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
pragma solidity 0.8.21;

import "forge-std/Test.sol";

import { CSModule, NodeOperator } from "../../src/CSModule.sol";
import { ILidoLocator } from "../../src/interfaces/ILidoLocator.sol";
import { IStakingRouter } from "../../src/interfaces/IStakingRouter.sol";
import { CSAccounting } from "../../src/CSAccounting.sol";
import { ILido } from "../../src/interfaces/ILido.sol";
import { IWstETH } from "../../src/interfaces/IWstETH.sol";
import "../helpers/Utilities.sol";
import "../helpers/Fixtures.sol";
import { Utilities } from "../helpers/Utilities.sol";
import { IntegrationFixtures } from "../helpers/Fixtures.sol";

contract StakingRouterIntegrationTest is Test, Utilities, IntegrationFixtures {
uint256 networkFork;
Expand All @@ -29,11 +30,12 @@ contract StakingRouterIntegrationTest is Test, Utilities, IntegrationFixtures {

networkFork = vm.createFork(env.RPC_URL);
vm.selectFork(networkFork);
checkChainId(1);

locator = ILidoLocator(vm.parseAddress(env.LIDO_LOCATOR_ADDRESS));
locator = ILidoLocator(LOCATOR_ADDRESS);
stakingRouter = IStakingRouter(payable(locator.stakingRouter()));
lido = ILido(locator.lido());
wstETH = IWstETH(vm.parseAddress(env.WSTETH_ADDRESS));
wstETH = IWstETH(WSTETH_ADDRESS);
vm.label(address(lido), "lido");
vm.label(address(stakingRouter), "stakingRouter");

Expand Down

0 comments on commit d6c6743

Please sign in to comment.