Skip to content

Commit

Permalink
test: refactor all tests according to singleton contracts
Browse files Browse the repository at this point in the history
test: update periphery tests

chore: bump version to v1.3.0

 This is a combination of 14 commits.

test: update tests accordingly to singletone architecture

test: update fork tests for core

test(core): refactor integration tests for core

test(integration): rename Lockup_Create_Integration_Shared_Test to Lockup_Integration_Shared_Test

test: dry'ify concrete tests

test(core): update fuzz tests

test(core): updates invariant tests

test(benchmark): update benchmark

test: fix file path

build: link libraries to optimized build

test: move nullStreamId variable into Integration tests
build: etch helpers bytecode onto dummy addresses for optimized tests
test: update precompiles

test: fix benchmarks

test: polish librariy linkage

test: mock lockup in periphery fork test

test: deploy libraries through DeployOptimized contract
  • Loading branch information
smol-ninja authored and andreivladbrg committed Nov 11, 2024
1 parent 9050f98 commit 0828db8
Show file tree
Hide file tree
Showing 231 changed files with 4,153 additions and 4,944 deletions.
1 change: 1 addition & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"gas-custom-errors": "off",
"max-states-count": ["warn", 20],
"imports-order": "warn",
"max-line-length": ["error", 124],
"named-parameters-mapping": "warn",
Expand Down
58 changes: 35 additions & 23 deletions benchmark/BatchLockup.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.22;

import { ud2x18 } from "@prb/math/src/UD2x18.sol";

import { LockupDynamic, LockupTranched } from "../src/core/types/DataTypes.sol";
import { Lockup, LockupDynamic, LockupTranched } from "../src/core/types/DataTypes.sol";
import { BatchLockup } from "../src/periphery/types/DataTypes.sol";
import { BatchLockupBuilder } from "../test/utils/BatchLockupBuilder.sol";

Expand Down Expand Up @@ -58,13 +58,14 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
//////////////////////////////////////////////////////////////////////////*/

function gasCreateWithDurationsLD(uint256 batchSize, uint256 segmentsCount) internal {
LockupDynamic.CreateWithDurations memory createParams = defaults.createWithDurationsBrokerNullLD();
Lockup.CreateWithDurations memory createParams = defaults.createWithDurationsBrokerNull();
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * segmentsCount);
createParams.segments = _generateSegmentsWithDuration(segmentsCount);
BatchLockup.CreateWithDurationsLD[] memory params = BatchLockupBuilder.fillBatch(createParams, batchSize);
LockupDynamic.SegmentWithDuration[] memory segments = _generateSegmentsWithDuration(segmentsCount);
BatchLockup.CreateWithDurationsLD[] memory params =
BatchLockupBuilder.fillBatch(createParams, segments, batchSize);

uint256 initialGas = gasleft();
batchLockup.createWithDurationsLD(lockupDynamic, dai, params);
batchLockup.createWithDurationsLD(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand All @@ -82,14 +83,16 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
}

function gasCreateWithTimestampsLD(uint256 batchSize, uint256 segmentsCount) internal {
LockupDynamic.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNullLD();
Lockup.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNull();
LockupDynamic.Segment[] memory segments = _generateSegments(segmentsCount);
createParams.startTime = getBlockTimestamp();
createParams.endTime = segments[segments.length - 1].timestamp;
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * segmentsCount);
createParams.segments = _generateSegments(segmentsCount);
BatchLockup.CreateWithTimestampsLD[] memory params = BatchLockupBuilder.fillBatch(createParams, batchSize);
BatchLockup.CreateWithTimestampsLD[] memory params =
BatchLockupBuilder.fillBatch(createParams, segments, batchSize);

uint256 initialGas = gasleft();
batchLockup.createWithTimestampsLD(lockupDynamic, dai, params);
batchLockup.createWithTimestampsLD(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand All @@ -107,11 +110,14 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
}

