From f2c826d507f0408de2d0321f8a85e0092d18c62c Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Thu, 12 Oct 2023 16:51:53 +0300 Subject: [PATCH 1/4] test: add Target_Integration_Test contract test: move target helpers from Base_Test Target_Integration_Test test: move some merkle streamer helpers in MerkleStreamer_Integration_Test test: add approveContracts helper function in Base_Test --- test/Base.t.sol | 159 ++---------------- test/fork/Fork.t.sol | 10 +- test/fork/target/batchCancelMultiple.t.sol | 12 +- test/integration/Integration.t.sol | 12 +- .../merkle-streamer/MerkleStreamer.t.sol | 16 ++ .../on-stream-canceled/onStreamCanceled.t.sol | 3 +- test/integration/target/Target.t.sol | 138 +++++++++++++++ .../batchCancelMultiple.t.sol | 4 +- .../batchCreateWithDeltas.t.sol | 4 +- .../batchCreateWithDurations.t.sol | 4 +- .../batchCreateWithMilestones.t.sol | 4 +- .../batchCreateWithRange.t.sol | 4 +- test/integration/target/burn/burn.t.sol | 4 +- .../cancel-and-create/cancelAndCreate.t.sol | 4 +- .../cancel-multiple/cancelMultiple.t.sol | 4 +- test/integration/target/cancel/cancel.t.sol | 4 +- .../target/renounce/renounce.t.sol | 4 +- .../withdrawMaxAndTransfer.t.sol | 4 +- .../target/withdraw-max/withdrawMax.t.sol | 4 +- .../withdraw-multiple/withdrawMultiple.t.sol | 4 +- .../target/withdraw/withdraw.t.sol | 4 +- .../wrap-and-create/wrapAndCreate.t.sol | 4 +- test/utils/Defaults.sol | 2 +- 23 files changed, 214 insertions(+), 198 deletions(-) create mode 100644 test/integration/target/Target.t.sol diff --git a/test/Base.t.sol b/test/Base.t.sol index a4841d50..3a8c00e7 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -94,6 +94,19 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil HELPERS //////////////////////////////////////////////////////////////////////////*/ + /// @dev Approves relevant contracts to spend assets from some users. + function approveContracts() internal { + // Approve Permit2 to spend assets from the stream's recipient. + vm.startPrank({ msgSender: users.recipient0.addr }); + asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); + + // Approve Permit2, SablierV2Batch and Alice's Proxy to spend assets from Alice (the proxy owner). + changePrank({ msgSender: users.alice.addr }); + asset.approve({ spender: address(batch), amount: MAX_UINT256 }); + asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); + asset.approve({ spender: address(aliceProxy), amount: MAX_UINT256 }); + } + /// @dev Generates a user, labels its address, and funds it with ETH. function createUser(string memory name) internal returns (Account memory user) { user = makeAccount(name); @@ -375,22 +388,6 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil MERKLE-STREAMER //////////////////////////////////////////////////////////////////////////*/ - function computeMerkleStreamerLLAddress() internal returns (address) { - return computeMerkleStreamerLLAddress(users.admin.addr, defaults.MERKLE_ROOT(), defaults.EXPIRATION()); - } - - function computeMerkleStreamerLLAddress(address admin) internal returns (address) { - return computeMerkleStreamerLLAddress(admin, defaults.MERKLE_ROOT(), defaults.EXPIRATION()); - } - - function computeMerkleStreamerLLAddress(address admin, uint40 expiration) internal returns (address) { - return computeMerkleStreamerLLAddress(admin, defaults.MERKLE_ROOT(), expiration); - } - - function computeMerkleStreamerLLAddress(address admin, bytes32 merkleRoot) internal returns (address) { - return computeMerkleStreamerLLAddress(admin, merkleRoot, defaults.EXPIRATION()); - } - function computeMerkleStreamerLLAddress( address admin, bytes32 merkleRoot, @@ -435,134 +432,4 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil ); } } - - /*////////////////////////////////////////////////////////////////////////// - TARGET - //////////////////////////////////////////////////////////////////////////*/ - - function batchCreateWithDeltas() internal returns (uint256[] memory) { - bytes memory data = abi.encodeCall( - target.batchCreateWithDeltas, - (lockupDynamic, asset, defaults.batchCreateWithDeltas(), getTransferData(defaults.TOTAL_TRANSFER_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function batchCreateWithDurations() internal returns (uint256[] memory) { - bytes memory data = abi.encodeCall( - target.batchCreateWithDurations, - ( - lockupLinear, - asset, - defaults.batchCreateWithDurations(), - getTransferData(defaults.TOTAL_TRANSFER_AMOUNT()) - ) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function batchCreateWithMilestones() internal returns (uint256[] memory) { - bytes memory data = abi.encodeCall( - target.batchCreateWithMilestones, - ( - lockupDynamic, - asset, - defaults.batchCreateWithMilestones(), - getTransferData(defaults.TOTAL_TRANSFER_AMOUNT()) - ) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function batchCreateWithMilestones(uint256 batchSize) internal returns (uint256[] memory) { - uint128 totalTransferAmount = uint128(batchSize) * defaults.PER_STREAM_AMOUNT(); - bytes memory data = abi.encodeCall( - target.batchCreateWithMilestones, - (lockupDynamic, asset, defaults.batchCreateWithMilestones(batchSize), getTransferData(totalTransferAmount)) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function batchCreateWithRange() internal returns (uint256[] memory) { - bytes memory data = abi.encodeCall( - target.batchCreateWithRange, - (lockupLinear, asset, defaults.batchCreateWithRange(), getTransferData(defaults.TOTAL_TRANSFER_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function batchCreateWithRange(uint256 batchSize) internal returns (uint256[] memory) { - uint128 totalTransferAmount = uint128(batchSize) * defaults.PER_STREAM_AMOUNT(); - bytes memory data = abi.encodeCall( - target.batchCreateWithRange, - (lockupLinear, asset, defaults.batchCreateWithRange(batchSize), getTransferData(totalTransferAmount)) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256[])); - } - - function createWithDeltas() internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithDeltas, - (lockupDynamic, defaults.createWithDeltas(), getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function createWithDurations() internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithDurations, - (lockupLinear, defaults.createWithDurations(), getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function createWithMilestones() internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithMilestones, - (lockupDynamic, defaults.createWithMilestones(), getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function createWithMilestones(LockupDynamic.CreateWithMilestones memory params) internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithMilestones, (lockupDynamic, params, getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function createWithRange() internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithRange, - (lockupLinear, defaults.createWithRange(), getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function createWithRange(LockupLinear.CreateWithRange memory params) internal returns (uint256) { - bytes memory data = abi.encodeCall( - target.createWithRange, (lockupLinear, params, getTransferData(defaults.PER_STREAM_AMOUNT())) - ); - bytes memory response = aliceProxy.execute(address(target), data); - return abi.decode(response, (uint256)); - } - - function getTransferData(uint160 amount) internal view returns (bytes memory) { - if (target == targetPermit2) { - return defaults.permit2Params(amount); - } - // The {ProxyTargetApprove} contract does not require any transfer data. - return bytes(""); - } } diff --git a/test/fork/Fork.t.sol b/test/fork/Fork.t.sol index fa8f20ec..e54cd83b 100644 --- a/test/fork/Fork.t.sol +++ b/test/fork/Fork.t.sol @@ -56,14 +56,8 @@ abstract contract Fork_Test is Base_Test, V2CoreFuzzers { // Label the contracts. labelContracts(); - // Make Alice the default caller. - vm.startPrank({ msgSender: users.alice.addr }); - - // Approve {Permit2} to transfer Alice's assets. - maxApprovePermit2(); - - // Approve Alice's Proxy to spend assets from Alice. - asset.approve({ spender: address(aliceProxy), amount: MAX_UINT256 }); + // Approve the relevant contracts. + approveContracts(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/test/fork/target/batchCancelMultiple.t.sol b/test/fork/target/batchCancelMultiple.t.sol index 023634de..c1a07a90 100644 --- a/test/fork/target/batchCancelMultiple.t.sol +++ b/test/fork/target/batchCancelMultiple.t.sol @@ -18,8 +18,16 @@ abstract contract BatchCancelMultiple_Fork_Test is Fork_Test { batchSize = _bound(batchSize, 1, 50); // Create two batches of streams. - uint256[] memory dynamicStreamIds = batchCreateWithMilestones(batchSize); - uint256[] memory linearStreamIds = batchCreateWithRange(batchSize); + uint256[] memory dynamicStreamIds = batch.createWithMilestones({ + lockupDynamic: lockupDynamic, + asset: asset, + batch: defaults.batchCreateWithMilestones(batchSize) + }); + uint256[] memory linearStreamIds = batch.createWithRange({ + lockupLinear: lockupLinear, + asset: asset, + batch: defaults.batchCreateWithRange(batchSize) + }); // Simulate the passage of time. vm.warp({ timestamp: defaults.CLIFF_TIME() }); diff --git a/test/integration/Integration.t.sol b/test/integration/Integration.t.sol index 5547a2fa..2db68343 100644 --- a/test/integration/Integration.t.sol +++ b/test/integration/Integration.t.sol @@ -34,16 +34,8 @@ abstract contract Integration_Test is Base_Test { // Label the contracts. labelContracts(); - // Approve Permit2 to spend assets from the stream's recipient and Alice (the proxy owner). - vm.startPrank({ msgSender: users.recipient0.addr }); - asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); - - changePrank({ msgSender: users.alice.addr }); - asset.approve({ spender: address(batch), amount: MAX_UINT256 }); - asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); - - // Approve Alice's Proxy to spend assets from Alice. - asset.approve({ spender: address(aliceProxy), amount: MAX_UINT256 }); + // Approve the relevant contracts. + approveContracts(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/test/integration/merkle-streamer/MerkleStreamer.t.sol b/test/integration/merkle-streamer/MerkleStreamer.t.sol index 3829f73a..3abe2af1 100644 --- a/test/integration/merkle-streamer/MerkleStreamer.t.sol +++ b/test/integration/merkle-streamer/MerkleStreamer.t.sol @@ -25,6 +25,22 @@ abstract contract MerkleStreamer_Integration_Test is Integration_Test { }); } + function computeMerkleStreamerLLAddress() internal returns (address) { + return computeMerkleStreamerLLAddress(users.admin.addr, defaults.MERKLE_ROOT(), defaults.EXPIRATION()); + } + + function computeMerkleStreamerLLAddress(address admin) internal returns (address) { + return computeMerkleStreamerLLAddress(admin, defaults.MERKLE_ROOT(), defaults.EXPIRATION()); + } + + function computeMerkleStreamerLLAddress(address admin, uint40 expiration) internal returns (address) { + return computeMerkleStreamerLLAddress(admin, defaults.MERKLE_ROOT(), expiration); + } + + function computeMerkleStreamerLLAddress(address admin, bytes32 merkleRoot) internal returns (address) { + return computeMerkleStreamerLLAddress(admin, merkleRoot, defaults.EXPIRATION()); + } + function createMerkleStreamerLL() internal returns (ISablierV2MerkleStreamerLL) { return createMerkleStreamerLL(users.admin.addr, defaults.EXPIRATION()); } diff --git a/test/integration/plugin/on-stream-canceled/onStreamCanceled.t.sol b/test/integration/plugin/on-stream-canceled/onStreamCanceled.t.sol index 48c025c0..e369a6b1 100644 --- a/test/integration/plugin/on-stream-canceled/onStreamCanceled.t.sol +++ b/test/integration/plugin/on-stream-canceled/onStreamCanceled.t.sol @@ -15,7 +15,8 @@ contract OnStreamCanceled_Integration_Test is Integration_Test { Integration_Test.setUp(); proxyRegistry.installPlugin(plugin); - streamId = createWithRange(); + asset.approve({ spender: address(lockupLinear), amount: MAX_UINT256 }); + streamId = lockupLinear.createWithRange(defaults.createWithRange()); // List the {LockupLinear} contract in the archive. changePrank({ msgSender: users.admin.addr }); diff --git a/test/integration/target/Target.t.sol b/test/integration/target/Target.t.sol new file mode 100644 index 00000000..905e9747 --- /dev/null +++ b/test/integration/target/Target.t.sol @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity >=0.8.20 <0.9.0; + +import { LockupDynamic, LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol"; + +import { Integration_Test } from "../Integration.t.sol"; + +abstract contract Target_Integration_Test is Integration_Test { + function setUp() public virtual override { + Integration_Test.setUp(); + } + + function batchCreateWithDeltas() internal returns (uint256[] memory) { + bytes memory data = abi.encodeCall( + target.batchCreateWithDeltas, + (lockupDynamic, asset, defaults.batchCreateWithDeltas(), getTransferData(defaults.TOTAL_TRANSFER_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function batchCreateWithDurations() internal returns (uint256[] memory) { + bytes memory data = abi.encodeCall( + target.batchCreateWithDurations, + ( + lockupLinear, + asset, + defaults.batchCreateWithDurations(), + getTransferData(defaults.TOTAL_TRANSFER_AMOUNT()) + ) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function batchCreateWithMilestones() internal returns (uint256[] memory) { + bytes memory data = abi.encodeCall( + target.batchCreateWithMilestones, + ( + lockupDynamic, + asset, + defaults.batchCreateWithMilestones(), + getTransferData(defaults.TOTAL_TRANSFER_AMOUNT()) + ) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function batchCreateWithMilestones(uint256 batchSize) internal returns (uint256[] memory) { + uint128 totalTransferAmount = uint128(batchSize) * defaults.PER_STREAM_AMOUNT(); + bytes memory data = abi.encodeCall( + target.batchCreateWithMilestones, + (lockupDynamic, asset, defaults.batchCreateWithMilestones(batchSize), getTransferData(totalTransferAmount)) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function batchCreateWithRange() internal returns (uint256[] memory) { + bytes memory data = abi.encodeCall( + target.batchCreateWithRange, + (lockupLinear, asset, defaults.batchCreateWithRange(), getTransferData(defaults.TOTAL_TRANSFER_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function batchCreateWithRange(uint256 batchSize) internal returns (uint256[] memory) { + uint128 totalTransferAmount = uint128(batchSize) * defaults.PER_STREAM_AMOUNT(); + bytes memory data = abi.encodeCall( + target.batchCreateWithRange, + (lockupLinear, asset, defaults.batchCreateWithRange(batchSize), getTransferData(totalTransferAmount)) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256[])); + } + + function createWithDeltas() internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithDeltas, + (lockupDynamic, defaults.createWithDeltas(), getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function createWithDurations() internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithDurations, + (lockupLinear, defaults.createWithDurations(), getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function createWithMilestones() internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithMilestones, + (lockupDynamic, defaults.createWithMilestones(), getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function createWithMilestones(LockupDynamic.CreateWithMilestones memory params) internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithMilestones, (lockupDynamic, params, getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function createWithRange() internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithRange, + (lockupLinear, defaults.createWithRange(), getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function createWithRange(LockupLinear.CreateWithRange memory params) internal returns (uint256) { + bytes memory data = abi.encodeCall( + target.createWithRange, (lockupLinear, params, getTransferData(defaults.PER_STREAM_AMOUNT())) + ); + bytes memory response = aliceProxy.execute(address(target), data); + return abi.decode(response, (uint256)); + } + + function getTransferData(uint160 amount) internal view returns (bytes memory) { + if (target == targetPermit2) { + return defaults.permit2Params(amount); + } + // The {ProxyTargetApprove} contract does not require any transfer data. + return bytes(""); + } +} diff --git a/test/integration/target/batch-cancel-multiple/batchCancelMultiple.t.sol b/test/integration/target/batch-cancel-multiple/batchCancelMultiple.t.sol index 6c8ed12e..269febcd 100644 --- a/test/integration/target/batch-cancel-multiple/batchCancelMultiple.t.sol +++ b/test/integration/target/batch-cancel-multiple/batchCancelMultiple.t.sol @@ -7,9 +7,9 @@ import { Lockup } from "@sablier/v2-core/src/types/DataTypes.sol"; import { Errors } from "src/libraries/Errors.sol"; import { Batch } from "src/types/DataTypes.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract BatchCancelMultiple_Integration_Test is Integration_Test { +abstract contract BatchCancelMultiple_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/batch-create-with-deltas/batchCreateWithDeltas.t.sol b/test/integration/target/batch-create-with-deltas/batchCreateWithDeltas.t.sol index 11df2acc..cfa48257 100644 --- a/test/integration/target/batch-create-with-deltas/batchCreateWithDeltas.t.sol +++ b/test/integration/target/batch-create-with-deltas/batchCreateWithDeltas.t.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.19 <0.9.0; import { Errors } from "src/libraries/Errors.sol"; import { Batch } from "src/types/DataTypes.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract BatchCreateWithDeltas_Integration_Test is Integration_Test { +abstract contract BatchCreateWithDeltas_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/batch-create-with-durations/batchCreateWithDurations.t.sol b/test/integration/target/batch-create-with-durations/batchCreateWithDurations.t.sol index e8a5c528..dbd0003a 100644 --- a/test/integration/target/batch-create-with-durations/batchCreateWithDurations.t.sol +++ b/test/integration/target/batch-create-with-durations/batchCreateWithDurations.t.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.19 <0.9.0; import { Errors } from "src/libraries/Errors.sol"; import { Batch } from "src/types/DataTypes.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract BatchCreateWithDurations_Integration_Test is Integration_Test { +abstract contract BatchCreateWithDurations_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/batch-create-with-milestones/batchCreateWithMilestones.t.sol b/test/integration/target/batch-create-with-milestones/batchCreateWithMilestones.t.sol index 2b95c4ca..a02d1a42 100644 --- a/test/integration/target/batch-create-with-milestones/batchCreateWithMilestones.t.sol +++ b/test/integration/target/batch-create-with-milestones/batchCreateWithMilestones.t.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.19 <0.9.0; import { Errors } from "src/libraries/Errors.sol"; import { Batch } from "src/types/DataTypes.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract BatchCreateWithMilestones_Integration_Test is Integration_Test { +abstract contract BatchCreateWithMilestones_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/batch-create-with-range/batchCreateWithRange.t.sol b/test/integration/target/batch-create-with-range/batchCreateWithRange.t.sol index c54e11d7..a58170f9 100644 --- a/test/integration/target/batch-create-with-range/batchCreateWithRange.t.sol +++ b/test/integration/target/batch-create-with-range/batchCreateWithRange.t.sol @@ -4,9 +4,9 @@ pragma solidity >=0.8.19 <0.9.0; import { Errors } from "src/libraries/Errors.sol"; import { Batch } from "src/types/DataTypes.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract BatchCreateWithRange_Integration_Test is Integration_Test { +abstract contract BatchCreateWithRange_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/burn/burn.t.sol b/test/integration/target/burn/burn.t.sol index 02b6dbff..81361944 100644 --- a/test/integration/target/burn/burn.t.sol +++ b/test/integration/target/burn/burn.t.sol @@ -6,9 +6,9 @@ import { LockupDynamic, LockupLinear } from "@sablier/v2-core/src/types/DataType import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract Burn_Integration_Test is Integration_Test { +abstract contract Burn_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/cancel-and-create/cancelAndCreate.t.sol b/test/integration/target/cancel-and-create/cancelAndCreate.t.sol index 69e395e7..68414f0a 100644 --- a/test/integration/target/cancel-and-create/cancelAndCreate.t.sol +++ b/test/integration/target/cancel-and-create/cancelAndCreate.t.sol @@ -8,14 +8,14 @@ import { LockupLinear, LockupDynamic } from "@sablier/v2-core/src/types/DataType import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; /// @dev This contracts tests the following functions: /// - `cancelAndCreateWithDeltas` /// - `cancelAndCreateWithDurations` /// - `cancelAndCreateWithMilestones` /// - `cancelAndCreateWithRange` -abstract contract CancelAndCreate_Integration_Test is Integration_Test { +abstract contract CancelAndCreate_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } modifier whenDelegateCalled() { diff --git a/test/integration/target/cancel-multiple/cancelMultiple.t.sol b/test/integration/target/cancel-multiple/cancelMultiple.t.sol index 09b5eeb3..bc4dd1b6 100644 --- a/test/integration/target/cancel-multiple/cancelMultiple.t.sol +++ b/test/integration/target/cancel-multiple/cancelMultiple.t.sol @@ -7,9 +7,9 @@ import { Lockup } from "@sablier/v2-core/src/types/DataTypes.sol"; import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract CancelMultiple_Integration_Test is Integration_Test { +abstract contract CancelMultiple_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/cancel/cancel.t.sol b/test/integration/target/cancel/cancel.t.sol index bb951d21..6f556a7e 100644 --- a/test/integration/target/cancel/cancel.t.sol +++ b/test/integration/target/cancel/cancel.t.sol @@ -6,9 +6,9 @@ import { Lockup } from "@sablier/v2-core/src/types/DataTypes.sol"; import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract Cancel_Integration_Test is Integration_Test { +abstract contract Cancel_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/renounce/renounce.t.sol b/test/integration/target/renounce/renounce.t.sol index 8d2c1cf6..f3c54d69 100644 --- a/test/integration/target/renounce/renounce.t.sol +++ b/test/integration/target/renounce/renounce.t.sol @@ -5,9 +5,9 @@ import { ISablierV2Lockup } from "@sablier/v2-core/src/interfaces/ISablierV2Lock import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract Renounce_Integration_Test is Integration_Test { +abstract contract Renounce_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/withdraw-max-and-transfer/withdrawMaxAndTransfer.t.sol b/test/integration/target/withdraw-max-and-transfer/withdrawMaxAndTransfer.t.sol index 115b8511..37201d2a 100644 --- a/test/integration/target/withdraw-max-and-transfer/withdrawMaxAndTransfer.t.sol +++ b/test/integration/target/withdraw-max-and-transfer/withdrawMaxAndTransfer.t.sol @@ -6,9 +6,9 @@ import { LockupDynamic, LockupLinear } from "@sablier/v2-core/src/types/DataType import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract WithdrawMaxAndTransfer_Integration_Test is Integration_Test { +abstract contract WithdrawMaxAndTransfer_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/withdraw-max/withdrawMax.t.sol b/test/integration/target/withdraw-max/withdrawMax.t.sol index 7d1b8aeb..d77aadfb 100644 --- a/test/integration/target/withdraw-max/withdrawMax.t.sol +++ b/test/integration/target/withdraw-max/withdrawMax.t.sol @@ -5,9 +5,9 @@ import { ISablierV2Lockup } from "@sablier/v2-core/src/interfaces/ISablierV2Lock import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract WithdrawMax_Integration_Test is Integration_Test { +abstract contract WithdrawMax_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/withdraw-multiple/withdrawMultiple.t.sol b/test/integration/target/withdraw-multiple/withdrawMultiple.t.sol index 6186a52b..4bf81975 100644 --- a/test/integration/target/withdraw-multiple/withdrawMultiple.t.sol +++ b/test/integration/target/withdraw-multiple/withdrawMultiple.t.sol @@ -5,9 +5,9 @@ import { ISablierV2Lockup } from "@sablier/v2-core/src/interfaces/ISablierV2Lock import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract WithdrawMultiple_Integration_Test is Integration_Test { +abstract contract WithdrawMultiple_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/withdraw/withdraw.t.sol b/test/integration/target/withdraw/withdraw.t.sol index cd02cd70..58d99203 100644 --- a/test/integration/target/withdraw/withdraw.t.sol +++ b/test/integration/target/withdraw/withdraw.t.sol @@ -5,9 +5,9 @@ import { ISablierV2Lockup } from "@sablier/v2-core/src/interfaces/ISablierV2Lock import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; -abstract contract Withdraw_Integration_Test is Integration_Test { +abstract contract Withdraw_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } function test_RevertWhen_NotDelegateCalled() external { diff --git a/test/integration/target/wrap-and-create/wrapAndCreate.t.sol b/test/integration/target/wrap-and-create/wrapAndCreate.t.sol index 6a118dd1..891abaaf 100644 --- a/test/integration/target/wrap-and-create/wrapAndCreate.t.sol +++ b/test/integration/target/wrap-and-create/wrapAndCreate.t.sol @@ -6,14 +6,14 @@ import { LockupDynamic, LockupLinear } from "@sablier/v2-core/src/types/DataType import { IWrappedNativeAsset } from "src/interfaces/IWrappedNativeAsset.sol"; import { Errors } from "src/libraries/Errors.sol"; -import { Integration_Test } from "../../Integration.t.sol"; +import { Target_Integration_Test } from "../Target.t.sol"; /// @dev This contracts tests the following functions: /// - `wrapAndCreateWithDeltas` /// - `wrapAndCreateWithDurations` /// - `wrapAndCreateWithMilestones` /// - `wrapAndCreateWithRange` -abstract contract WrapAndCreate_Integration_Test is Integration_Test { +abstract contract WrapAndCreate_Integration_Test is Target_Integration_Test { function setUp() public virtual override { } modifier whenDelegateCalled() { diff --git a/test/utils/Defaults.sol b/test/utils/Defaults.sol index c2aa02cb..e4d4bd67 100644 --- a/test/utils/Defaults.sol +++ b/test/utils/Defaults.sol @@ -307,7 +307,7 @@ contract Defaults is Merkle, PermitSignature { } /*////////////////////////////////////////////////////////////////////////// - SABLIER-V2-PROXY-TARGET + BATCH //////////////////////////////////////////////////////////////////////////*/ /// @dev Returns a default-size batch of `Batch.CreateWithDeltas` parameters. From 173d00d79df8f62bda8a311344f5a995b43d21ad Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Thu, 12 Oct 2023 18:51:48 +0300 Subject: [PATCH 2/4] test: add DeployPrecompiled util contract test: use deployPrecompiledPeriphery in Precompiles tests --- test/Base.t.sol | 73 +++------------------- test/utils/DeployPrecompiled.sol | 104 +++++++++++++++++++++++++++++++ test/utils/Precompiles.t.sol | 66 +++++++++++--------- 3 files changed, 149 insertions(+), 94 deletions(-) create mode 100644 test/utils/DeployPrecompiled.sol diff --git a/test/Base.t.sol b/test/Base.t.sol index 3a8c00e7..85f4a73f 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -14,7 +14,6 @@ import { LockupDynamic, LockupLinear } from "@sablier/v2-core/src/types/DataType import { IAllowanceTransfer } from "@uniswap/permit2/interfaces/IAllowanceTransfer.sol"; import { Utils as V2CoreUtils } from "@sablier/v2-core-test/utils/Utils.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; import { ISablierV2Archive } from "src/interfaces/ISablierV2Archive.sol"; import { ISablierV2Batch } from "src/interfaces/ISablierV2Batch.sol"; @@ -35,12 +34,13 @@ import { SablierV2ProxyTargetPush } from "src/SablierV2ProxyTargetPush.sol"; import { WLC } from "./mocks/WLC.sol"; import { Assertions } from "./utils/Assertions.sol"; import { Defaults } from "./utils/Defaults.sol"; +import { DeployPrecompiled } from "./utils/DeployPrecompiled.sol"; import { Events } from "./utils/Events.sol"; import { Merkle } from "./utils/Murky.sol"; import { Users } from "./utils/Types.sol"; /// @notice Base test contract with common logic needed by all tests. -abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtils { +abstract contract Base_Test is Assertions, DeployPrecompiled, Events, Merkle, V2CoreUtils { /*////////////////////////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////////////////////*/ @@ -64,9 +64,9 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil ISablierV2ProxyPlugin internal plugin; IPRBProxyRegistry internal proxyRegistry; ISablierV2ProxyTarget internal target; - SablierV2ProxyTargetApprove internal targetApprove; - SablierV2ProxyTargetPermit2 internal targetPermit2; - SablierV2ProxyTargetPush internal targetPush; + ISablierV2ProxyTarget internal targetApprove; + ISablierV2ProxyTarget internal targetPermit2; + ISablierV2ProxyTarget internal targetPush; IWrappedNativeAsset internal weth; WLC internal wlc; @@ -100,7 +100,7 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil vm.startPrank({ msgSender: users.recipient0.addr }); asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); - // Approve Permit2, SablierV2Batch and Alice's Proxy to spend assets from Alice (the proxy owner). + // Approve Permit2, Batch and Alice's Proxy to spend assets from Alice (the proxy owner). changePrank({ msgSender: users.alice.addr }); asset.approve({ spender: address(batch), amount: MAX_UINT256 }); asset.approve({ spender: address(permit2), amount: MAX_UINT256 }); @@ -125,70 +125,13 @@ abstract contract Base_Test is Assertions, Events, Merkle, StdCheats, V2CoreUtil targetPermit2 = new SablierV2ProxyTargetPermit2(permit2); targetPush = new SablierV2ProxyTargetPush(); } else { - archive = deployPrecompiledArchive(users.admin.addr); - batch = deployPrecompiledBatch(); - merkleStreamerFactory = deployPrecompiledMerkleStreamerFactory(); - plugin = deployPrecompiledProxyPlugin(archive); - targetApprove = deployPrecompiledProxyTargetApprove(); - targetPermit2 = deployPrecompiledProxyTargetPermit2(permit2); - targetPush = deployPrecompiledProxyTargetPush(); + (archive, batch, merkleStreamerFactory, plugin, targetApprove, targetPermit2, targetPush) = + deployPrecompiledPeriphery(users.admin.addr, permit2); } // The default target. target = targetApprove; } - /// @dev Deploys {SablierV2Archive} from a source precompiled with `--via-ir`. - function deployPrecompiledArchive(address initialAdmin) internal returns (ISablierV2Archive) { - return ISablierV2Archive( - deployCode("out-optimized/SablierV2Archive.sol/SablierV2Archive.json", abi.encode(initialAdmin)) - ); - } - - /// @dev Deploys {SablierV2Batch} from a source precompiled with `--via-ir`. - function deployPrecompiledBatch() internal returns (ISablierV2Batch) { - return ISablierV2Batch(deployCode("out-optimized/SablierV2Batch.sol/SablierV2Batch.json")); - } - - /// @dev Deploys {SablierV2MerkleStreamerFactory} from a source precompiled with `--via-ir`. - function deployPrecompiledMerkleStreamerFactory() internal returns (ISablierV2MerkleStreamerFactory) { - return ISablierV2MerkleStreamerFactory( - deployCode("out-optimized/SablierV2MerkleStreamerFactory.sol/SablierV2MerkleStreamerFactory.json") - ); - } - - /// @dev Deploys {SablierV2ProxyPlugin} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyPlugin(ISablierV2Archive archive_) internal returns (ISablierV2ProxyPlugin) { - return ISablierV2ProxyPlugin( - deployCode("out-optimized/SablierV2ProxyPlugin.sol/SablierV2ProxyPlugin.json", abi.encode(archive_)) - ); - } - - /// @dev Deploys {SablierV2ProxyTargetApprove} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetApprove() internal returns (SablierV2ProxyTargetApprove) { - return SablierV2ProxyTargetApprove( - deployCode("out-optimized/SablierV2ProxyTargetApprove.sol/SablierV2ProxyTargetApprove.json") - ); - } - - /// @dev Deploys {SablierV2ProxyTargetPermit2} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetPermit2(IAllowanceTransfer permit2_) - internal - returns (SablierV2ProxyTargetPermit2) - { - return SablierV2ProxyTargetPermit2( - deployCode( - "out-optimized/SablierV2ProxyTargetPermit2.sol/SablierV2ProxyTargetPermit2.json", abi.encode(permit2_) - ) - ); - } - - /// @dev Deploys {deployPrecompiledProxyTargetPush} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetPush() internal returns (SablierV2ProxyTargetPush) { - return SablierV2ProxyTargetPush( - deployCode("out-optimized/SablierV2ProxyTargetPush.sol/SablierV2ProxyTargetPush.json") - ); - } - /// @dev Labels the most relevant contracts. function labelContracts() internal { vm.label({ account: address(aliceProxy), newLabel: "Alice's Proxy" }); diff --git a/test/utils/DeployPrecompiled.sol b/test/utils/DeployPrecompiled.sol new file mode 100644 index 00000000..3e04b2de --- /dev/null +++ b/test/utils/DeployPrecompiled.sol @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity >=0.8.19 <0.9.0; + +import { IAllowanceTransfer } from "@uniswap/permit2/interfaces/IAllowanceTransfer.sol"; +import { StdCheats } from "forge-std/StdCheats.sol"; + +import { ISablierV2Archive } from "../../src/interfaces/ISablierV2Archive.sol"; +import { ISablierV2Batch } from "../../src/interfaces/ISablierV2Batch.sol"; +import { ISablierV2MerkleStreamerFactory } from "../../src/interfaces/ISablierV2MerkleStreamerFactory.sol"; +import { ISablierV2ProxyPlugin } from "../../src/interfaces/ISablierV2ProxyPlugin.sol"; +import { ISablierV2ProxyTarget } from "../../src/interfaces/ISablierV2ProxyTarget.sol"; +import { SablierV2ProxyTargetApprove } from "../../src/SablierV2ProxyTargetApprove.sol"; +import { SablierV2ProxyTargetPermit2 } from "../../src/SablierV2ProxyTargetPermit2.sol"; +import { SablierV2ProxyTargetPush } from "../../src/SablierV2ProxyTargetPush.sol"; + +contract DeployPrecompiled is StdCheats { + /// @dev Deploys {SablierV2Archive} from a source precompiled with `--via-ir`. + function deployPrecompiledArchive(address initialAdmin) internal returns (ISablierV2Archive) { + return ISablierV2Archive( + deployCode("out-optimized/SablierV2Archive.sol/SablierV2Archive.json", abi.encode(initialAdmin)) + ); + } + + /// @dev Deploys {SablierV2Batch} from a source precompiled with `--via-ir`. + function deployPrecompiledBatch() internal returns (ISablierV2Batch) { + return ISablierV2Batch(deployCode("out-optimized/SablierV2Batch.sol/SablierV2Batch.json")); + } + + /// @dev Deploys {SablierV2MerkleStreamerFactory} from a source precompiled with `--via-ir`. + function deployPrecompiledMerkleStreamerFactory() internal returns (ISablierV2MerkleStreamerFactory) { + return ISablierV2MerkleStreamerFactory( + deployCode("out-optimized/SablierV2MerkleStreamerFactory.sol/SablierV2MerkleStreamerFactory.json") + ); + } + + /// @dev Deploys {SablierV2ProxyPlugin} from a source precompiled with `--via-ir`. + function deployPrecompiledProxyPlugin(ISablierV2Archive archive_) internal returns (ISablierV2ProxyPlugin) { + return ISablierV2ProxyPlugin( + deployCode("out-optimized/SablierV2ProxyPlugin.sol/SablierV2ProxyPlugin.json", abi.encode(archive_)) + ); + } + + /// @dev Deploys {SablierV2ProxyTargetApprove} from a source precompiled with `--via-ir`. + function deployPrecompiledProxyTargetApprove() internal returns (SablierV2ProxyTargetApprove) { + return SablierV2ProxyTargetApprove( + deployCode("out-optimized/SablierV2ProxyTargetApprove.sol/SablierV2ProxyTargetApprove.json") + ); + } + + /// @dev Deploys {SablierV2ProxyTargetPermit2} from a source precompiled with `--via-ir`. + function deployPrecompiledProxyTargetPermit2(IAllowanceTransfer permit2_) + internal + returns (SablierV2ProxyTargetPermit2) + { + return SablierV2ProxyTargetPermit2( + deployCode( + "out-optimized/SablierV2ProxyTargetPermit2.sol/SablierV2ProxyTargetPermit2.json", abi.encode(permit2_) + ) + ); + } + + /// @dev Deploys {deployPrecompiledProxyTargetPush} from a source precompiled with `--via-ir`. + function deployPrecompiledProxyTargetPush() internal returns (SablierV2ProxyTargetPush) { + return SablierV2ProxyTargetPush( + deployCode("out-optimized/SablierV2ProxyTargetPush.sol/SablierV2ProxyTargetPush.json") + ); + } + + /// @notice Deploys all V2 Periphery contracts from a source precompiled with `--via-ir` in the following order: + /// + /// 1. {SablierV2Archive} + /// 2. {SablierV2Batch} + /// 3. {SablierV2MerkleStreamerFactory} + /// 4. {SablierV2ProxyPlugin} + /// 5. {SablierV2ProxyTargetApprove} + /// 6. {SablierV2ProxyTargetPermit2} + /// 7. {SablierV2ProxyTargetPush} + function deployPrecompiledPeriphery( + address initialAdmin_, + IAllowanceTransfer permit2_ + ) + internal + returns ( + ISablierV2Archive, + ISablierV2Batch, + ISablierV2MerkleStreamerFactory, + ISablierV2ProxyPlugin, + ISablierV2ProxyTarget, + ISablierV2ProxyTarget, + ISablierV2ProxyTarget + ) + { + ISablierV2Archive archive_ = deployPrecompiledArchive(initialAdmin_); + return ( + archive_, + deployPrecompiledBatch(), + deployPrecompiledMerkleStreamerFactory(), + deployPrecompiledProxyPlugin(archive_), + deployPrecompiledProxyTargetApprove(), + deployPrecompiledProxyTargetPermit2(permit2_), + deployPrecompiledProxyTargetPush() + ); + } +} diff --git a/test/utils/Precompiles.t.sol b/test/utils/Precompiles.t.sol index bd62664c..b55c4026 100644 --- a/test/utils/Precompiles.t.sol +++ b/test/utils/Precompiles.t.sol @@ -88,16 +88,16 @@ contract Precompiles_Test is Base_Test { ISablierV2ProxyTarget actualProxyTargetApprove; ISablierV2ProxyTarget actualProxyTargetPermit2; ISablierV2ProxyTarget actualProxyTargetPush; - address expectedArchive; - address expectedBatch; - address expectedMerkleStreamerFactory; - address expectedProxyPlugin; - bytes expectedLockupDynamicCode; - address expectedProxyTargetApprove; + ISablierV2Archive expectedArchive; + ISablierV2Batch expectedBatch; + ISablierV2MerkleStreamerFactory expectedMerkleStreamerFactory; + ISablierV2ProxyPlugin expectedProxyPlugin; + bytes expectedProxyPluginCode; + ISablierV2ProxyTarget expectedProxyTargetApprove; bytes expectedProxyTargetApproveCode; - address expectedProxyTargetPermit2; + ISablierV2ProxyTarget expectedProxyTargetPermit2; bytes expectedProxyTargetPermit2Code; - address expectedProxyTargetPush; + ISablierV2ProxyTarget expectedProxyTargetPush; bytes expectedProxyTargetPushCode; } @@ -115,44 +115,52 @@ contract Precompiles_Test is Base_Test { vars.actualProxyTargetPush ) = precompiles.deployPeriphery(users.admin.addr, permit2); - vars.expectedArchive = address(deployPrecompiledArchive(users.admin.addr)); - assertEq(address(vars.actualArchive).code, vars.expectedArchive.code, "bytecodes mismatch"); - - vars.expectedBatch = address(deployPrecompiledBatch()); - assertEq(address(vars.actualBatch).code, vars.expectedBatch.code, "bytecodes mismatch"); + ( + vars.expectedArchive, + vars.expectedBatch, + vars.expectedMerkleStreamerFactory, + vars.expectedProxyPlugin, + vars.expectedProxyTargetApprove, + vars.expectedProxyTargetPermit2, + vars.expectedProxyTargetPush + ) = deployPrecompiledPeriphery(users.admin.addr, permit2); - vars.expectedMerkleStreamerFactory = address(deployPrecompiledMerkleStreamerFactory()); + assertEq(address(vars.actualArchive).code, address(vars.expectedArchive).code, "bytecodes mismatch"); + assertEq(address(vars.actualBatch).code, address(vars.expectedBatch).code, "bytecodes mismatch"); assertEq( address(vars.actualMerkleStreamerFactory).code, address(vars.expectedMerkleStreamerFactory).code, "bytecodes mismatch" ); - vars.expectedProxyPlugin = address(deployPrecompiledProxyPlugin(vars.actualArchive)); - vars.expectedLockupDynamicCode = - adjustBytecode(vars.expectedProxyPlugin.code, vars.expectedProxyPlugin, address(vars.actualProxyPlugin)); - assertEq(address(vars.actualProxyPlugin).code, vars.expectedLockupDynamicCode, "bytecodes mismatch"); - - vars.expectedProxyTargetApprove = address(deployPrecompiledProxyTargetApprove()); + // We need to deploy the Proxy Plugin again here because the address of the Archive passed inside the + // `deployPrecompiledPeriphery` function is `vars.expectedProxyPlugin`. Otherwise we cannot adjust the + // bytecode correctly. + vars.expectedProxyPlugin = deployPrecompiledProxyPlugin(vars.actualArchive); + vars.expectedProxyPluginCode = adjustBytecode( + address(vars.expectedProxyPlugin).code, address(vars.expectedProxyPlugin), address(vars.actualProxyPlugin) + ); vars.expectedProxyTargetApproveCode = adjustBytecode( - vars.expectedProxyTargetApprove.code, - vars.expectedProxyTargetApprove, + address(vars.expectedProxyTargetApprove).code, + address(vars.expectedProxyTargetApprove), address(vars.actualProxyTargetApprove) ); - assertEq(address(vars.actualProxyTargetApprove).code, vars.expectedProxyTargetApproveCode, "bytecodes mismatch"); - vars.expectedProxyTargetPermit2 = address(deployPrecompiledProxyTargetPermit2(permit2)); vars.expectedProxyTargetPermit2Code = adjustBytecode( - vars.expectedProxyTargetPermit2.code, - vars.expectedProxyTargetPermit2, + address(vars.expectedProxyTargetPermit2).code, + address(vars.expectedProxyTargetPermit2), address(vars.actualProxyTargetPermit2) ); - assertEq(address(vars.actualProxyTargetPermit2).code, vars.expectedProxyTargetPermit2Code, "bytecodes mismatch"); - vars.expectedProxyTargetPush = address(deployPrecompiledProxyTargetPush()); vars.expectedProxyTargetPushCode = adjustBytecode( - vars.expectedProxyTargetPush.code, vars.expectedProxyTargetPush, address(vars.actualProxyTargetPush) + address(vars.expectedProxyTargetPush).code, + address(vars.expectedProxyTargetPush), + address(vars.actualProxyTargetPush) ); + + assertEq(address(vars.actualProxyPlugin).code, vars.expectedProxyPluginCode, "bytecodes mismatch"); + assertEq(address(vars.actualProxyTargetApprove).code, vars.expectedProxyTargetApproveCode, "bytecodes mismatch"); + assertEq(address(vars.actualProxyTargetPermit2).code, vars.expectedProxyTargetPermit2Code, "bytecodes mismatch"); assertEq(address(vars.actualProxyTargetPush).code, vars.expectedProxyTargetPushCode, "bytecodes mismatch"); } From 958e37aa904d9914bd8c3c1106c47a0467a6af80 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Wed, 18 Oct 2023 16:29:55 +0300 Subject: [PATCH 3/4] test: rename contract to DeployOptimized test: use explicit contract types for targets --- test/Base.t.sol | 10 +++++----- .../{DeployPrecompiled.sol => DeployOptimized.sol} | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) rename test/utils/{DeployPrecompiled.sol => DeployOptimized.sol} (95%) diff --git a/test/Base.t.sol b/test/Base.t.sol index 85f4a73f..b2528a86 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -34,13 +34,13 @@ import { SablierV2ProxyTargetPush } from "src/SablierV2ProxyTargetPush.sol"; import { WLC } from "./mocks/WLC.sol"; import { Assertions } from "./utils/Assertions.sol"; import { Defaults } from "./utils/Defaults.sol"; -import { DeployPrecompiled } from "./utils/DeployPrecompiled.sol"; +import { DeployOptimized } from "./utils/DeployOptimized.sol"; import { Events } from "./utils/Events.sol"; import { Merkle } from "./utils/Murky.sol"; import { Users } from "./utils/Types.sol"; /// @notice Base test contract with common logic needed by all tests. -abstract contract Base_Test is Assertions, DeployPrecompiled, Events, Merkle, V2CoreUtils { +abstract contract Base_Test is Assertions, DeployOptimized, Events, Merkle, V2CoreUtils { /*////////////////////////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////////////////////*/ @@ -64,9 +64,9 @@ abstract contract Base_Test is Assertions, DeployPrecompiled, Events, Merkle, V2 ISablierV2ProxyPlugin internal plugin; IPRBProxyRegistry internal proxyRegistry; ISablierV2ProxyTarget internal target; - ISablierV2ProxyTarget internal targetApprove; - ISablierV2ProxyTarget internal targetPermit2; - ISablierV2ProxyTarget internal targetPush; + SablierV2ProxyTargetApprove internal targetApprove; + SablierV2ProxyTargetPermit2 internal targetPermit2; + SablierV2ProxyTargetPush internal targetPush; IWrappedNativeAsset internal weth; WLC internal wlc; diff --git a/test/utils/DeployPrecompiled.sol b/test/utils/DeployOptimized.sol similarity index 95% rename from test/utils/DeployPrecompiled.sol rename to test/utils/DeployOptimized.sol index 3e04b2de..e5530039 100644 --- a/test/utils/DeployPrecompiled.sol +++ b/test/utils/DeployOptimized.sol @@ -8,12 +8,11 @@ import { ISablierV2Archive } from "../../src/interfaces/ISablierV2Archive.sol"; import { ISablierV2Batch } from "../../src/interfaces/ISablierV2Batch.sol"; import { ISablierV2MerkleStreamerFactory } from "../../src/interfaces/ISablierV2MerkleStreamerFactory.sol"; import { ISablierV2ProxyPlugin } from "../../src/interfaces/ISablierV2ProxyPlugin.sol"; -import { ISablierV2ProxyTarget } from "../../src/interfaces/ISablierV2ProxyTarget.sol"; import { SablierV2ProxyTargetApprove } from "../../src/SablierV2ProxyTargetApprove.sol"; import { SablierV2ProxyTargetPermit2 } from "../../src/SablierV2ProxyTargetPermit2.sol"; import { SablierV2ProxyTargetPush } from "../../src/SablierV2ProxyTargetPush.sol"; -contract DeployPrecompiled is StdCheats { +abstract contract DeployOptimized is StdCheats { /// @dev Deploys {SablierV2Archive} from a source precompiled with `--via-ir`. function deployPrecompiledArchive(address initialAdmin) internal returns (ISablierV2Archive) { return ISablierV2Archive( @@ -85,9 +84,9 @@ contract DeployPrecompiled is StdCheats { ISablierV2Batch, ISablierV2MerkleStreamerFactory, ISablierV2ProxyPlugin, - ISablierV2ProxyTarget, - ISablierV2ProxyTarget, - ISablierV2ProxyTarget + SablierV2ProxyTargetApprove, + SablierV2ProxyTargetPermit2, + SablierV2ProxyTargetPush ) { ISablierV2Archive archive_ = deployPrecompiledArchive(initialAdmin_); From d178bbf354f71b6bb3b75b510e94adc2881f3575 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Wed, 18 Oct 2023 18:54:02 +0300 Subject: [PATCH 4/4] test: rename functions in DeployOptimized --- test/Base.t.sol | 2 +- test/utils/DeployOptimized.sol | 48 +++++++++++++++++----------------- test/utils/Precompiles.t.sol | 22 ++++++++-------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/test/Base.t.sol b/test/Base.t.sol index b2528a86..cfb5262f 100644 --- a/test/Base.t.sol +++ b/test/Base.t.sol @@ -126,7 +126,7 @@ abstract contract Base_Test is Assertions, DeployOptimized, Events, Merkle, V2Co targetPush = new SablierV2ProxyTargetPush(); } else { (archive, batch, merkleStreamerFactory, plugin, targetApprove, targetPermit2, targetPush) = - deployPrecompiledPeriphery(users.admin.addr, permit2); + deployOptimizedPeriphery(users.admin.addr, permit2); } // The default target. target = targetApprove; diff --git a/test/utils/DeployOptimized.sol b/test/utils/DeployOptimized.sol index e5530039..83e20b5b 100644 --- a/test/utils/DeployOptimized.sol +++ b/test/utils/DeployOptimized.sol @@ -13,41 +13,41 @@ import { SablierV2ProxyTargetPermit2 } from "../../src/SablierV2ProxyTargetPermi import { SablierV2ProxyTargetPush } from "../../src/SablierV2ProxyTargetPush.sol"; abstract contract DeployOptimized is StdCheats { - /// @dev Deploys {SablierV2Archive} from a source precompiled with `--via-ir`. - function deployPrecompiledArchive(address initialAdmin) internal returns (ISablierV2Archive) { + /// @dev Deploys {SablierV2Archive} from a optimized source compiled with `--via-ir`. + function deployOptimizedArchive(address initialAdmin) internal returns (ISablierV2Archive) { return ISablierV2Archive( deployCode("out-optimized/SablierV2Archive.sol/SablierV2Archive.json", abi.encode(initialAdmin)) ); } - /// @dev Deploys {SablierV2Batch} from a source precompiled with `--via-ir`. - function deployPrecompiledBatch() internal returns (ISablierV2Batch) { + /// @dev Deploys {SablierV2Batch} from a optimized source compiled with `--via-ir`. + function deployOptimizedBatch() internal returns (ISablierV2Batch) { return ISablierV2Batch(deployCode("out-optimized/SablierV2Batch.sol/SablierV2Batch.json")); } - /// @dev Deploys {SablierV2MerkleStreamerFactory} from a source precompiled with `--via-ir`. - function deployPrecompiledMerkleStreamerFactory() internal returns (ISablierV2MerkleStreamerFactory) { + /// @dev Deploys {SablierV2MerkleStreamerFactory} from a optimized source compiled with `--via-ir`. + function deployOptimizedMerkleStreamerFactory() internal returns (ISablierV2MerkleStreamerFactory) { return ISablierV2MerkleStreamerFactory( deployCode("out-optimized/SablierV2MerkleStreamerFactory.sol/SablierV2MerkleStreamerFactory.json") ); } - /// @dev Deploys {SablierV2ProxyPlugin} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyPlugin(ISablierV2Archive archive_) internal returns (ISablierV2ProxyPlugin) { + /// @dev Deploys {SablierV2ProxyPlugin} from a optimized source compiled with `--via-ir`. + function deployOptimizedProxyPlugin(ISablierV2Archive archive_) internal returns (ISablierV2ProxyPlugin) { return ISablierV2ProxyPlugin( deployCode("out-optimized/SablierV2ProxyPlugin.sol/SablierV2ProxyPlugin.json", abi.encode(archive_)) ); } - /// @dev Deploys {SablierV2ProxyTargetApprove} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetApprove() internal returns (SablierV2ProxyTargetApprove) { + /// @dev Deploys {SablierV2ProxyTargetApprove} from a optimized source compiled with `--via-ir`. + function deployOptimizedProxyTargetApprove() internal returns (SablierV2ProxyTargetApprove) { return SablierV2ProxyTargetApprove( deployCode("out-optimized/SablierV2ProxyTargetApprove.sol/SablierV2ProxyTargetApprove.json") ); } - /// @dev Deploys {SablierV2ProxyTargetPermit2} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetPermit2(IAllowanceTransfer permit2_) + /// @dev Deploys {SablierV2ProxyTargetPermit2} from a optimized source compiled with `--via-ir`. + function deployOptimizedProxyTargetPermit2(IAllowanceTransfer permit2_) internal returns (SablierV2ProxyTargetPermit2) { @@ -58,14 +58,14 @@ abstract contract DeployOptimized is StdCheats { ); } - /// @dev Deploys {deployPrecompiledProxyTargetPush} from a source precompiled with `--via-ir`. - function deployPrecompiledProxyTargetPush() internal returns (SablierV2ProxyTargetPush) { + /// @dev Deploys {SablierV2ProxyTargetPush} from a optimized source compiled with `--via-ir`. + function deployOptimizedProxyTargetPush() internal returns (SablierV2ProxyTargetPush) { return SablierV2ProxyTargetPush( deployCode("out-optimized/SablierV2ProxyTargetPush.sol/SablierV2ProxyTargetPush.json") ); } - /// @notice Deploys all V2 Periphery contracts from a source precompiled with `--via-ir` in the following order: + /// @notice Deploys all V2 Periphery contracts from a optimized source in the following order: /// /// 1. {SablierV2Archive} /// 2. {SablierV2Batch} @@ -74,8 +74,8 @@ abstract contract DeployOptimized is StdCheats { /// 5. {SablierV2ProxyTargetApprove} /// 6. {SablierV2ProxyTargetPermit2} /// 7. {SablierV2ProxyTargetPush} - function deployPrecompiledPeriphery( - address initialAdmin_, + function deployOptimizedPeriphery( + address initialAdmin, IAllowanceTransfer permit2_ ) internal @@ -89,15 +89,15 @@ abstract contract DeployOptimized is StdCheats { SablierV2ProxyTargetPush ) { - ISablierV2Archive archive_ = deployPrecompiledArchive(initialAdmin_); + ISablierV2Archive archive_ = deployOptimizedArchive(initialAdmin); return ( archive_, - deployPrecompiledBatch(), - deployPrecompiledMerkleStreamerFactory(), - deployPrecompiledProxyPlugin(archive_), - deployPrecompiledProxyTargetApprove(), - deployPrecompiledProxyTargetPermit2(permit2_), - deployPrecompiledProxyTargetPush() + deployOptimizedBatch(), + deployOptimizedMerkleStreamerFactory(), + deployOptimizedProxyPlugin(archive_), + deployOptimizedProxyTargetApprove(), + deployOptimizedProxyTargetPermit2(permit2_), + deployOptimizedProxyTargetPush() ); } } diff --git a/test/utils/Precompiles.t.sol b/test/utils/Precompiles.t.sol index b55c4026..83452ca2 100644 --- a/test/utils/Precompiles.t.sol +++ b/test/utils/Precompiles.t.sol @@ -28,26 +28,26 @@ contract Precompiles_Test is Base_Test { function test_DeployArchive() external onlyTestOptimizedProfile { address actualArchive = address(precompiles.deployArchive(users.admin.addr)); - address expectedArchive = address(deployPrecompiledArchive(users.admin.addr)); + address expectedArchive = address(deployOptimizedArchive(users.admin.addr)); assertEq(actualArchive.code, expectedArchive.code, "bytecodes mismatch"); } function test_DeployBatch() external onlyTestOptimizedProfile { address actualBatch = address(precompiles.deployBatch()); - address expectedBatch = address(deployPrecompiledBatch()); + address expectedBatch = address(deployOptimizedBatch()); assertEq(actualBatch.code, expectedBatch.code, "bytecodes mismatch"); } function test_DeployMerkleStreamerFactory() external onlyTestOptimizedProfile { address actualFactory = address(precompiles.deployMerkleStreamerFactory()); - address expectedFactory = address(deployPrecompiledMerkleStreamerFactory()); + address expectedFactory = address(deployOptimizedMerkleStreamerFactory()); assertEq(actualFactory.code, expectedFactory.code, "bytecodes mismatch"); } function test_DeployProxyPlugin() external onlyTestOptimizedProfile { - ISablierV2Archive archive = deployPrecompiledArchive(users.admin.addr); + ISablierV2Archive archive = deployOptimizedArchive(users.admin.addr); address actualProxyPlugin = address(precompiles.deployProxyPlugin(archive)); - address expectedProxyPlugin = address(deployPrecompiledProxyPlugin(archive)); + address expectedProxyPlugin = address(deployOptimizedProxyPlugin(archive)); bytes memory expectedProxyPluginCode = adjustBytecode(expectedProxyPlugin.code, expectedProxyPlugin, actualProxyPlugin); assertEq(actualProxyPlugin.code, expectedProxyPluginCode, "bytecodes mismatch"); @@ -55,7 +55,7 @@ contract Precompiles_Test is Base_Test { function test_DeployProxyTargetApprove() external onlyTestOptimizedProfile { address actualProxyTargetApprove = address(precompiles.deployProxyTargetApprove()); - address expectedProxyTargetApprove = address(deployPrecompiledProxyTargetApprove()); + address expectedProxyTargetApprove = address(deployOptimizedProxyTargetApprove()); bytes memory expectedProxyTargetCode = adjustBytecode(expectedProxyTargetApprove.code, expectedProxyTargetApprove, actualProxyTargetApprove); assertEq(actualProxyTargetApprove.code, expectedProxyTargetCode, "bytecodes mismatch"); @@ -64,7 +64,7 @@ contract Precompiles_Test is Base_Test { function test_DeployProxyTargetPermit2() external onlyTestOptimizedProfile { IAllowanceTransfer permit2 = IAllowanceTransfer(new DeployPermit2().run()); address actualProxyTargetPermit2 = address(precompiles.deployProxyTargetPermit2(permit2)); - address expectedProxyTargetPermit2 = address(deployPrecompiledProxyTargetPermit2(permit2)); + address expectedProxyTargetPermit2 = address(deployOptimizedProxyTargetPermit2(permit2)); bytes memory expectedProxyTargetCode = adjustBytecode(expectedProxyTargetPermit2.code, expectedProxyTargetPermit2, actualProxyTargetPermit2); assertEq(actualProxyTargetPermit2.code, expectedProxyTargetCode, "bytecodes mismatch"); @@ -72,7 +72,7 @@ contract Precompiles_Test is Base_Test { function test_DeployProxyTargetPush() external onlyTestOptimizedProfile { address actualProxyTargetPush = address(precompiles.deployProxyTargetPush()); - address expectedProxyTargetPush = address(deployPrecompiledProxyTargetPush()); + address expectedProxyTargetPush = address(deployOptimizedProxyTargetPush()); bytes memory expectedProxyTargetCode = adjustBytecode(expectedProxyTargetPush.code, expectedProxyTargetPush, actualProxyTargetPush); assertEq(actualProxyTargetPush.code, expectedProxyTargetCode, "bytecodes mismatch"); @@ -123,7 +123,7 @@ contract Precompiles_Test is Base_Test { vars.expectedProxyTargetApprove, vars.expectedProxyTargetPermit2, vars.expectedProxyTargetPush - ) = deployPrecompiledPeriphery(users.admin.addr, permit2); + ) = deployOptimizedPeriphery(users.admin.addr, permit2); assertEq(address(vars.actualArchive).code, address(vars.expectedArchive).code, "bytecodes mismatch"); assertEq(address(vars.actualBatch).code, address(vars.expectedBatch).code, "bytecodes mismatch"); @@ -134,9 +134,9 @@ contract Precompiles_Test is Base_Test { ); // We need to deploy the Proxy Plugin again here because the address of the Archive passed inside the - // `deployPrecompiledPeriphery` function is `vars.expectedProxyPlugin`. Otherwise we cannot adjust the + // `deployOptimizedPeriphery` function is `vars.expectedProxyPlugin`. Otherwise we cannot adjust the // bytecode correctly. - vars.expectedProxyPlugin = deployPrecompiledProxyPlugin(vars.actualArchive); + vars.expectedProxyPlugin = deployOptimizedProxyPlugin(vars.actualArchive); vars.expectedProxyPluginCode = adjustBytecode( address(vars.expectedProxyPlugin).code, address(vars.expectedProxyPlugin), address(vars.actualProxyPlugin) );