Skip to content

Commit

Permalink
feat: return data from Bridge.deposit() (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
viatrix authored Apr 24, 2023
1 parent bab70c0 commit 6e99f0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 8 additions & 3 deletions contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,16 @@ contract Bridge is Pausable, Context, EIP712 {
@param depositData Additional data to be passed to specified handler.
@param feeData Additional data to be passed to the fee handler.
@notice Emits {Deposit} event with all necessary parameters and a handler response.
@return depositNonce deposit nonce for the destination domain.
@return handlerResponse a handler response:
- ERC20Handler: responds with an empty data.
- ERC721Handler: responds with the deposited token metadata acquired by calling a tokenURI method in the token contract.
- PermissionedGenericHandler: responds with the raw bytes returned from the call to the target contract.
- PermissionlessGenericHandler: responds with an empty data.
*/
function deposit(uint8 destinationDomainID, bytes32 resourceID, bytes calldata depositData, bytes calldata feeData) external payable whenNotPaused {
function deposit(uint8 destinationDomainID, bytes32 resourceID, bytes calldata depositData, bytes calldata feeData)
external payable whenNotPaused
returns (uint64 depositNonce, bytes memory handlerResponse) {
require(destinationDomainID != _domainID, "Can't deposit to current domain");

address sender = _msgSender();
Expand All @@ -245,12 +249,13 @@ contract Bridge is Pausable, Context, EIP712 {
address handler = _resourceIDToHandlerAddress[resourceID];
require(handler != address(0), "resourceID not mapped to handler");

uint64 depositNonce = ++_depositCounts[destinationDomainID];
depositNonce = ++_depositCounts[destinationDomainID];

IHandler depositHandler = IHandler(handler);
bytes memory handlerResponse = depositHandler.deposit(resourceID, sender, depositData);
handlerResponse = depositHandler.deposit(resourceID, sender, depositData);

emit Deposit(destinationDomainID, resourceID, depositNonce, sender, depositData, handlerResponse);
return (depositNonce, handlerResponse);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/handlers/generic/permissionedDeposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,21 @@ contract("PermissionedGenericHandler - [deposit]", async (accounts) => {
);
});
});

it("Bridge should return correct data from deposit tx", async () => {
const argument = "soylentGreenIsPeople";
const encodedMetaData = Helpers.abiEncode(["string"], [argument]);

const callResult = await BridgeInstance.deposit.call(
destinationDomainID,
initialResourceIDs[6],
Helpers.createPermissionedGenericDepositData(encodedMetaData),
feeData,
{from: depositorAddress}
);

const expectedMetaData = Ethers.utils.formatBytes32String(argument);
assert.equal(callResult.depositNonce.toNumber(), 1);
assert.equal(callResult.handlerResponse, expectedMetaData);
});
});

0 comments on commit 6e99f0f

Please sign in to comment.