Skip to content

Commit

Permalink
Add Echidna support for local execution
Browse files Browse the repository at this point in the history
  • Loading branch information
matjazv committed Jun 18, 2024
1 parent a105603 commit 935ef05
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/properties"]
path = lib/properties
url = https://github.com/crytic/properties
[submodule "lib/openzeppelin-foundry-upgrades"]
path = lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
64 changes: 64 additions & 0 deletions test/fuzzing/L2Reward.echidna.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { PropertiesAsserts } from "properties/util/PropertiesHelper.sol";
import { L2LiskToken } from "src/L2/L2LiskToken.sol";
import { L2LockingPosition } from "src/L2/L2LockingPosition.sol";
import { L2Staking } from "src/L2/L2Staking.sol";

interface iHevm {
function prank(address sender) external;
}

contract L2RewardEchidnaTest is PropertiesAsserts {
L2Staking public l2Staking;
L2LockingPosition public l2LockingPosition;

iHevm public hevm;

constructor() {
hevm = iHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
address bridge = address(0x1234567890123456789012345678901234567890);
address remoteToken = address(0xaBcDef1234567890123456789012345678901234);

hevm.prank(msg.sender);
L2LiskToken l2LiskToken = new L2LiskToken(remoteToken);
l2LiskToken.initialize(bridge);

L2Staking l2StakingImplementation = new L2Staking();
l2Staking = L2Staking(
address(
new ERC1967Proxy(
address(l2StakingImplementation),
abi.encodeWithSelector(l2Staking.initialize.selector, address(l2LiskToken))
)
)
);

L2LockingPosition l2LockingPositionImplementation = new L2LockingPosition();
l2LockingPosition = L2LockingPosition(
address(
new ERC1967Proxy(
address(l2LockingPositionImplementation),
abi.encodeWithSelector(l2LockingPosition.initialize.selector, address(l2Staking))
)
)
);
}

function durationIsNeverLargerThanMax(uint256 lockID) public {
lockID = PropertiesAsserts.clampBetween(lockID, 1, 1000);
(,, uint256 expDate, uint256 pausedDuration) = l2LockingPosition.lockingPositions(lockID);
uint256 maxDuration = l2Staking.MAX_LOCKING_DURATION();
uint256 today = block.timestamp / 1 days;
PropertiesAsserts.assertWithMsg(
pausedDuration <= maxDuration, "The position paused duration is larger than max!"
);
if (expDate > today) {
PropertiesAsserts.assertWithMsg(
expDate - today <= maxDuration, "The position unpaused duration is larger than max!"
);
}
}
}
19 changes: 19 additions & 0 deletions test/scripts/runEchidna.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

echo "Instructing the shell to exit immediately if any command returns a non-zero exit status..."
set -e
echo "Done."

echo "Navigating to the root directory of the project..."
cd ../../
echo "Done."

if [ -z "$1" ]
then
echo "Please provide the contract name as the first argument."$'\n'"Exaxmple: runEchidna.sh <contract_name>"
exit 1
fi

echo "Starting Echidna tool..."
echidna test/fuzzing --workers 5 --contract $1 --corpus-dir test/fuzzing --format text --test-mode assertion --test-limit 5000000
echo "Done."

0 comments on commit 935ef05

Please sign in to comment.