Skip to content

Commit

Permalink
fixed bug in cron
Browse files Browse the repository at this point in the history
  • Loading branch information
laudiacay committed Nov 6, 2023
1 parent b18714a commit 2aa8d7f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/TimeTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity >=0.6.2 <0.9.0;
/// @param amount The amount of Ether to send with the call
/// @param addr The target address of the call
/// @param gas The gas limit for the call
/// @param callvalue The ABI-encoded data payload for the call
/// @param callvalue The optional ABI-encoded data payload for the call
struct CallObject {
uint256 amount;
address addr;
Expand Down
4 changes: 2 additions & 2 deletions src/lamination/LaminatedProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ contract LaminatedProxy is LaminatedStorage, ReentrancyGuard {
bool success;
bytes memory returnvalue;

(success, returnvalue) =
callToMake.addr.call{gas: callToMake.gas, value: callToMake.amount}(callToMake.callvalue);
(success, returnvalue) =
callToMake.addr.call{gas: callToMake.gas, value: callToMake.amount}(callToMake.callvalue);
if (!success) {
revert CallFailed();
}
Expand Down
8 changes: 6 additions & 2 deletions src/tips/Tips.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import "../timetravel/CallBreaker.sol";
contract Tips {
event Tip(address indexed from, address indexed to, uint256 amount);

event LogAmounts(uint256 msgvalue, uint256 balance);

CallBreaker public callbreaker;

constructor(address _callbreaker) {
callbreaker = CallBreaker(payable(_callbreaker));
}

/// @dev Tips should be transferred from each LaminatorProxy to the solver via msg.value
receive() external payable {
fallback() external payable {
emit LogAmounts(msg.value, address(this).balance);
bytes32 tipAddrKey = keccak256(abi.encodePacked("tipYourBartender"));
bytes memory tipAddrBytes = callbreaker.fetchFromAssociatedDataStore(tipAddrKey);
address tipAddr = abi.decode(tipAddrBytes, (address));
emit Tip(msg.sender, tipAddr, msg.value);
payable(tipAddr).transfer(msg.value);
emit Tip(msg.sender, address(this), msg.value);
}

}
10 changes: 6 additions & 4 deletions test/CronTwoExample.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract CronTwoTest is Test, CronTwoLib {
filler = address(300);

// give the pusher some eth
vm.deal(pusherLaminated, 100 ether);
vm.deal(pusher, 100 ether);

// start deployer land
vm.startPrank(deployer);
Expand All @@ -33,7 +33,7 @@ contract CronTwoTest is Test, CronTwoLib {
vm.label(filler, "filler");
}

function testFail_run1CronTwo() external {
function testrun1CronTwo() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
Expand All @@ -58,12 +58,14 @@ contract CronTwoTest is Test, CronTwoLib {
vm.stopPrank();

assertEq(counter.getCount(pusherLaminated), 2);
assertEq(address(filler).balance, initialFillerBalance + 2 * 100000000000000000);
assertEq(address(filler).balance, initialFillerBalance + 2 * 33);

assertFalse(callbreaker.isPortalOpen());

// Should be cleared so init should be false (testFail format is for compliance with Kontrol framework)
(bool init,) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
assertTrue(init);


assertFalse(init);
}
}
2 changes: 1 addition & 1 deletion test/Laminator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ contract LaminatorTest is Test {
});
bytes memory cData = abi.encode(callObj);
vm.prank(randomFriendAddress);
vm.expectRevert(LaminatedProxy.NotLaminatorOrProxy.selector);
vm.expectRevert(LaminatedProxy.NotLaminator.selector);
proxy.push(cData, 0);
}

Expand Down
4 changes: 2 additions & 2 deletions test/WorkedExample.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract WorkedExampleTest is Test, WorkedExampleLib {
vm.label(filler, "filler");
}

function testFail_run1() external {
function testrun1() external {
uint256 laminatorSequenceNumber;

vm.startPrank(pusher);
Expand All @@ -57,6 +57,6 @@ contract WorkedExampleTest is Test, WorkedExampleLib {

(bool init, CallObject[] memory co) = LaminatedProxy(pusherLaminated).viewDeferredCall(laminatorSequenceNumber);
// Test should fail here because we already solved and cleared the tx!
assertTrue(init);
assertFalse(init);
}
}
5 changes: 4 additions & 1 deletion test/solve-lib/CronTwo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract CronTwoLib {
CronTwoLogic public cronTwoLogic;
Tips public tips;
uint32 _blocksInADay = 7150;
uint256 _tipWei = 100000000000000000;
uint256 _tipWei = 33;

function deployerLand(address pusher) public {
// Initializing contracts
Expand All @@ -37,6 +37,9 @@ contract CronTwoLib {
}

function userLand() public returns (uint256) {
// send proxy some eth
pusherLaminated.transfer(1 ether);

// Userland operations
CallObject[] memory pusherCallObjs = new CallObject[](4);
pusherCallObjs[0] = CallObject({
Expand Down

0 comments on commit 2aa8d7f

Please sign in to comment.