From 3ef8cb5f17fd619b05889cf92c484a2ee36cb488 Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Thu, 3 Oct 2024 14:18:34 -0300 Subject: [PATCH] feat!: make quorum factory return interface --- .changeset/nine-grapes-pull.md | 5 +++++ contracts/consensus/quorum/IQuorumFactory.sol | 8 ++++---- contracts/consensus/quorum/QuorumFactory.sol | 11 ++++++----- test/foundry/consensus/quorum/QuorumFactory.t.sol | 10 +++++----- 4 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/nine-grapes-pull.md diff --git a/.changeset/nine-grapes-pull.md b/.changeset/nine-grapes-pull.md new file mode 100644 index 00000000..c32719d8 --- /dev/null +++ b/.changeset/nine-grapes-pull.md @@ -0,0 +1,5 @@ +--- +"@cartesi/rollups": major +--- + +Make `IQuorumFactory` functions return `IQuorum` diff --git a/contracts/consensus/quorum/IQuorumFactory.sol b/contracts/consensus/quorum/IQuorumFactory.sol index 52dd9890..5b838e57 100644 --- a/contracts/consensus/quorum/IQuorumFactory.sol +++ b/contracts/consensus/quorum/IQuorumFactory.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.8; -import {Quorum} from "./Quorum.sol"; +import {IQuorum} from "./IQuorum.sol"; /// @title Quorum Factory interface interface IQuorumFactory { @@ -12,7 +12,7 @@ interface IQuorumFactory { /// @notice A new quorum was deployed. /// @param quorum The quorum /// @dev MUST be triggered on a successful call to `newQuorum`. - event QuorumCreated(Quorum quorum); + event QuorumCreated(IQuorum quorum); // Permissionless functions @@ -26,7 +26,7 @@ interface IQuorumFactory { function newQuorum( address[] calldata validators, uint256 epochLength - ) external returns (Quorum); + ) external returns (IQuorum); /// @notice Deploy a new quorum deterministically. /// @param validators the list of validators @@ -40,7 +40,7 @@ interface IQuorumFactory { address[] calldata validators, uint256 epochLength, bytes32 salt - ) external returns (Quorum); + ) external returns (IQuorum); /// @notice Calculate the address of a quorum to be deployed deterministically. /// @param validators the list of validators diff --git a/contracts/consensus/quorum/QuorumFactory.sol b/contracts/consensus/quorum/QuorumFactory.sol index d8283111..855c6d6a 100644 --- a/contracts/consensus/quorum/QuorumFactory.sol +++ b/contracts/consensus/quorum/QuorumFactory.sol @@ -6,16 +6,17 @@ pragma solidity ^0.8.8; import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; import {IQuorumFactory} from "./IQuorumFactory.sol"; +import {IQuorum} from "./IQuorum.sol"; import {Quorum} from "./Quorum.sol"; /// @title Quorum Factory -/// @notice Allows anyone to reliably deploy a new `Quorum` contract. +/// @notice Allows anyone to reliably deploy a new `IQuorum` contract. contract QuorumFactory is IQuorumFactory { function newQuorum( address[] calldata validators, uint256 epochLength - ) external override returns (Quorum) { - Quorum quorum = new Quorum(validators, epochLength); + ) external override returns (IQuorum) { + IQuorum quorum = new Quorum(validators, epochLength); emit QuorumCreated(quorum); @@ -26,8 +27,8 @@ contract QuorumFactory is IQuorumFactory { address[] calldata validators, uint256 epochLength, bytes32 salt - ) external override returns (Quorum) { - Quorum quorum = new Quorum{salt: salt}(validators, epochLength); + ) external override returns (IQuorum) { + IQuorum quorum = new Quorum{salt: salt}(validators, epochLength); emit QuorumCreated(quorum); diff --git a/test/foundry/consensus/quorum/QuorumFactory.t.sol b/test/foundry/consensus/quorum/QuorumFactory.t.sol index d967ae03..1494ff17 100644 --- a/test/foundry/consensus/quorum/QuorumFactory.t.sol +++ b/test/foundry/consensus/quorum/QuorumFactory.t.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.22; import {QuorumFactory, IQuorumFactory} from "contracts/consensus/quorum/QuorumFactory.sol"; -import {Quorum} from "contracts/consensus/quorum/Quorum.sol"; +import {IQuorum} from "contracts/consensus/quorum/IQuorum.sol"; import {Vm} from "forge-std/Vm.sol"; import {TestBase} from "../../util/TestBase.sol"; @@ -37,7 +37,7 @@ contract QuorumFactoryTest is TestBase { vm.recordLogs(); - Quorum quorum = _factory.newQuorum(validators, epochLength); + IQuorum quorum = _factory.newQuorum(validators, epochLength); _testNewQuorumAux(validators, epochLength, quorum); } @@ -60,7 +60,7 @@ contract QuorumFactoryTest is TestBase { vm.recordLogs(); - Quorum quorum = _factory.newQuorum(validators, epochLength, salt); + IQuorum quorum = _factory.newQuorum(validators, epochLength, salt); _testNewQuorumAux(validators, epochLength, quorum); @@ -84,7 +84,7 @@ contract QuorumFactoryTest is TestBase { function _testNewQuorumAux( address[] memory validators, uint256 epochLength, - Quorum quorum + IQuorum quorum ) internal { Vm.Log[] memory entries = vm.getRecordedLogs(); @@ -97,7 +97,7 @@ contract QuorumFactoryTest is TestBase { entry.topics[0] == IQuorumFactory.QuorumCreated.selector ) { ++numQuorumCreated; - Quorum eventQuorum = abi.decode(entry.data, (Quorum)); + IQuorum eventQuorum = abi.decode(entry.data, (IQuorum)); assertEq(address(eventQuorum), address(quorum)); } }