Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update halmos tests for new version #692

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/halmos-cheatcodes
Submodule halmos-cheatcodes updated 1 files
+11 −0 src/SVM.sol
37 changes: 25 additions & 12 deletions test/halmos/HalmosTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {IMorpho} from "../../src/interfaces/IMorpho.sol";
import {IrmMock} from "../../src/mocks/IrmMock.sol";
import {ERC20Mock} from "../../src/mocks/ERC20Mock.sol";
import {OracleMock} from "../../src/mocks/OracleMock.sol";
import {FlashBorrowerMock} from "../../src/mocks/FlashBorrowerMock.sol";

import "../../src/Morpho.sol";
import "../../src/libraries/ConstantsLib.sol";
import {MorphoLib} from "../../src/libraries/periphery/MorphoLib.sol";

/// @custom:halmos --symbolic-storage --solver-timeout-assertion 0
/// @custom:halmos --solver-timeout-assertion 0
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
contract HalmosTest is SymTest, Test {
using MorphoLib for IMorpho;
using MarketParamsLib for MarketParams;
Expand All @@ -29,6 +30,9 @@ contract HalmosTest is SymTest, Test {

MarketParams internal marketParams;

ERC20Mock internal otherToken;
FlashBorrowerMock internal flashBorrower;

function setUp() public virtual {
owner = svm.createAddress("owner");
morpho = IMorpho(address(new Morpho(owner)));
Expand All @@ -47,6 +51,23 @@ contract HalmosTest is SymTest, Test {
morpho.enableLltv(lltv);
morpho.createMarket(marketParams);
vm.stopPrank();

// for flashLoan
otherToken = new ERC20Mock();
flashBorrower = new FlashBorrowerMock(morpho);
QGarchery marked this conversation as resolved.
Show resolved Hide resolved

// Enable symbolic storage
svm.enableSymbolicStorage(address(morpho));
svm.enableSymbolicStorage(address(loanToken));
svm.enableSymbolicStorage(address(collateralToken));
svm.enableSymbolicStorage(address(oracle));
svm.enableSymbolicStorage(address(irm));
svm.enableSymbolicStorage(address(otherToken));
svm.enableSymbolicStorage(address(flashBorrower));
daejunpark marked this conversation as resolved.
Show resolved Hide resolved

// Set symbolic block number and timestamp
vm.roll(svm.createUint(64, "block.number"));
vm.warp(svm.createUint(64, "block.timestamp"));
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
}

// Call Morpho, assuming interacting with only the defined market for performance reasons.
Expand Down Expand Up @@ -74,17 +95,9 @@ contract HalmosTest is SymTest, Test {
address borrower = svm.createAddress("borrower");
args = abi.encode(marketParams, borrower, assets, shares, emptyData);
} else if (selector == morpho.flashLoan.selector) {
uint256 rand = svm.createUint256("rand");
address token;
if (rand == 0) {
token = address(loanToken);
} else if (rand == 1) {
token = address(collateralToken);
} else {
ERC20Mock otherToken = new ERC20Mock();
token = address(otherToken);
}
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
args = abi.encode(marketParams, token, assets, emptyData);
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
address token = svm.createAddress("token");
bytes memory _data = svm.createBytes(1024, "_data");
args = abi.encode(token, assets, _data);
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
} else if (selector == morpho.accrueInterest.selector) {
args = abi.encode(marketParams);
} else if (selector == morpho.setFee.selector) {
Expand Down
Loading