Skip to content

Commit

Permalink
Invariant testing campaign (#29)
Browse files Browse the repository at this point in the history
* chore: add solmate.

* feat: add mock for stETH.

* feat: add mock for Lido Withdraw.

* fix: cleanup variables

* feat: create shared contract for invariant.

* [WIP] feat: add handler logic.

* feat: add more users.

* [WIP] feat: add distribution handler.

* chore: add invariant config

* fix: address null user bug.

* feat: add LP Handler.

* [WIP]: feat: swapHandler.

* feat: add swapTokensForExactTokens to handler.

* fix: adjust handler  weight.

* fix: set default verbosity to 3.

* fix: adjust console log

* feat: add Owner handler.

* fix: account withdraw queue in available liquidity.

* fix: adjust failing tx.

* fix: use vm to send ETH instead of .call.

* feat: add Lido Liquidity Manager Handler.

* feat: check preview return corerct amount.

* fix: use correct price

* fix: adjust new availableTotalAssets

* chore: use --fail-fast for test

* [WIP] feat: add first invariants.

* [WIP] feat: add more invariants.

* [WIP] feat: adjust handler and add more invariants.

* [WIP] feat: add invariant for lido liquidity manager.

* feat: add donation handler.

* test: add new concrete scenario test.

* test: fix CI.

* try to fix CI.

* test[invariant]: ensure enough liquiidty before claiming fees.

* chore: add --show-progress for `make test`

* test[invariant]: adjust `withdrawsClaimable` removal.

* fix: use aproxEq instead of Eq due to rounding error

* chore: remove --show-progress

* test[invariant]: only request when there is enough liquidity

* test[invariant]: add more invariant.

* fix: remove wrong invariant.

* fix: adjust with latest update.

* test: adjust with lastest update.

* test[invariant]: use owner to set price.

* chore: add --show-progress for tests.

* fix: use new claimDelay.

* docs: adjust comments.

* test[invariant]: add setCrossPrice to handlers.

* test[invariant]: adjust test.

* forge fmt

* feat: add stats for invariants.

* chore: ignore warning in Proxy.sol.

* fix: adjust with new variable name.

* test[invariant]: adjust swap handler with latest update.

* fix: import console.

* fix: adjust claimResquest for invariant.

* test[invariant]: WIP.

* test[invariant]: add LLM to invariant.

* test[invariant]: adjust owner handler.

* perf: optimize calls for logs.

* perf: adjust % for call distribution.

* feat: add skip %.

* test[invariant]: adjust last invariant.

* fix: log stat bool.

* test[invariant]: up only shares values invariant.

* fix: adjust type uint120 to uint128

* fix: prevetn setCrossPrice to revert.

* feat: remove all user funds after invariants.

* test[invariant]: add approx up-only invariant [WIP]

* test[invariant]: add invariant for approx up-only.

* docs: adjust natspec and description.

* forge fmt

* fix: increase error tolerance.
  • Loading branch information
clement-ux authored Oct 16, 2024
1 parent 77321c0 commit 5883df2
Show file tree
Hide file tree
Showing 16 changed files with 2,038 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ snapshot:

# Tests
test:
@forge test --summary
@forge test --summary --fail-fast --show-progress

test-f-%:
@FOUNDRY_MATCH_TEST=$* make test
Expand Down
9 changes: 9 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ auto_detect_remappings = false
gas_reports = ["OEthARM", "Proxy"]
fs_permissions = [{ access = "read-write", path = "./build" }]
extra_output_files = ["metadata"]
ignored_warnings_from = ["src/contracts/Proxy.sol"]
remappings = [
"contracts/=./src/contracts",
"script/=./script",
Expand All @@ -17,15 +18,23 @@ remappings = [
"forge-std/=dependencies/forge-std-1.9.2/src/",
"@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.0.2/",
"@openzeppelin/contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.0.2/",
"@solmate/=dependencies/solmate-6.7.0/src/",
]

[fuzz]
runs = 1_000

[invariant]
runs = 256
depth = 500
fail_on_revert = true
shrink_run_limit = 5_000

[dependencies]
"@openzeppelin-contracts" = "5.0.2"
"@openzeppelin-contracts-upgradeable" = "5.0.2"
forge-std = { version = "1.9.2", git = "https://github.com/foundry-rs/forge-std.git", rev = "5a802d7c10abb4bbfb3e7214c75052ef9e6a06f8" }
solmate = "6.7.0"

[soldeer]
recursive_deps = false
Expand Down
49 changes: 48 additions & 1 deletion test/Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ abstract contract Base_Test_ is Test {
Proxy public proxy;
Proxy public lpcProxy;
Proxy public lidoProxy;
Proxy public lidoOwnerProxy;
OethARM public oethARM;
LidoARM public lidoARM;
CapManager public capManager;
Expand All @@ -51,11 +50,20 @@ abstract contract Base_Test_ is Test {
/// --- Governance, multisigs and EOAs
//////////////////////////////////////////////////////
address public alice;
address public bob;
address public charlie;
address public dave;
address public eve;
address public frank;
address public george;
address public harry;

address public deployer;
address public governor;
address public operator;
address public oethWhale;
address public feeCollector;
address public lidoWithdraw;

//////////////////////////////////////////////////////
/// --- DEFAULT VALUES
Expand All @@ -70,4 +78,43 @@ abstract contract Base_Test_ is Test {
function setUp() public virtual {
resolver = new AddressResolver();
}

/// @notice Better if called once all contract have been depoyed.
function labelAll() public virtual {
// Contracts
_labelNotNull(address(proxy), "DEFAULT PROXY");
_labelNotNull(address(lpcProxy), "LPC PROXY");
_labelNotNull(address(lidoProxy), "LIDO ARM PROXY");
_labelNotNull(address(oethARM), "OETH ARM");
_labelNotNull(address(lidoARM), "LIDO ARM");
_labelNotNull(address(capManager), "CAP MANAGER");

_labelNotNull(address(oeth), "OETH");
_labelNotNull(address(weth), "WETH");
_labelNotNull(address(steth), "STETH");
_labelNotNull(address(wsteth), " WRAPPED STETH");
_labelNotNull(address(badToken), "BAD TOKEN");
_labelNotNull(address(vault), "OETH VAULT");

// Governance, multisig and EOAs
_labelNotNull(alice, "Alice");
_labelNotNull(bob, "Bob");
_labelNotNull(charlie, "Charlie");
_labelNotNull(dave, "Dave");
_labelNotNull(eve, "Eve");
_labelNotNull(frank, "Frank");
_labelNotNull(george, "George");
_labelNotNull(harry, "Harry");

_labelNotNull(deployer, "Deployer");
_labelNotNull(governor, "Governor");
_labelNotNull(operator, "Operator");
_labelNotNull(oethWhale, "OETH Whale");
_labelNotNull(feeCollector, "Fee Collector");
_labelNotNull(lidoWithdraw, "Lido Withdraw");
}

function _labelNotNull(address _address, string memory _name) internal {
if (_address != address(0)) vm.label(_address, _name);
}
}
1 change: 0 additions & 1 deletion test/fork/shared/Shared.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ abstract contract Fork_Shared_Test_ is Modifiers {
proxy = new Proxy();
lpcProxy = new Proxy();
lidoProxy = new Proxy();
lidoOwnerProxy = new Proxy();

// --- Deploy OethARM implementation ---
// Deploy OethARM implementation.
Expand Down
Loading

0 comments on commit 5883df2

Please sign in to comment.