Skip to content

Commit

Permalink
feat!: remove sender parameter from InputAdded event
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Nov 21, 2023
1 parent aaa7968 commit 4861c4e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 45 deletions.
7 changes: 7 additions & 0 deletions onchain/rollups/.changeset/nine-walls-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cartesi/rollups": major
---

Removed `sender` from `InputAdded` event.
We removed this parameter because it will be encoded in the input blob.
Off-chain components should listen to this new event instead.
8 changes: 1 addition & 7 deletions onchain/rollups/contracts/inputs/IInputBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@ interface IInputBox {
/// @notice Emitted when an input is added to a DApp's input box.
/// @param dapp The address of the DApp
/// @param inputIndex The index of the input in the input box
/// @param sender The address that sent the input
/// @param input The input payload
/// @dev MUST be triggered on a successful call to `addInput`.
event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);

/// @notice Add an input to a DApp's input box.
/// @param _dapp The address of the DApp
Expand Down
2 changes: 1 addition & 1 deletion onchain/rollups/contracts/inputs/InputBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract InputBox is IInputBox {
inputBox.push(inputHash);

// block.number and timestamp can be retrieved by the event metadata itself
emit InputAdded(_dapp, inputIndex, msg.sender, _input);
emit InputAdded(_dapp, inputIndex, input);

return inputHash;
}
Expand Down
9 changes: 2 additions & 7 deletions onchain/rollups/test/foundry/inputs/InputBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ contract InputBoxTest is Test {
InputBox inputBox;
InputBoxHandler handler;

event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);

