-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from matter-labs/bh-EVM-216-move-l1-tests-to-f…
…oundry test: Move l1 tests to foundry Part-1
- Loading branch information
Showing
36 changed files
with
2,702 additions
and
1,575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "ethereum/lib/forge-std"] | ||
path = ethereum/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
/typechain | ||
node_modules | ||
./contracts/DS_Store | ||
/artifacts-forge | ||
/cache-forge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[profile.default] | ||
src = 'cache/solpp-generated-contracts' | ||
out = 'artifacts-forge' | ||
libs = ['node_modules', 'lib'] | ||
cache_path = 'cache-forge' | ||
test = 'test/foundry' | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ensdomains/=node_modules/@ensdomains/ | ||
@openzeppelin/=node_modules/@openzeppelin/ | ||
ds-test/=lib/forge-std/lib/ds-test/src/ | ||
eth-gas-reporter/=node_modules/eth-gas-reporter/ | ||
forge-std/=lib/forge-std/src/ | ||
hardhat/=node_modules/hardhat/ |
34 changes: 34 additions & 0 deletions
34
ethereum/test/foundry/unit/concrete/AllowList/AccessMode/DepositLimit.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
import {AccessModeTest} from "./_AccessMode_Shared.t.sol"; | ||
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol"; | ||
|
||
contract DepositLimitTest is AccessModeTest { | ||
address private l1token = makeAddr("l1token"); | ||
|
||
function test_RevertWhen_NonOwner() public { | ||
vm.expectRevert(abi.encodePacked("Ownable: caller is not the owner")); | ||
vm.prank(randomSigner); | ||
allowList.setDepositLimit(l1token, true, 1000); | ||
} | ||
|
||
function test_Owner() public { | ||
vm.prank(owner); | ||
allowList.setDepositLimit(l1token, true, 1000); | ||
|
||
IAllowList.Deposit memory deposit = allowList.getTokenDepositLimitData(l1token); | ||
assertEq(deposit.depositLimitation, true, "depositLimitation should be true"); | ||
assertEq(deposit.depositCap, 1000, "depositCap should be 1000"); | ||
} | ||
|
||
function test_UnlimitedToken() public { | ||
address unlimitedToken = makeAddr("unlimitedToken"); | ||
|
||
IAllowList.Deposit memory deposit = allowList.getTokenDepositLimitData(unlimitedToken); | ||
|
||
assertEq(deposit.depositLimitation, false, "depositLimitation should be false"); | ||
assertEq(deposit.depositCap, 0, "depositCap should be 0"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
ethereum/test/foundry/unit/concrete/AllowList/AccessMode/SetAccessMode.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
import {AccessModeTest} from "./_AccessMode_Shared.t.sol"; | ||
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol"; | ||
|
||
contract SetAccessModeTest is AccessModeTest { | ||
function test_RevertWhen_NonOwner() public { | ||
vm.expectRevert(abi.encodePacked("Ownable: caller is not the owner")); | ||
vm.prank(randomSigner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
} | ||
|
||
function test_Owner() public { | ||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
} | ||
|
||
function test_OwnerTwice() public { | ||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
|
||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
} | ||
|
||
function test_AccessModeBefore() public { | ||
bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig); | ||
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false"); | ||
|
||
IAllowList.AccessMode accessMode = allowList.getAccessMode(target); | ||
bool isClosed = accessMode == IAllowList.AccessMode.Closed; | ||
assertEq(isClosed, true, "AccessMode should be Closed"); | ||
|
||
bool canCall = allowList.canCall(owner, target, functionSig); | ||
assertEq(canCall, false, "canCall should be false"); | ||
} | ||
|
||
function test_AccessModeAfter() public { | ||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
|
||
bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig); | ||
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false"); | ||
|
||
IAllowList.AccessMode accessMode = allowList.getAccessMode(target); | ||
bool isPublic = accessMode == IAllowList.AccessMode.Public; | ||
assertEq(isPublic, true, "AccessMode should be Public"); | ||
|
||
bool canCall = allowList.canCall(owner, target, functionSig); | ||
assertEq(canCall, true, "canCall should be true"); | ||
} | ||
|
||
function test_RemovePermission() public { | ||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Closed); | ||
|
||
vm.prank(owner); | ||
allowList.setAccessMode(target, IAllowList.AccessMode.Public); | ||
|
||
bool hasSpecialAccessToCall = allowList.hasSpecialAccessToCall(owner, target, functionSig); | ||
assertEq(hasSpecialAccessToCall, false, "hasSpecialAccessToCall should be false"); | ||
|
||
IAllowList.AccessMode accessMode = allowList.getAccessMode(target); | ||
bool isPublic = accessMode == IAllowList.AccessMode.Public; | ||
assertEq(isPublic, true, "AccessMode should be Public"); | ||
|
||
bool canCall = allowList.canCall(owner, target, functionSig); | ||
assertEq(canCall, true, "canCall should be true"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ethereum/test/foundry/unit/concrete/AllowList/AccessMode/SetBatchAccessMode.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
import {AccessModeTest} from "./_AccessMode_Shared.t.sol"; | ||
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol"; | ||
|
||
contract SetBatchAccessModeTest is AccessModeTest { | ||
function test_RevertWhen_NonOwner() public { | ||
address[] memory targets = new address[](2); | ||
targets[0] = target; | ||
targets[1] = target; | ||
|
||
IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2); | ||
accessModes[0] = IAllowList.AccessMode.Public; | ||
accessModes[1] = IAllowList.AccessMode.Public; | ||
|
||
vm.expectRevert("Ownable: caller is not the owner"); | ||
vm.prank(randomSigner); | ||
allowList.setBatchAccessMode(targets, accessModes); | ||
} | ||
|
||
function test_Owner() public { | ||
address[] memory targets = new address[](2); | ||
targets[0] = target; | ||
targets[1] = target; | ||
|
||
IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2); | ||
accessModes[0] = IAllowList.AccessMode.Public; | ||
accessModes[1] = IAllowList.AccessMode.Public; | ||
|
||
vm.prank(owner); | ||
allowList.setBatchAccessMode(targets, accessModes); | ||
} | ||
|
||
function test_RevertWhen_ArrayLengthNotEqual() public { | ||
address[] memory targets = new address[](1); | ||
targets[0] = target; | ||
|
||
IAllowList.AccessMode[] memory accessModes = new IAllowList.AccessMode[](2); | ||
accessModes[0] = IAllowList.AccessMode.Public; | ||
accessModes[1] = IAllowList.AccessMode.Public; | ||
|
||
vm.expectRevert(abi.encodePacked("yg")); | ||
vm.prank(owner); | ||
allowList.setBatchAccessMode(targets, accessModes); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
ethereum/test/foundry/unit/concrete/AllowList/AccessMode/_AccessMode_Shared.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
import {AllowListTest} from "../_AllowList_Shared.t.sol"; | ||
|
||
contract AccessModeTest is AllowListTest { | ||
address internal target = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045; | ||
bytes4 internal functionSig = 0xdeadbeaf; | ||
} |
71 changes: 71 additions & 0 deletions
71
ethereum/test/foundry/unit/concrete/AllowList/Permission/SetBatchPermissionToCall.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.17; | ||
|
||
import {PermissionTest} from "./_Permission_Shared.t.sol"; | ||
|
||
contract SetBatchPermissionToCall is PermissionTest { | ||
function test_RevertWhen_NonOwner() public { | ||
address[] memory callers = new address[](2); | ||
callers[0] = owner; | ||
callers[1] = owner; | ||
|
||
address[] memory targets = new address[](2); | ||
targets[0] = target; | ||
targets[1] = target; | ||
|
||
bytes4[] memory functionSigs = new bytes4[](2); | ||
functionSigs[0] = functionSig; | ||
functionSigs[1] = functionSig; | ||
|
||
bool[] memory enables = new bool[](2); | ||
enables[0] = true; | ||
enables[1] = true; | ||
|
||
vm.expectRevert("Ownable: caller is not the owner"); | ||
vm.prank(randomSigner); | ||
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables); | ||
} | ||
|
||
function test_Owner() public { | ||
address[] memory callers = new address[](2); | ||
callers[0] = owner; | ||
callers[1] = owner; | ||
|
||
address[] memory targets = new address[](2); | ||
targets[0] = target; | ||
targets[1] = target; | ||
|
||
bytes4[] memory functionSigs = new bytes4[](2); | ||
functionSigs[0] = functionSig; | ||
functionSigs[1] = functionSig; | ||
|
||
bool[] memory enables = new bool[](2); | ||
enables[0] = true; | ||
enables[1] = true; | ||
|
||
vm.prank(owner); | ||
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables); | ||
} | ||
|
||
function test_RevertWhen_ArrayLengthNotEqual() public { | ||
address[] memory callers = new address[](1); | ||
callers[0] = owner; | ||
|
||
address[] memory targets = new address[](2); | ||
targets[0] = target; | ||
targets[1] = target; | ||
|
||
bytes4[] memory functionSigs = new bytes4[](2); | ||
functionSigs[0] = functionSig; | ||
functionSigs[1] = functionSig; | ||
|
||
bool[] memory enables = new bool[](2); | ||
enables[0] = true; | ||
enables[1] = true; | ||
|
||
vm.expectRevert(abi.encodePacked("yw")); | ||
vm.prank(owner); | ||
allowList.setBatchPermissionToCall(callers, targets, functionSigs, enables); | ||
} | ||
} |
Oops, something went wrong.