Skip to content

Commit

Permalink
test: add fork test to check distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed May 7, 2024
1 parent e145663 commit 6342660
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 3 deletions.
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"files": "*.sol",
"options": {
"compiler": "0.8.23",
"parser": "solidity-parse",
"tabWidth": 4,
"singleQuote": false,
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ deploy-production:
deploy-local:
./set-epochs.sh -p dev && forge script script/DeployDev.s.sol --skip src --skip test --rpc-url localhost --broadcast --slow -vvv

deploy-fork:
./set-epochs.sh -p production && forge script script/DeployProduction.s.sol --skip src --skip test --rpc-url localhost --broadcast --slow -vvv

# Run slither
slither:
./set-epochs.sh -p production && FOUNDRY_PROFILE=production forge build --build-info --skip '*/test/**' --skip '*/script/**' --force && slither --compile-force-framework foundry --ignore-compile --sarif results.sarif --config-file slither.config.json .
Expand Down
10 changes: 7 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ depth = 25
fail_on_revert = true

[rpc_endpoints]
localhost = "http://127.0.0.1:8545"
sepolia = "https://rpc.sepolia.org"
mainnet = "https://eth.meowrpc.com"
localhost = "${LOCALHOST_RPC_URL}"
mainnet = "${MAINNET_RPC_URL}"
sepolia = "${SEPOLIA_RPC_URL}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api" }
sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api-sepolia.etherscan.io/api" }
69 changes: 69 additions & 0 deletions test/fork/Deploy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.23;

import { IERC20 } from "../../lib/protocol/lib/common/src/interfaces/IERC20.sol";

import { TestUtils } from "../utils/TestUtils.sol";

import { DeployBase } from "../../script/DeployBase.sol";

contract ForkTests is TestUtils, DeployBase {
uint256 public localhostFork;

// DeployProduction script address
address public deployer = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);

mapping(address account => uint256 balance) private _expectedInitialPowerBalances;
mapping(address account => uint256 balance) private _expectedInitialZeroBalances;

function setUp() public {
localhostFork = vm.createFork(vm.rpcUrl("localhost"));

uint256 initialPowerAccountsLength_ = _expectedInitialAccounts[0].length;
uint256 initialZeroAccountsLength_ = _expectedInitialAccounts[1].length;

while (initialPowerAccountsLength_ > 0) {
initialPowerAccountsLength_--;

_expectedInitialPowerBalances[
_expectedInitialAccounts[0][initialPowerAccountsLength_]
] += _expectedInitialBalances[0][initialPowerAccountsLength_];
}

while (initialZeroAccountsLength_ > 0) {
initialZeroAccountsLength_--;

_expectedInitialZeroBalances[
_expectedInitialAccounts[1][initialZeroAccountsLength_]
] += _expectedInitialBalances[1][initialZeroAccountsLength_];
}
}

function testFork_checkDistribution() public {
vm.selectFork(localhostFork);

_warpToNextEpoch();
_warpToNextEpoch();

IERC20 powerToken_ = IERC20(0xCafac3dD18aC6c6e92c921884f9E4176737C052c);
IERC20 zeroToken_ = IERC20(0x5FC8d32690cc91D4c39d9d3abcBD16989F875707);

uint256 initialPowerAccountsLength_ = _expectedInitialAccounts[0].length;
uint256 initialZeroAccountsLength_ = _expectedInitialAccounts[1].length;

while (initialPowerAccountsLength_ > 0) {
initialPowerAccountsLength_--;

address powerAccount_ = _expectedInitialAccounts[0][initialPowerAccountsLength_];
assertEq(powerToken_.balanceOf(powerAccount_), _expectedInitialPowerBalances[powerAccount_]);
}

while (initialZeroAccountsLength_ > 0) {
initialZeroAccountsLength_--;

address zeroAccount_ = _expectedInitialAccounts[1][initialZeroAccountsLength_];
assertEq(zeroToken_.balanceOf(zeroAccount_), _expectedInitialZeroBalances[zeroAccount_]);
}
}
}
Loading

0 comments on commit 6342660

Please sign in to comment.