Initial commit: add .gitignore and README
This commit is contained in:
70
contracts/test/AtomicExecutorLargeBatch.t.sol
Normal file
70
contracts/test/AtomicExecutorLargeBatch.t.sol
Normal file
@@ -0,0 +1,70 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import {AtomicExecutor} from "../AtomicExecutor.sol";
|
||||
|
||||
contract MockTarget {
|
||||
uint256 public value;
|
||||
|
||||
function setValue(uint256 _value) external {
|
||||
value = _value;
|
||||
}
|
||||
}
|
||||
|
||||
contract AtomicExecutorLargeBatchTest is Test {
|
||||
AtomicExecutor executor;
|
||||
MockTarget target;
|
||||
address owner = address(1);
|
||||
address user = address(2);
|
||||
|
||||
function setUp() public {
|
||||
vm.prank(owner);
|
||||
executor = new AtomicExecutor(owner);
|
||||
|
||||
target = new MockTarget();
|
||||
|
||||
vm.prank(owner);
|
||||
executor.setAllowedTarget(address(target), true);
|
||||
}
|
||||
|
||||
function testVeryLargeBatch() public {
|
||||
// Test with 100 calls (near gas limit)
|
||||
address[] memory targets = new address[](100);
|
||||
bytes[] memory calldatas = new bytes[](100);
|
||||
|
||||
for (uint i = 0; i < 100; i++) {
|
||||
targets[i] = address(target);
|
||||
calldatas[i] = abi.encodeWithSignature("setValue(uint256)", i);
|
||||
}
|
||||
|
||||
uint256 gasBefore = gasleft();
|
||||
vm.prank(user);
|
||||
executor.executeBatch(targets, calldatas);
|
||||
uint256 gasUsed = gasBefore - gasleft();
|
||||
|
||||
// Verify last value
|
||||
assertEq(target.value(), 99);
|
||||
|
||||
// Log gas usage for optimization
|
||||
console.log("Gas used for 100 calls:", gasUsed);
|
||||
}
|
||||
|
||||
function testGasLimitBoundary() public {
|
||||
// Test with calls that approach block gas limit
|
||||
// This helps identify optimal batch size
|
||||
address[] memory targets = new address[](50);
|
||||
bytes[] memory calldatas = new bytes[](50);
|
||||
|
||||
for (uint i = 0; i < 50; i++) {
|
||||
targets[i] = address(target);
|
||||
calldatas[i] = abi.encodeWithSignature("setValue(uint256)", i);
|
||||
}
|
||||
|
||||
vm.prank(user);
|
||||
executor.executeBatch(targets, calldatas);
|
||||
|
||||
assertEq(target.value(), 49);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user