Skip to content

Commit

Permalink
add event to claimReward function and fix fulfiller references
Browse files Browse the repository at this point in the history
  • Loading branch information
jackchuma committed Dec 11, 2024
1 parent a6710f0 commit 7f2ce98
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions contracts/src/RIP7755Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract RIP7755Inbox {
/// @dev Block timestamp when fulfilled
uint96 timestamp;
/// @dev Msg.sender of fulfillment call
address filler;
address fulfiller;
}

// Main storage location used as the base for the fulfillmentInfo mapping following EIP-7201. (keccak256("RIP-7755"))
Expand Down Expand Up @@ -87,7 +87,7 @@ contract RIP7755Inbox {
revert CallAlreadyFulfilled();
}

_setFulfillmentInfo(requestHash, FulfillmentInfo({timestamp: uint96(block.timestamp), filler: fulfiller}));
_setFulfillmentInfo(requestHash, FulfillmentInfo({timestamp: uint96(block.timestamp), fulfiller: fulfiller}));

_sendCallsAndValidateMsgValue(request);

Expand Down
9 changes: 8 additions & 1 deletion contracts/src/RIP7755Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ abstract contract RIP7755Outbox {
/// @param request The requested cross chain call
event CrossChainCallRequested(bytes32 indexed requestHash, CrossChainRequest request);

/// @notice Event emitted when a cross chain call is successfully completed
/// @param requestHash The keccak256 hash of a `CrossChainRequest`
/// @param submitter The address of the fulfiller that successfully completed the cross chain call
event CrossChainCallCompleted(bytes32 indexed requestHash, address submitter);

/// @notice Event emitted when an expired cross chain call request is canceled
/// @param requestHash The keccak256 hash of a `CrossChainRequest`
event CrossChainCallCanceled(bytes32 indexed requestHash);
Expand Down Expand Up @@ -129,6 +134,8 @@ abstract contract RIP7755Outbox {
_requestStatus[requestHash] = CrossChainCallStatus.Completed;

_sendReward(request, payTo);

emit CrossChainCallCompleted(requestHash, msg.sender);
}

/// @notice Cancels a pending request that has expired
Expand Down Expand Up @@ -249,7 +256,7 @@ abstract contract RIP7755Outbox {
returns (RIP7755Inbox.FulfillmentInfo memory)
{
RIP7755Inbox.FulfillmentInfo memory fulfillmentInfo;
fulfillmentInfo.filler = address(uint160((uint256(inboxContractStorageValue) >> 96) & type(uint160).max));
fulfillmentInfo.fulfiller = address(uint160((uint256(inboxContractStorageValue) >> 96) & type(uint160).max));
fulfillmentInfo.timestamp = uint96(uint256(inboxContractStorageValue));
return fulfillmentInfo;
}
Expand Down
4 changes: 0 additions & 4 deletions contracts/test/HashiProver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ contract HashiProverTest is Test {
});
}

function _initFulfillmentInfo() private view returns (RIP7755Inbox.FulfillmentInfo memory) {
return RIP7755Inbox.FulfillmentInfo({timestamp: 1730125190, filler: FILLER});
}

function _deriveStorageKey(CrossChainRequest memory request) private pure returns (bytes memory) {
bytes32 requestHash = keccak256(abi.encode(request));
return abi.encode(keccak256(abi.encodePacked(requestHash, _VERIFIER_STORAGE_LOCATION)));
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/RIP7755Inbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract RIP7755InboxTest is Test {
bytes32 requestHash = inbox.hashRequest(request);
RIP7755Inbox.FulfillmentInfo memory info = inbox.getFulfillmentInfo(requestHash);

assertEq(info.filler, FULFILLER);
assertEq(info.fulfiller, FULFILLER);
assertEq(info.timestamp, block.timestamp);
}

Expand Down Expand Up @@ -152,7 +152,7 @@ contract RIP7755InboxTest is Test {
bytes32 requestHash = inbox.hashRequest(request);
RIP7755Inbox.FulfillmentInfo memory info = inbox.getFulfillmentInfo(requestHash);

assertEq(info.filler, FULFILLER);
assertEq(info.fulfiller, FULFILLER);
assertEq(info.timestamp, block.timestamp);
}

Expand All @@ -167,7 +167,7 @@ contract RIP7755InboxTest is Test {
bytes32 requestHash = inbox.hashRequest(request);
RIP7755Inbox.FulfillmentInfo memory info = inbox.getFulfillmentInfo(requestHash);

assertEq(info.filler, FULFILLER);
assertEq(info.fulfiller, FULFILLER);
assertEq(info.timestamp, block.timestamp);
}

Expand Down
15 changes: 15 additions & 0 deletions contracts/test/RIP7755Outbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract RIP7755OutboxTest is Test {
bytes32 private constant _NATIVE_ASSET = 0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee;

event CrossChainCallRequested(bytes32 indexed requestHash, CrossChainRequest request);
event CrossChainCallCompleted(bytes32 indexed requestHash, address submitter);
event CrossChainCallCanceled(bytes32 indexed callHash);

function setUp() public {
Expand Down Expand Up @@ -218,6 +219,20 @@ contract RIP7755OutboxTest is Test {
outbox.claimReward(request, storageProofData, FILLER);
}

function test_claimReward_emitsEvent(uint256 rewardAmount)
external
fundAlice(rewardAmount)
{
CrossChainRequest memory request = _submitRequest(rewardAmount);
bytes memory storageProofData = abi.encode(true);
bytes32 requestHash = outbox.hashRequest(request);

vm.prank(FILLER);
vm.expectEmit(true, false, false, true);
emit CrossChainCallCompleted(requestHash, FILLER);
outbox.claimReward(request, storageProofData, FILLER);
}

function test_claimReward_storesCompletedStatus_pendingState(uint256 rewardAmount)
external
fundAlice(rewardAmount)
Expand Down

0 comments on commit 7f2ce98

Please sign in to comment.