From b1f776c3fb068d19ff3507662cda7603ef86a31d Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Mon, 9 Oct 2023 18:01:14 -0300 Subject: [PATCH] feat: decode event data with struct --- .../authority/AuthorityFactory.t.sol | 15 +++--- .../AuthorityHistoryPairFactory.t.sol | 52 ++++++++++++------- .../foundry/dapp/CartesiDAppFactory.t.sol | 18 ++++--- .../test/foundry/history/HistoryFactory.t.sol | 14 +++-- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/onchain/rollups/test/foundry/consensus/authority/AuthorityFactory.t.sol b/onchain/rollups/test/foundry/consensus/authority/AuthorityFactory.t.sol index d0987ff1..d569836b 100644 --- a/onchain/rollups/test/foundry/consensus/authority/AuthorityFactory.t.sol +++ b/onchain/rollups/test/foundry/consensus/authority/AuthorityFactory.t.sol @@ -12,9 +12,13 @@ import {Vm} from "forge-std/Vm.sol"; contract AuthorityFactoryTest is Test { AuthorityFactory factory; - // event emitted in the factory event AuthorityCreated(address authorityOwner, Authority authority); + struct AuthorityCreatedEventData { + address authorityOwner; + Authority authority; + } + function setUp() public { factory = new AuthorityFactory(); } @@ -46,13 +50,12 @@ contract AuthorityFactoryTest is Test { ) { ++numOfAuthorityCreated; - address a; - address b; + AuthorityCreatedEventData memory eventData; - (a, b) = abi.decode(entry.data, (address, address)); + eventData = abi.decode(entry.data, (AuthorityCreatedEventData)); - assertEq(_authorityOwner, a); - assertEq(address(_authority), b); + assertEq(_authorityOwner, eventData.authorityOwner); + assertEq(address(_authority), address(eventData.authority)); } } diff --git a/onchain/rollups/test/foundry/consensus/authority/AuthorityHistoryPairFactory.t.sol b/onchain/rollups/test/foundry/consensus/authority/AuthorityHistoryPairFactory.t.sol index aaec0423..8bf25051 100644 --- a/onchain/rollups/test/foundry/consensus/authority/AuthorityHistoryPairFactory.t.sol +++ b/onchain/rollups/test/foundry/consensus/authority/AuthorityHistoryPairFactory.t.sol @@ -25,12 +25,31 @@ contract AuthorityFactoryTest is Test { IHistoryFactory historyFactory ); + struct FactoryCreatedEventData { + IAuthorityFactory authorityFactory; + IHistoryFactory historyFactory; + } + event AuthorityCreated(address authorityOwner, Authority authority); + struct AuthorityCreatedEventData { + address authorityOwner; + Authority authority; + } + event HistoryCreated(address historyOwner, History history); + struct HistoryCreatedEventData { + address historyOwner; + History history; + } + event NewHistory(IHistory history); + struct NewHistoryEventData{ + IHistory history; + } + event OwnershipTransferred( address indexed previousOwner, address indexed newOwner @@ -66,13 +85,12 @@ contract AuthorityFactoryTest is Test { ) { ++numOfFactoryCreated; - address a; - address b; + FactoryCreatedEventData memory eventData; - (a, b) = abi.decode(entry.data, (address, address)); + eventData = abi.decode(entry.data, (FactoryCreatedEventData)); - assertEq(address(authorityFactory), a); - assertEq(address(historyFactory), b); + assertEq(address(authorityFactory), address(eventData.authorityFactory)); + assertEq(address(historyFactory), address(eventData.historyFactory)); } } @@ -118,13 +136,12 @@ contract AuthorityFactoryTest is Test { ) { ++numOfAuthorityCreated; - address a; - address b; + AuthorityCreatedEventData memory eventData; - (a, b) = abi.decode(entry.data, (address, address)); + eventData = abi.decode(entry.data, (AuthorityCreatedEventData)); - assertEq(address(factory), a); - assertEq(address(_authority), b); + assertEq(address(factory), eventData.authorityOwner); + assertEq(address(_authority), address(eventData.authority)); } if ( @@ -133,13 +150,12 @@ contract AuthorityFactoryTest is Test { ) { ++numOfHistoryCreated; - address a; - address b; + HistoryCreatedEventData memory eventData; - (a, b) = abi.decode(entry.data, (address, address)); + eventData = abi.decode(entry.data, (HistoryCreatedEventData)); - assertEq(address(_authority), a); - assertEq(address(_history), b); + assertEq(address(_authority), eventData.historyOwner); + assertEq(address(_history), address(eventData.history)); } if ( @@ -148,11 +164,11 @@ contract AuthorityFactoryTest is Test { ) { ++numOfNewHistory; - address a; + NewHistoryEventData memory eventData; - a = abi.decode(entry.data, (address)); + eventData = abi.decode(entry.data, (NewHistoryEventData)); - assertEq(address(_history), a); + assertEq(address(_history), address(eventData.history)); } if ( diff --git a/onchain/rollups/test/foundry/dapp/CartesiDAppFactory.t.sol b/onchain/rollups/test/foundry/dapp/CartesiDAppFactory.t.sol index 96cbf42f..7bccec64 100644 --- a/onchain/rollups/test/foundry/dapp/CartesiDAppFactory.t.sol +++ b/onchain/rollups/test/foundry/dapp/CartesiDAppFactory.t.sol @@ -27,6 +27,12 @@ contract CartesiDAppFactoryTest is TestBase { CartesiDApp application ); + struct ApplicationCreatedEventData { + address dappOwner; + bytes32 templateHash; + CartesiDApp application; + } + function testNewApplication( address _dappOwner, bytes32 _templateHash @@ -158,15 +164,13 @@ contract CartesiDAppFactoryTest is TestBase { bytes32(uint256(uint160(address(consensus)))) ); - address a; - bytes32 b; - address c; + ApplicationCreatedEventData memory eventData; - (a, b, c) = abi.decode(entry.data, (address, bytes32, address)); + eventData = abi.decode(entry.data, (ApplicationCreatedEventData)); - assertEq(_dappOwner, a); - assertEq(_templateHash, b); - assertEq(address(_dapp), c); + assertEq(_dappOwner, eventData.dappOwner); + assertEq(_templateHash, eventData.templateHash); + assertEq(address(_dapp), address(eventData.application)); } } diff --git a/onchain/rollups/test/foundry/history/HistoryFactory.t.sol b/onchain/rollups/test/foundry/history/HistoryFactory.t.sol index f4cf1715..ab934235 100644 --- a/onchain/rollups/test/foundry/history/HistoryFactory.t.sol +++ b/onchain/rollups/test/foundry/history/HistoryFactory.t.sol @@ -14,6 +14,11 @@ contract HistoryFactoryTest is Test { event HistoryCreated(address historyOwner, History history); + struct HistoryCreatedEventData { + address historyOwner; + History history; + } + function setUp() public { factory = new HistoryFactory(); } @@ -45,13 +50,12 @@ contract HistoryFactoryTest is Test { ) { ++numOfHistoryCreated; - address a; - address b; + HistoryCreatedEventData memory eventData; - (a, b) = abi.decode(entry.data, (address, address)); + eventData = abi.decode(entry.data, (HistoryCreatedEventData)); - assertEq(_historyOwner, a); - assertEq(address(_history), b); + assertEq(_historyOwner, eventData.historyOwner); + assertEq(address(_history), address(eventData.history)); } }