Skip to content

Commit

Permalink
chore: polish batch comments and tests
Browse files Browse the repository at this point in the history
Co-authored-by: andreivladbrg <[email protected]>
  • Loading branch information
smol-ninja and andreivladbrg committed Dec 24, 2024
1 parent 00facce commit f890214
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/abstracts/Batch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { IBatch } from "../interfaces/IBatch.sol";

/// @title Batch
/// @notice See the documentation in {IBatch}.
/// @dev Forked from: https://github.com/boringcrypto/BoringSolidity/blob/master/contracts/BoringBatchable.sol
abstract contract Batch is IBatch {
/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
Expand All @@ -22,7 +21,7 @@ abstract contract Batch is IBatch {
for (uint256 i = 0; i < count; ++i) {
(bool success, bytes memory result) = address(this).delegatecall(calls[i]);

// Check: If the delegate call failed, load and bubble up the revert data.
// Check: If the delegatecall failed, load and bubble up the revert data.
if (!success) {
assembly {
// Get the length of the result stored in the first 32 bytes.
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/concrete/batch/batch.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ contract Batch_Integration_Concrete_Test is Integration_Test {
assertEq(results.length, 6, "batch results length");
assertTrue(abi.decode(results[0], (bool)), "batch results[0]");
assertEq(abi.decode(results[1], (uint128)), defaults.WITHDRAW_AMOUNT(), "batch results[1]");
assertEq(results[2], hex"", "batch results[2]");
assertEq(results[2], "", "batch results[2]");
assertEq(abi.decode(results[3], (uint256)), expectedNextStreamId, "batch results[3]");
assertEq(abi.decode(results[4], (uint256)), expectedNextStreamId, "batch results[4]");
assertEq(results[5], hex"", "batch results[5]");
assertEq(results[5], "", "batch results[5]");
}

/// @dev The batch call includes:
Expand Down Expand Up @@ -93,7 +93,7 @@ contract Batch_Integration_Concrete_Test is Integration_Test {
assertEq(abi.decode(results[3], (uint256)), expectedNextStreamId + 3, "batch results[3]");
assertEq(abi.decode(results[4], (uint256)), expectedNextStreamId + 4, "batch results[4]");
assertEq(abi.decode(results[5], (uint256)), expectedNextStreamId + 5, "batch results[5]");
assertEq(address(lockup).balance, initialEthBalance + 1 wei, "batch contract balance");
assertEq(address(lockup).balance, initialEthBalance + 1 wei, "lockup contract balance");
}

/// @dev The batch call includes:
Expand All @@ -119,12 +119,12 @@ contract Batch_Integration_Concrete_Test is Integration_Test {

bytes[] memory results = lockup.batch{ value: 1 wei }(calls);

assertEq(results.length, 4);
assertEq(results[0], hex"");
assertEq(results[1], hex"");
assertEq(results[2], hex"");
assertEq(results[3], hex"");
assertEq(address(lockup).balance, initialEthBalance + 1 wei);
assertEq(results.length, 4, "batch results length");
assertEq(results[0], "", "batch results[0]");
assertEq(results[1], "", "batch results[1]");
assertEq(results[2], "", "batch results[2]");
assertEq(results[3], "", "batch results[3]");
assertEq(address(lockup).balance, initialEthBalance + 1 wei, "lockup contract balance");
}

/// @dev The batch call includes:
Expand Down Expand Up @@ -155,11 +155,11 @@ contract Batch_Integration_Concrete_Test is Integration_Test {
bytes[] memory results = lockup.batch{ value: 1 wei }(calls);

assertEq(results.length, 5, "batch results length");
assertEq(results[0], hex"", "batch results[0]");
assertEq(results[0], "", "batch results[0]");
assertEq(abi.decode(results[1], (uint128)), defaults.DEPOSIT_AMOUNT() - 1, "batch results[1]");
assertEq(results[2], hex"", "batch results[2]");
assertEq(results[2], "", "batch results[2]");
assertEq(abi.decode(results[3], (uint128)), defaults.DEPOSIT_AMOUNT() - 2, "batch results[3]");
assertEq(results[4], hex"", "batch results[4]");
assertEq(address(lockup).balance, initialEthBalance + 1 wei, "batch contract balance");
assertEq(results[4], "", "batch results[4]");
assertEq(address(lockup).balance, initialEthBalance + 1 wei, "lockup contract balance");
}
}
4 changes: 2 additions & 2 deletions tests/unit/concrete/batch/batch.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract Batch_Unit_Concrete_Test is Base_Test {

// It should return the empty string.
assertEq(results.length, 1, "batch results length");
assertEq(results[0], hex"", "batch results[0]");
assertEq(results[0], "", "batch results[0]");
}

modifier whenPayable() {
Expand Down Expand Up @@ -134,6 +134,6 @@ contract Batch_Unit_Concrete_Test is Base_Test {

// It should return an empty value.
assertEq(results.length, 1, "batch results length");
assertEq(results[0], hex"", "batch results[0]");
assertEq(results[0], "", "batch results[0]");
}
}
4 changes: 2 additions & 2 deletions tests/unit/concrete/batch/batch.tree
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Batch_Unit_Concrete_Test
├── when function does not exist
│ └── it should revert
└── when function exists
├── when non state-changing function
├── when non state changing function
│ ├── when function reverts
│ │ └── it should revert
│ └── when function not revert
│ └── it should return expected value
└── when state-changing function
└── when state changing function
├── when not payable
│ ├── when batch includes ETH value
│ │ └── it should revert
Expand Down

0 comments on commit f890214

Please sign in to comment.