function setUp() public {
inputBox = new InputBox();
Expand Down Expand Up @@ -189,7 +184,7 @@ contract InputBoxTest is Test {
vm.expectEmit(true, true, false, true, address(inputBox));

// The event we expect
emit InputAdded(_dapp, i, address(this), _inputs[i]);
emit InputAdded(_dapp, i, _inputs[i]);

returnedValues[i] = inputBox.addInput(_dapp, _inputs[i]);

Expand Down
42 changes: 42 additions & 0 deletions onchain/rollups/test/foundry/portals/ERC1155BatchPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ contract ERC1155BatchPortalTest is Test {
uint256[] ids,
uint256[] values
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);

function setUp() public {
inputBox = new InputBox();
Expand Down Expand Up @@ -105,6 +106,17 @@ contract ERC1155BatchPortalTest is Test {
// Expect TransferBatch to be emitted with the right arguments
vm.expectEmit(true, true, true, true);
emit TransferBatch(address(portal), alice, dapp, tokenIds, values);
// Expect InputAdded to be emitted with the right arguments
bytes memory input = this.encodeBatchERC1155Deposit(
token,
alice,
tokenIds,
values,
baseLayerData,
execLayerData
);
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, input);

portal.depositBatchERC1155Token(
token,
Expand Down Expand Up @@ -180,6 +192,17 @@ contract ERC1155BatchPortalTest is Test {
// Expect TransferBatch to be emitted with the right arguments
vm.expectEmit(true, true, true, true);
emit TransferBatch(address(portal), alice, dapp, tokenIds, values);
// Expect InputAdded to be emitted with the right arguments
bytes memory input = this.encodeBatchERC1155Deposit(
token,
alice,
tokenIds,
values,
baseLayerData,
execLayerData
);
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, input);

portal.depositBatchERC1155Token(
token,
Expand Down Expand Up @@ -262,6 +285,25 @@ contract ERC1155BatchPortalTest is Test {
}
return values;
}

function encodeBatchERC1155Deposit(
IERC1155 _token,
address _sender,
uint256[] calldata _tokenIds,
uint256[] calldata _values,
bytes calldata _baseLayerData,
bytes calldata _execLayerData
) external pure returns (bytes memory) {
return
InputEncoding.encodeBatchERC1155Deposit(
_token,
_sender,
_tokenIds,
_values,
_baseLayerData,
_execLayerData
);
}
}

contract InvariantSettings {
Expand Down
24 changes: 24 additions & 0 deletions onchain/rollups/test/foundry/portals/ERC1155SinglePortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import {IInputBox} from "contracts/inputs/IInputBox.sol";
import {InputBox} from "contracts/inputs/InputBox.sol";
import {InputEncoding} from "contracts/common/InputEncoding.sol";

contract NormalToken is ERC1155 {
constructor(
Expand Down Expand Up @@ -81,6 +82,7 @@ contract ERC1155SinglePortalTest is Test {
uint256 id,
uint256 value
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);

function setUp() public {
inputBox = new InputBox();
Expand Down Expand Up @@ -112,6 +114,17 @@ contract ERC1155SinglePortalTest is Test {
// Expect TransferSingle to be emitted with the right arguments
vm.expectEmit(true, true, true, true);
emit TransferSingle(address(portal), alice, dapp, tokenId, value);
// Expect InputAdded to be emitted with the right arguments
bytes memory input = InputEncoding.encodeSingleERC1155Deposit(
token,
alice,
tokenId,
value,
baseLayerData,
execLayerData
);
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, input);

portal.depositSingleERC1155Token(
token,
Expand Down Expand Up @@ -184,6 +197,17 @@ contract ERC1155SinglePortalTest is Test {
// Expect TransferSingle to be emitted with the right arguments
vm.expectEmit(true, true, true, true);
emit TransferSingle(address(portal), alice, dapp, tokenId, value);
// Expect InputAdded to be emitted with the right arguments
bytes memory input = InputEncoding.encodeSingleERC1155Deposit(
token,
alice,
tokenId,
value,
baseLayerData,
execLayerData
);
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, input);

portal.depositSingleERC1155Token(
token,
Expand Down
9 changes: 2 additions & 7 deletions onchain/rollups/test/foundry/portals/ERC20Portal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ contract ERC20PortalTest is Test {
address alice;
address dapp;

event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);
event WatchedTransfer(
address from,
address to,
Expand Down Expand Up @@ -160,7 +155,7 @@ contract ERC20PortalTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, address(portal), input);
emit InputAdded(dapp, 0, input);

// Transfer ERC-20 tokens to the DApp via the portal
portal.depositERC20Tokens(token, dapp, _amount, _data);
Expand Down
13 changes: 4 additions & 9 deletions onchain/rollups/test/foundry/portals/ERC721Portal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ contract ERC721PortalTest is Test {
address alice;
address dapp;

event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);
event Transfer(
address indexed from,
address indexed to,
Expand Down Expand Up @@ -152,7 +147,7 @@ contract ERC721PortalTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, address(portal), input);
emit InputAdded(dapp, 0, input);

// Transfer ERC-721 tokens to the DApp via the portal
portal.depositERC721Token(
Expand Down Expand Up @@ -206,7 +201,7 @@ contract ERC721PortalTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, address(portal), input);
emit InputAdded(dapp, 0, input);

// Transfer ERC-721 tokens to the DApp via the portal
portal.depositERC721Token(
Expand Down Expand Up @@ -333,7 +328,7 @@ contract ERC721PortalTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, address(portal), input);
emit InputAdded(dapp, 0, input);

// Deposit token in DApp's account
portal.depositERC721Token(
Expand Down
9 changes: 2 additions & 7 deletions onchain/rollups/test/foundry/portals/EtherPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ contract EtherPortalTest is Test {
address alice;
address dapp;

event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);
event WatchedFallback(
address sender,
uint256 value,
Expand Down Expand Up @@ -83,7 +78,7 @@ contract EtherPortalTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(dapp, 0, address(etherPortal), input);
emit InputAdded(dapp, 0, input);

// Deposit Ether in the DApp via the portal
etherPortal.depositEther{value: value}(dapp, data);
Expand Down
9 changes: 2 additions & 7 deletions onchain/rollups/test/foundry/relays/DAppAddressRelay.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ contract DAppAddressRelayTest is Test {
IInputBox inputBox;
IDAppAddressRelay relay;

event InputAdded(
address indexed dapp,
uint256 indexed inputIndex,
address sender,
bytes input
);
event InputAdded(address indexed dapp, uint256 indexed inputIndex, bytes input);

function setUp() public {
inputBox = new InputBox();
Expand All @@ -40,7 +35,7 @@ contract DAppAddressRelayTest is Test {

// Expect InputAdded to be emitted with the right arguments
vm.expectEmit(true, true, false, true, address(inputBox));
emit InputAdded(_dapp, 0, address(relay), input);
emit InputAdded(_dapp, 0, input);

// Relay the DApp's address
relay.relayDAppAddress(_dapp);
Expand Down

0 comments on commit 4861c4e

Please sign in to comment.