From 6e99f0fa3fc11d42ef067ff6d3c99f8624e04d04 Mon Sep 17 00:00:00 2001 From: Tanya Bushenyova Date: Mon, 24 Apr 2023 12:19:13 +0300 Subject: [PATCH] feat: return data from Bridge.deposit() (#165) --- contracts/Bridge.sol | 11 ++++++++--- test/handlers/generic/permissionedDeposit.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/contracts/Bridge.sol b/contracts/Bridge.sol index 254cafe1..f7b48e11 100644 --- a/contracts/Bridge.sol +++ b/contracts/Bridge.sol @@ -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(); @@ -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); } /** diff --git a/test/handlers/generic/permissionedDeposit.js b/test/handlers/generic/permissionedDeposit.js index 1fac73f7..774c51c4 100644 --- a/test/handlers/generic/permissionedDeposit.js +++ b/test/handlers/generic/permissionedDeposit.js @@ -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); + }); });