function gasCreateWithDurationsLL(uint256 batchSize) internal {
BatchLockup.CreateWithDurationsLL[] memory params =
BatchLockupBuilder.fillBatch({ params: defaults.createWithDurationsBrokerNullLL(), batchSize: batchSize });
BatchLockup.CreateWithDurationsLL[] memory params = BatchLockupBuilder.fillBatch({
params: defaults.createWithDurationsBrokerNull(),
durations: defaults.durations(),
batchSize: batchSize
});

uint256 initialGas = gasleft();
batchLockup.createWithDurationsLL(lockupLinear, dai, params);
batchLockup.createWithDurationsLL(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand All @@ -123,11 +129,14 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
}

function gasCreateWithTimestampsLL(uint256 batchSize) internal {
BatchLockup.CreateWithTimestampsLL[] memory params =
BatchLockupBuilder.fillBatch({ params: defaults.createWithTimestampsBrokerNullLL(), batchSize: batchSize });
BatchLockup.CreateWithTimestampsLL[] memory params = BatchLockupBuilder.fillBatch({
params: defaults.createWithTimestampsBrokerNull(),
cliff: defaults.CLIFF_TIME(),
batchSize: batchSize
});

uint256 initialGas = gasleft();
batchLockup.createWithTimestampsLL(lockupLinear, dai, params);
batchLockup.createWithTimestampsLL(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand All @@ -139,13 +148,14 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
}

function gasCreateWithDurationsLT(uint256 batchSize, uint256 tranchesCount) internal {
LockupTranched.CreateWithDurations memory createParams = defaults.createWithDurationsBrokerNullLT();
Lockup.CreateWithDurations memory createParams = defaults.createWithDurationsBrokerNull();
LockupTranched.TrancheWithDuration[] memory tranches = _generateTranchesWithDuration(tranchesCount);
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * tranchesCount);
createParams.tranches = _generateTranchesWithDuration(tranchesCount);
BatchLockup.CreateWithDurationsLT[] memory params = BatchLockupBuilder.fillBatch(createParams, batchSize);
BatchLockup.CreateWithDurationsLT[] memory params =
BatchLockupBuilder.fillBatch(createParams, tranches, batchSize);

uint256 initialGas = gasleft();
batchLockup.createWithDurationsLT(lockupTranched, dai, params);
batchLockup.createWithDurationsLT(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand All @@ -163,14 +173,16 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
}

function gasCreateWithTimestampsLT(uint256 batchSize, uint256 tranchesCount) internal {
LockupTranched.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNullLT();
Lockup.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNull();
LockupTranched.Tranche[] memory tranches = _generateTranches(tranchesCount);
createParams.startTime = getBlockTimestamp();
createParams.endTime = tranches[tranches.length - 1].timestamp;
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * tranchesCount);
createParams.tranches = _generateTranches(tranchesCount);
BatchLockup.CreateWithTimestampsLT[] memory params = BatchLockupBuilder.fillBatch(createParams, batchSize);
BatchLockup.CreateWithTimestampsLT[] memory params =
BatchLockupBuilder.fillBatch(createParams, tranches, batchSize);

uint256 initialGas = gasleft();
batchLockup.createWithTimestampsLT(lockupTranched, dai, params);
batchLockup.createWithTimestampsLT(lockup, dai, params);
string memory gasUsed = vm.toString(initialGas - gasleft());

contentToAppend = string.concat(
Expand Down
9 changes: 3 additions & 6 deletions benchmark/Benchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.22;

import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";

import { ISablierLockup } from "../src/core/interfaces/ISablierLockup.sol";
import { Base_Test } from "../test/Base.t.sol";

/// @notice Benchmark contract with common logic needed by all tests.
Expand All @@ -24,8 +23,6 @@ abstract contract Benchmark_Test is Base_Test {
/// @dev A variable used to store the content to append to the results file.
string internal contentToAppend;

ISablierLockup internal lockup;

uint256[7] internal streamIds = [50, 51, 52, 53, 54, 55, 56];

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -167,9 +164,9 @@ abstract contract Benchmark_Test is Base_Test {
/// @dev Internal function to creates a few streams in each Lockup contract.
function _createFewStreams() internal {
for (uint128 i = 0; i < 100; ++i) {
lockupDynamic.createWithTimestamps(defaults.createWithTimestampsLD());
lockupLinear.createWithTimestamps(defaults.createWithTimestampsLL());
lockupTranched.createWithTimestamps(defaults.createWithTimestampsLT());
lockup.createWithTimestampsLD(defaults.createWithTimestamps(), defaults.segments());
lockup.createWithTimestampsLL(defaults.createWithTimestamps(), defaults.CLIFF_TIME());
lockup.createWithTimestampsLT(defaults.createWithTimestamps(), defaults.tranches());
}
}
}
12 changes: 6 additions & 6 deletions benchmark/EstimateMaxCount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity >=0.8.22 <0.9.0;
import { console2 } from "forge-std/src/console2.sol";
import { Test } from "forge-std/src/Test.sol";

import { LockupDynamic_Gas_Test } from "./LockupDynamic.Gas.t.sol";
import { LockupTranched_Gas_Test } from "./LockupTranched.Gas.t.sol";
import { Lockup_Dynamic_Gas_Test } from "./LockupDynamic.Gas.t.sol";
import { Lockup_Tranched_Gas_Test } from "./LockupTranched.Gas.t.sol";

/// @notice Structure to group the block gas limit and chain id.
struct ChainInfo {
Expand Down Expand Up @@ -39,7 +39,7 @@ contract EstimateMaxCount is Test {

/// @notice Estimate the maximum number of segments allowed in LockupDynamic.
function test_EstimateSegments() public {
LockupDynamic_Gas_Test lockupDynamicGasTest = new LockupDynamic_Gas_Test();
Lockup_Dynamic_Gas_Test lockupDynamicGasTest = new Lockup_Dynamic_Gas_Test();
lockupDynamicGasTest.setUp();

for (uint256 i = 0; i < chains.length; ++i) {
Expand All @@ -56,7 +56,7 @@ contract EstimateMaxCount is Test {
lastGasConsumed = gasConsumed;

// Estimate the gas consumed by adding 10 segments.
gasConsumed = lockupDynamicGasTest.computeGas_CreateWithDurations(count + 10);
gasConsumed = lockupDynamicGasTest.computeGas_CreateWithDurationsLD(count + 10);
}

console2.log("count: %d and gasUsed: %d and chainId: %d", count, lastGasConsumed, chains[i].chainId);
Expand All @@ -65,7 +65,7 @@ contract EstimateMaxCount is Test {

/// @notice Estimate the maximum number of tranches allowed in LockupTranched.
function test_EstimateTranches() public {
LockupTranched_Gas_Test lockupTranchedGasTest = new LockupTranched_Gas_Test();
Lockup_Tranched_Gas_Test lockupTranchedGasTest = new Lockup_Tranched_Gas_Test();
lockupTranchedGasTest.setUp();

for (uint256 i = 0; i < chains.length; ++i) {
Expand All @@ -82,7 +82,7 @@ contract EstimateMaxCount is Test {
lastGasConsumed = gasConsumed;

// Estimate the gas consumed by adding 10 tranches.
gasConsumed = lockupTranchedGasTest.computeGas_CreateWithDurations(count + 10);
gasConsumed = lockupTranchedGasTest.computeGas_CreateWithDurationsLT(count + 10);
}

console2.log("count: %d and gasUsed: %d and chainId: %d", count, lastGasConsumed, chains[i].chainId);
Expand Down
Loading

0 comments on commit 0828db8

Please sign in to comment.