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

[SC-1130] Use Foundry for zkSync tests #76

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
143 changes: 71 additions & 72 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,72 +1,71 @@
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 482596)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 477903)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 183296)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 124816)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 22721)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 118055)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 27461)
EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 30180)
EscrowTest:test_CancelDst() (gas: 111132)
EscrowTest:test_CancelDstDifferentTarget() (gas: 145126)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93301)
EscrowTest:test_CancelPublicSrc() (gas: 161827)
EscrowTest:test_CancelResolverSrc() (gas: 164984)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 178399)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 160075)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 281819)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 116779)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 116517)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 160209)
EscrowTest:test_NoFailedNativeTokenTransferCancelDst() (gas: 127587)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 175588)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 149546)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 83044)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 193854)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 159368)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 121957)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 165273)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 171460)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 205450)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 170877)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 205342)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 157101)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 116460)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 121373)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 165819)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 117847)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 160684)
EscrowTest:test_PublicWithdrawSrc() (gas: 178118)
EscrowTest:test_RescueFundsDst() (gas: 153292)
EscrowTest:test_RescueFundsDstNative() (gas: 181840)
EscrowTest:test_RescueFundsSrc() (gas: 191847)
EscrowTest:test_RescueFundsSrcNative() (gas: 194063)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 136344)
EscrowTest:test_WithdrawByResolverDst() (gas: 137429)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97489)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 136775)
EscrowTest:test_WithdrawSrc() (gas: 182897)
EscrowTest:test_WithdrawSrcTo() (gas: 189947)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 348299)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 152295)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 360668)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 146699)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 371172)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 369711)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 156734)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 156168)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 389238)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 178082)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 361564)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 931771)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 930494)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 712017)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 938922)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 711647)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 308647)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 786038)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 445059)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 711970)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 929334)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 128572)
TimelocksLibTest:test_getStartTimestamps() (gas: 16176)
TimelocksLibTest:test_setDeployedAt() (gas: 5743)
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 482489)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 477799)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 183372)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 124743)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 22641)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 117983)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 27377)
EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 30064)
EscrowTest:test_CancelDst() (gas: 111112)
EscrowTest:test_CancelDstDifferentTarget() (gas: 142939)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93281)
EscrowTest:test_CancelPublicSrc() (gas: 161815)
EscrowTest:test_CancelResolverSrc() (gas: 164972)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 176242)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 160063)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 281809)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 116759)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 116519)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 160197)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 175576)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 149542)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 83024)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 308570)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 159378)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 121943)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 165261)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 171462)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 205434)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 170905)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 205351)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 157089)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 116459)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 121359)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 165822)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 117824)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 160694)
EscrowTest:test_PublicWithdrawSrc() (gas: 178106)
EscrowTest:test_RescueFundsDst() (gas: 153272)
EscrowTest:test_RescueFundsDstNative() (gas: 181829)
EscrowTest:test_RescueFundsSrc() (gas: 191851)
EscrowTest:test_RescueFundsSrcNative() (gas: 194051)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 136324)
EscrowTest:test_WithdrawByResolverDst() (gas: 137409)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97469)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 136755)
EscrowTest:test_WithdrawSrc() (gas: 182885)
EscrowTest:test_WithdrawSrcTo() (gas: 187768)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 343737)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 152267)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 356348)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 146632)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 366627)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 365296)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 156582)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 156154)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 384781)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 178039)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 357109)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 926652)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 925325)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 707482)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 933645)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 707079)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 303976)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 781280)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 440455)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 707437)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 924236)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 128398)
TimelocksLibTest:test_getStartTimestamps() (gas: 16180)
TimelocksLibTest:test_setDeployedAt() (gas: 5731)
22 changes: 20 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Check snapshot
run: forge snapshot --check --no-match-test "testFuzz_*"
run: FOUNDRY_PROFILE=default forge snapshot --check --no-match-test "testFuzz_*"

test:
runs-on: ubuntu-latest
Expand All @@ -36,7 +36,25 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Run tests
run: forge test -vvv --gas-report
run: FOUNDRY_PROFILE=default forge test -vvv --gas-report

test-zksync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/checkout@v4
with:
repository: matter-labs/foundry-zksync
ref: 'dev'
path: 'foundry-zksync'

- name: Install Foundry for zksync
run: cd foundry-zksync && ./install-foundry-zksync

- name: Run tests
run: FOUNDRY_PROFILE=zksync forge test -vvv --zksync

coverage:
runs-on: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions contracts/mocks/NoReceiveCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { RevertReasonForwarder } from "@1inch/solidity-utils/contracts/libraries/RevertReasonForwarder.sol";

contract NoReceiveCaller {
function arbitraryCall(address target, bytes calldata arguments) external {
// solhint-disable-next-line avoid-low-level-calls
(bool success,) = target.call(arguments);
if (!success) RevertReasonForwarder.reRevert();
}
}
7 changes: 7 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ wrap_comments = true

[fuzz]
runs = 1024

[profile.zksync]
src = 'contracts'
libs = ['lib']
fallback_oz = true
is_system = false
mode = "3"
2 changes: 1 addition & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
fi

printf "Running forge snapshot --diff... \n"
if forge snapshot --check --no-match-test "testFuzz_*" &>/dev/null; then
if FOUNDRY_PROFILE=default forge snapshot --check --no-match-test "testFuzz_*" &>/dev/null; then
printf "${GREEN}No gas difference${NC} \n"
else
printf "${RED}Gas difference${NC} Please run forge snapshot and add changes to the commit. \n"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
"lint": "solhint --max-warnings 0 \"contracts/**/*.sol\" \"test/**/*.sol\"",
"lint:js": "eslint .",
"lint:fix": "solhint --max-warnings 0 \"contracts/**/*.sol\" \"test/**/*.sol\" --fix",
"test": "forge snapshot --no-match-test \"testFuzz_*\" && forge test -vvv --gas-report",
"test:lite": "FOUNDRY_PROFILE=lite forge test -vvv"
"test": "FOUNDRY_PROFILE=default forge snapshot --no-match-test \"testFuzz_*\" && FOUNDRY_PROFILE=default forge test -vvv --gas-report",
"test:lite": "FOUNDRY_PROFILE=lite forge test -vvv",
"test:zksync": "FOUNDRY_PROFILE=zksync forge test -vvv --zksync"
},
"dependencies": {}
}
4 changes: 2 additions & 2 deletions test/integration/EscrowFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
false // allowMultipleFills
);

(uint8 v, bytes32 r, bytes32 s) = vm.sign(alice, orderHash);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alice.privateKey, orderHash);
bytes32 vs = bytes32((uint256(v - 27) << 255)) | s;

(TakerTraits takerTraits, bytes memory args) = _buildTakerTraits(
Expand Down Expand Up @@ -85,7 +85,7 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
/* IBaseEscrow.Immutables memory immutables */
) = _prepareDataSrc(HASHED_SECRET, MAKING_AMOUNT, TAKING_AMOUNT, SRC_SAFETY_DEPOSIT, DST_SAFETY_DEPOSIT, address(0), false, false);

(uint8 v, bytes32 r, bytes32 s) = vm.sign(alice, orderHash);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alice.privateKey, orderHash);
bytes32 vs = bytes32((uint256(v - 27) << 255)) | s;

(TakerTraits takerTraits, bytes memory args) = _buildTakerTraits(
Expand Down
Loading
Loading