Skip to content

Commit

Permalink
Merge pull request #88 from 1inch/chore/Separate-library
Browse files Browse the repository at this point in the history
Separate library for tests
  • Loading branch information
byshape authored Jul 30, 2024
2 parents b3acc0f + 90c7443 commit ccce099
Show file tree
Hide file tree
Showing 12 changed files with 1,217 additions and 1,460 deletions.
140 changes: 70 additions & 70 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 477392)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 472722)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 183965)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 119657)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 22658)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 112896)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 27394)
EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 30108)
EscrowTest:test_CancelDst() (gas: 111454)
EscrowTest:test_CancelDstDifferentTarget() (gas: 143281)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93611)
EscrowTest:test_CancelPublicSrc() (gas: 156600)
EscrowTest:test_CancelResolverSrc() (gas: 159757)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 170942)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 154958)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 277046)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 117101)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 116861)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 155092)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 170449)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 149884)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 83354)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 303443)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 154273)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 122285)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 160156)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 171804)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 200175)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 171247)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 200092)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 151984)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 116801)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 121701)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 160717)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 118166)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 155589)
EscrowTest:test_PublicWithdrawSrc() (gas: 172891)
EscrowTest:test_RescueFundsDst() (gas: 153614)
EscrowTest:test_RescueFundsDstNative() (gas: 182171)
EscrowTest:test_RescueFundsSrc() (gas: 186570)
EscrowTest:test_RescueFundsSrcNative() (gas: 188836)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 136666)
EscrowTest:test_WithdrawByResolverDst() (gas: 137751)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97799)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 137097)
EscrowTest:test_WithdrawSrc() (gas: 177670)
EscrowTest:test_WithdrawSrcTo() (gas: 182509)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 470984)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 338739)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 152609)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 351046)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 146974)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 361519)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 360087)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 156924)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 156496)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 379602)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 178381)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 352052)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 921492)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 920173)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 704406)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 930326)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 704142)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 298851)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 776050)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 437381)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 704285)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 918885)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 128740)
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 478531)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 473846)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 190767)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 128468)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 27118)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 121693)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 27377)
EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 34474)
EscrowTest:test_CancelDst() (gas: 116028)
EscrowTest:test_CancelDstDifferentTarget() (gas: 143286)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93622)
EscrowTest:test_CancelPublicSrc() (gas: 165442)
EscrowTest:test_CancelResolverSrc() (gas: 168586)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 179340)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 163829)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 286452)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 121678)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 121438)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 163938)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 179317)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 154458)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 83365)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 312313)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 163124)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 126855)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169069)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 176275)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 209062)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 175685)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 209019)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 160840)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 121384)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 126271)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169632)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 122749)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 164468)
EscrowTest:test_PublicWithdrawSrc() (gas: 181745)
EscrowTest:test_RescueFundsDst() (gas: 158179)
EscrowTest:test_RescueFundsDstNative() (gas: 186642)
EscrowTest:test_RescueFundsSrc() (gas: 195445)
EscrowTest:test_RescueFundsSrcNative() (gas: 197721)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 141240)
EscrowTest:test_WithdrawByResolverDst() (gas: 142325)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97810)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 141671)
EscrowTest:test_WithdrawSrc() (gas: 186512)
EscrowTest:test_WithdrawSrcTo() (gas: 191326)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 473480)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 341110)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 157108)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 354513)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 151449)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 365558)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 392497)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 164765)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 161014)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 382547)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 182848)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 355389)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 923881)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 922554)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 706697)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 932899)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 706419)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 301339)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 778527)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 439187)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 706707)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 921368)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 133743)
TimelocksLibTest:test_getStartTimestamps() (gas: 16180)
TimelocksLibTest:test_setDeployedAt() (gas: 5731)
90 changes: 35 additions & 55 deletions test/integration/EscrowFactory.t.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import { IEscrowFactory } from "../../contracts/interfaces/IEscrowFactory.sol";
import { IBaseEscrow } from "../../contracts/interfaces/IBaseEscrow.sol";
import { TakerTraits } from "limit-order-protocol/contracts/libraries/TakerTraitsLib.sol";
import { Address } from "solidity-utils/contracts/libraries/AddressLib.sol";

import { Address, AddressLib, BaseSetup, IOrderMixin, TakerTraits } from "../utils/BaseSetup.sol";
import { IEscrowFactory } from "contracts/interfaces/IEscrowFactory.sol";

