Skip to content

Commit

Permalink
chore: fix BlockTimeSchedulerLib test & run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mevtxn committed Dec 20, 2024
1 parent d836d3e commit 3513b0d
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 87 deletions.
4 changes: 1 addition & 3 deletions src/interfaces/IFlashLoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
pragma solidity 0.8.26;

interface IFlashLoan {
function flashLoan(address receiver, uint256 amountA, uint256 amountB, bytes memory data)
external
returns (bool);
function flashLoan(address receiver, uint256 amountA, uint256 amountB, bytes memory data) external returns (bool);
}
6 changes: 2 additions & 4 deletions src/timetravel/CallBreaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ contract CallBreaker is CallBreakerStorage {
FlashLoanData calldata flashLoanData
) external payable onlyPortalClosed {
_setupExecutionData(callObjs, returnsBytes, associatedData);
bytes memory data = abi.encode(callObjs);
IFlashLoan(flashLoanData.provider).flashLoan(
address(this), flashLoanData.amountA, flashLoanData.amountB, data
);
bytes memory data = abi.encode(callObjs);
IFlashLoan(flashLoanData.provider).flashLoan(address(this), flashLoanData.amountA, flashLoanData.amountB, data);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions test/BlockTimeScheduler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ contract BlockTimeSchedulerTest is Test, BlockTimeSchedulerLib {

// start deployer calls
vm.startPrank(deployer);
(address pusherLaminated, address _blockTimeScheduler) = deployerLand(pusher);
deployerLand(pusher);
vm.stopPrank();

BlockTimeScheduler blockTimeScheduler = BlockTimeScheduler(_blockTimeScheduler);
vm.prank(pusher);
blockTimeScheduler.transferOwnership(pusherLaminated);

// Label operations in the run function.
vm.label(pusher, "pusher");
vm.label(address(this), "deployer");
Expand Down
4 changes: 1 addition & 3 deletions test/NoopTurnerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ contract NoopTurnerTest is Test {
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
28 changes: 7 additions & 21 deletions test/SmarterContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function testFail_FrontrunBlocker() external {
Expand Down Expand Up @@ -192,9 +190,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function testBackrunBlocker() external {
Expand Down Expand Up @@ -241,9 +237,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function testFail_BackrunBlocker() external {
Expand Down Expand Up @@ -290,9 +284,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function testAssertFutureCallTo() external {
Expand Down Expand Up @@ -344,9 +336,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);

callbreakerHarness.setPortalOpen(callObjs, returnObjs);

Expand Down Expand Up @@ -404,9 +394,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);

uint256 callLength = 3;
uint256 executeIndex = 2;
Expand Down Expand Up @@ -477,9 +465,7 @@ contract SmarterContractTest is Test {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

vm.prank(address(0xdeadbeef), address(0xdeadbeef));
callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);

uint256 callLength = 3;
uint256 executeIndex = 2;
Expand Down
44 changes: 24 additions & 20 deletions test/solve-lib/BlockTime/BlockTimeSchedulerLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ contract BlockTimeSchedulerLib {
uint256 constant tipWei = 33;
bytes32 public constant SELECTOR = keccak256(abi.encode("BLOCKTIME.UPDATE_TIME"));

function deployerLand(address pusher) public returns (address, address) {
function deployerLand(address pusher) public {
// Initializing contracts
callBreaker = new CallBreaker();
laminator = new Laminator(address(callBreaker));
blockTime = new BlockTime(timeTokenName, timeTokenSymbol);
blockTimeScheduler = new BlockTimeScheduler(address(callBreaker), address(blockTime), pusher);
blockTime = new BlockTime();
blockTimeScheduler = new BlockTimeScheduler(address(callBreaker), address(blockTime));
blockTime.grantRole(blockTime.SCHEDULER_ROLE(), address(blockTimeScheduler));
pusherLaminated = payable(laminator.computeProxyAddress(pusher));
return (address(pusherLaminated), address(blockTimeScheduler));
blockTimeScheduler.grantRole(blockTimeScheduler.TIME_SOLVER(), address(pusherLaminated));
}

function userLand() public returns (uint256) {
Expand Down Expand Up @@ -66,11 +66,12 @@ contract BlockTimeSchedulerLib {
SolverData[] memory dataValues = new SolverData[](1);
dataValues[0] = data;

return laminator.pushToProxy(abi.encode(pusherCallObjs), 1, SELECTOR, dataValues);
return laminator.pushToProxy(pusherCallObjs, 1, SELECTOR, dataValues);
}

function solverLand(uint256 laminatorSequenceNumber, address filler, address pusher) public {
BlockTimeScheduler.BlockTimeData memory data = _getUpdateTimeData(filler, pusher);
(bytes memory chroniclesData, bytes memory meanTimeData, bytes memory receiversData, bytes memory amountsData) =
_getUpdateTimeData(filler, pusher);

CallObject[] memory callObjs = new CallObject[](1);
ReturnObject[] memory returnObjs = new ReturnObject[](1);
Expand All @@ -89,37 +90,40 @@ contract BlockTimeSchedulerLib {

returnObjs[0] = ReturnObject({returnvalue: abi.encode(abi.encode(returnObjsFromPull))});

AdditionalData[] memory associatedData = new AdditionalData[](3);
AdditionalData[] memory associatedData = new AdditionalData[](6);
associatedData[0] =
AdditionalData({key: keccak256(abi.encodePacked("tipYourBartender")), value: abi.encodePacked(filler)});
associatedData[1] =
AdditionalData({key: keccak256(abi.encodePacked("pullIndex")), value: abi.encode(laminatorSequenceNumber)});
associatedData[2] = AdditionalData({key: keccak256(abi.encodePacked("MoveTimeData")), value: abi.encode(data)});
associatedData[2] = AdditionalData({key: keccak256(abi.encodePacked("Chronicles")), value: chroniclesData});
associatedData[3] = AdditionalData({key: keccak256(abi.encodePacked("CurrentMeanTime")), value: meanTimeData});
associatedData[4] = AdditionalData({key: keccak256(abi.encodePacked("Recievers")), value: receiversData});
associatedData[5] = AdditionalData({key: keccak256(abi.encodePacked("Amounts")), value: amountsData});

AdditionalData[] memory hintdices = new AdditionalData[](1);
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});

callBreaker.executeAndVerify(
abi.encode(callObjs), abi.encode(returnObjs), abi.encode(associatedData), abi.encode(hintdices)
);
callBreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function _getUpdateTimeData(address receiver, address pusher)
private
view
returns (BlockTimeScheduler.BlockTimeData memory)
returns (
bytes memory chroniclesData,
bytes memory meanTimeData,
bytes memory receiversData,
bytes memory amountsData
)
{
IBlockTime.Chronicle[] memory chronicles = new IBlockTime.Chronicle[](1);
chronicles[0] = IBlockTime.Chronicle(100, pusher, bytes32(0));
chronicles[0] = IBlockTime.Chronicle(100, pusher, bytes(""));
address[] memory receivers = new address[](1);
uint256[] memory amounts = new uint256[](1);

receivers[0] = receiver;
amounts[0] = 1e18;

BlockTimeScheduler.BatchMintData memory batchMintData = BlockTimeScheduler.BatchMintData(receivers, amounts);
BlockTimeScheduler.BlockTimeData memory data =
BlockTimeScheduler.BlockTimeData(chronicles, block.timestamp, batchMintData);
return data;
chroniclesData = abi.encode(chronicles);
meanTimeData = abi.encode(block.timestamp);
receiversData = abi.encode(receivers);
amountsData = abi.encode(amounts);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/CronCounterLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ contract CronCounterLib {
associatedData[1].value = abi.encode(laminatorSequenceNumber + 1);
}

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/DeFi/FlashLiquidityLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ contract FlashLiquidityLib {
hintdices[3] = AdditionalData({key: keccak256(abi.encode(callObjs[3])), value: abi.encode(3)});
hintdices[4] = AdditionalData({key: keccak256(abi.encode(callObjs[4])), value: abi.encode(4)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
9 changes: 2 additions & 7 deletions test/solve-lib/DeFi/FlashLoanLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ contract FlashLoanLib {
AdditionalData({key: keccak256(abi.encodePacked("tipYourBartender")), value: abi.encodePacked(filler)});
associatedData[1] =
AdditionalData({key: keccak256(abi.encodePacked("pullIndex")), value: abi.encode(laminatorSequenceNumber)});

callbreaker.executeAndVerify(
callObjs,
returnObjs,
associatedData,
generateFlashLoanData(address(flashLoan))
);

callbreaker.executeAndVerify(callObjs, returnObjs, associatedData, generateFlashLoanData(address(flashLoan)));
}

function generateFlashLoanData(address _flashLoan) public pure returns (FlashLoanData memory) {
Expand Down
4 changes: 1 addition & 3 deletions test/solve-lib/DeFi/SelfCheckoutLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ contract SelfCheckoutLib {
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});
hintdices[2] = AdditionalData({key: keccak256(abi.encode(callObjs[2])), value: abi.encode(2)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/DeFi/SlippageProtectionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ contract SlippageProtectionLib {
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/FlashPillLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ contract FlashPillLib {
AdditionalData[] memory hintdices = new AdditionalData[](1);
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/MEVTimeOracle/KITNDisburmentSchedulerLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ contract KITNDisburmentSchedulerLib {
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}

function _getDisbursalData(address receiver) private pure returns (KITNDisburmentScheduler.DisbursalData memory) {
Expand Down
4 changes: 1 addition & 3 deletions test/solve-lib/MEVTimeOracle/MEVTimeComputeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ contract MEVTimeComputeLib {
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});
hintdices[1] = AdditionalData({key: keccak256(abi.encode(callObjs[1])), value: abi.encode(1)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}
4 changes: 1 addition & 3 deletions test/solve-lib/PnPLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ contract PnPLib {
AdditionalData[] memory hintdices = new AdditionalData[](1);
hintdices[0] = AdditionalData({key: keccak256(abi.encode(callObjs[0])), value: abi.encode(0)});

callbreaker.executeAndVerify(
callObjs, returnObjs, associatedData
);
callbreaker.executeAndVerify(callObjs, returnObjs, associatedData);
}
}

0 comments on commit 3513b0d

Please sign in to comment.