contract IntegrationEscrowFactoryTest is BaseSetup {
using AddressLib for Address;
import { BaseSetup } from "../utils/BaseSetup.sol";
import { CrossChainTestLib } from "../utils/libraries/CrossChainTestLib.sol";

contract IntegrationEscrowFactoryTest is BaseSetup {
function setUp() public virtual override {
BaseSetup.setUp();
}
Expand All @@ -20,47 +21,40 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
uint256 srcSafetyDeposit = uint256(srcAmount) * 10 / 100;
uint256 dstSafetyDeposit = uint256(dstAmount) * 10 / 100;

(
IOrderMixin.Order memory order,
bytes32 orderHash,
/* bytes memory extraData */,
bytes memory extension,
IBaseEscrow srcClone,
/* IBaseEscrow.Immutables memory immutables */
) = _prepareDataSrc(
CrossChainTestLib.SwapData memory swapData = _prepareDataSrcCustom(
keccak256(abi.encode(secret)),
srcAmount,
dstAmount,
srcSafetyDeposit,
dstSafetyDeposit,
address(0),
address(0), // receiver
false, // fakeOrder
false // allowMultipleFills
);

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

(TakerTraits takerTraits, bytes memory args) = _buildTakerTraits(
(TakerTraits takerTraits, bytes memory args) = CrossChainTestLib.buildTakerTraits(
true, // makingAmount
false, // unwrapWeth
false, // skipMakerPermit
false, // usePermit2
address(srcClone), // target
extension, // extension
address(swapData.srcClone), // target
swapData.extension, // extension
"", // interaction
0 // threshold
);

{
(bool success,) = address(srcClone).call{ value: uint64(srcAmount) * 10 / 100 }("");
(bool success,) = address(swapData.srcClone).call{ value: uint64(srcAmount) * 10 / 100 }("");
assertEq(success, true);

uint256 resolverCredit = feeBank.availableCredit(bob.addr);

vm.prank(bob.addr);
limitOrderProtocol.fillOrderArgs(
order,
swapData.order,
r,
vs,
srcAmount, // amount
Expand All @@ -71,39 +65,32 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
assertEq(feeBank.availableCredit(bob.addr), resolverCredit);
}

assertEq(usdc.balanceOf(address(srcClone)), srcAmount);
assertEq(address(srcClone).balance, srcSafetyDeposit);
assertEq(usdc.balanceOf(address(swapData.srcClone)), srcAmount);
assertEq(address(swapData.srcClone).balance, srcSafetyDeposit);
}

function test_DeployCloneForMakerNonWhitelistedResolverInt() public {
(
IOrderMixin.Order memory order,
bytes32 orderHash,
/* bytes memory extraData */,
bytes memory extension,
IBaseEscrow srcClone,
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.privateKey, orderHash);
CrossChainTestLib.SwapData memory swapData = _prepareDataSrc(false, false);

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

immutables.taker = Address.wrap(uint160(charlie.addr));
srcClone = IBaseEscrow(escrowFactory.addressOfEscrowSrc(immutables));
swapData.immutables.taker = Address.wrap(uint160(charlie.addr));
address srcClone = escrowFactory.addressOfEscrowSrc(swapData.immutables);

(TakerTraits takerTraits, bytes memory args) = _buildTakerTraits(
(TakerTraits takerTraits, bytes memory args) = CrossChainTestLib.buildTakerTraits(
true, // makingAmount
false, // unwrapWeth
false, // skipMakerPermit
false, // usePermit2
address(srcClone), // target
extension, // extension
srcClone, // target
swapData.extension, // extension
"", // interaction
0 // threshold
);

{
(bool success,) = address(srcClone).call{ value: SRC_SAFETY_DEPOSIT }("");
(bool success,) = srcClone.call{ value: SRC_SAFETY_DEPOSIT }("");
assertEq(success, true);

uint256 resolverCredit = feeBank.availableCredit(bob.addr);
Expand All @@ -113,7 +100,7 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
inch.approve(address(feeBank), 1000 ether);
feeBank.deposit(10 ether);
limitOrderProtocol.fillOrderArgs(
order,
swapData.order,
r,
vs,
MAKING_AMOUNT, // amount
Expand All @@ -125,41 +112,34 @@ contract IntegrationEscrowFactoryTest is BaseSetup {
assertLt(feeBank.availableCredit(charlie.addr), resolverCredit);
}

assertEq(usdc.balanceOf(address(srcClone)), MAKING_AMOUNT);
assertEq(address(srcClone).balance, SRC_SAFETY_DEPOSIT);
assertEq(usdc.balanceOf(srcClone), MAKING_AMOUNT);
assertEq(srcClone.balance, SRC_SAFETY_DEPOSIT);
}

function test_NoInsufficientBalanceDeploymentForMakerInt() public {
(
IOrderMixin.Order memory order,
bytes32 orderHash,
/* bytes memory extraData */,
bytes memory extension,
IBaseEscrow srcClone,
/* 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.privateKey, orderHash);
CrossChainTestLib.SwapData memory swapData = _prepareDataSrc(false, false);

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

(TakerTraits takerTraits, bytes memory args) = _buildTakerTraits(
(TakerTraits takerTraits, bytes memory args) = CrossChainTestLib.buildTakerTraits(
true, // makingAmount
false, // unwrapWeth
false, // skipMakerPermit
false, // usePermit2
address(0), // target
extension, // extension
swapData.extension, // extension
"", // interaction
0 // threshold
);

(bool success,) = address(srcClone).call{ value: SRC_SAFETY_DEPOSIT }("");
(bool success,) = address(swapData.srcClone).call{ value: SRC_SAFETY_DEPOSIT }("");
assertEq(success, true);

vm.prank(bob.addr);
vm.expectRevert(IEscrowFactory.InsufficientEscrowBalance.selector);
limitOrderProtocol.fillOrderArgs(
order,
swapData.order,
r,
vs,
MAKING_AMOUNT, // amount
Expand Down
Loading

0 comments on commit ccce099

Please sign in to comment.