From 0664183b43f359eeb6d7373c425ebfb8b8d6de1c Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Thu, 19 Dec 2024 22:39:44 -0300 Subject: [PATCH] feat: make `InputBox` implement ERC-165 --- contracts/dapp/Application.sol | 7 +------ contracts/inputs/InputBox.sol | 12 +++++++++++- test/dapp/Application.t.sol | 12 ++++++++++-- test/dapp/ApplicationFactory.t.sol | 10 ++++++++-- test/dapp/SelfHostedApplicationFactory.t.sol | 5 ++++- test/inputs/InputBox.t.sol | 17 +++++++++++++++++ 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/contracts/dapp/Application.sol b/contracts/dapp/Application.sol index cb93cc6a..dbec63b0 100644 --- a/contracts/dapp/Application.sol +++ b/contracts/dapp/Application.sol @@ -143,12 +143,7 @@ contract Application is return _consensus; } - function getDataAvailability() - external - view - override - returns (IERC165) - { + function getDataAvailability() external view override returns (IERC165) { return _dataAvailability; } diff --git a/contracts/inputs/InputBox.sol b/contracts/inputs/InputBox.sol index e170c4c0..fec46d6b 100644 --- a/contracts/inputs/InputBox.sol +++ b/contracts/inputs/InputBox.sol @@ -3,11 +3,13 @@ pragma solidity ^0.8.18; +import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; + import {IInputBox} from "./IInputBox.sol"; import {CanonicalMachine} from "../common/CanonicalMachine.sol"; import {Inputs} from "../common/Inputs.sol"; -contract InputBox is IInputBox { +contract InputBox is IInputBox, ERC165 { /// @notice Deployment block number uint256 immutable _deploymentBlockNumber; @@ -82,4 +84,12 @@ contract InputBox is IInputBox { { return _deploymentBlockNumber; } + + function supportsInterface( + bytes4 interfaceId + ) public view override returns (bool) { + return + interfaceId == type(IInputBox).interfaceId || + super.supportsInterface(interfaceId); + } } diff --git a/test/dapp/Application.t.sol b/test/dapp/Application.t.sol index 173e2c68..5e1d7a0b 100644 --- a/test/dapp/Application.t.sol +++ b/test/dapp/Application.t.sol @@ -95,7 +95,12 @@ contract ApplicationTest is TestBase, OwnableTest { address(0) ) ); - new Application(_consensus, address(0), _templateHash, IERC165(address(0))); + new Application( + _consensus, + address(0), + _templateHash, + IERC165(address(0)) + ); } function testConstructor( @@ -119,7 +124,10 @@ contract ApplicationTest is TestBase, OwnableTest { assertEq(address(appContract.getConsensus()), address(consensus)); assertEq(appContract.owner(), owner); assertEq(appContract.getTemplateHash(), templateHash); - assertEq(address(appContract.getDataAvailability()), address(dataAvailability)); + assertEq( + address(appContract.getDataAvailability()), + address(dataAvailability) + ); } // ------------------- diff --git a/test/dapp/ApplicationFactory.t.sol b/test/dapp/ApplicationFactory.t.sol index c3b533ab..63f6ce28 100644 --- a/test/dapp/ApplicationFactory.t.sol +++ b/test/dapp/ApplicationFactory.t.sol @@ -37,7 +37,10 @@ contract ApplicationFactoryTest is TestBase { assertEq(address(appContract.getConsensus()), address(consensus)); assertEq(appContract.owner(), appOwner); assertEq(appContract.getTemplateHash(), templateHash); - assertEq(address(appContract.getDataAvailability()), address(dataAvailability)); + assertEq( + address(appContract.getDataAvailability()), + address(dataAvailability) + ); } function testNewApplicationDeterministic( @@ -71,7 +74,10 @@ contract ApplicationFactoryTest is TestBase { assertEq(address(appContract.getConsensus()), address(consensus)); assertEq(appContract.owner(), appOwner); assertEq(appContract.getTemplateHash(), templateHash); - assertEq(address(appContract.getDataAvailability()), address(dataAvailability)); + assertEq( + address(appContract.getDataAvailability()), + address(dataAvailability) + ); precalculatedAddress = _factory.calculateApplicationAddress( consensus, diff --git a/test/dapp/SelfHostedApplicationFactory.t.sol b/test/dapp/SelfHostedApplicationFactory.t.sol index 93f4e401..4147a828 100644 --- a/test/dapp/SelfHostedApplicationFactory.t.sol +++ b/test/dapp/SelfHostedApplicationFactory.t.sol @@ -164,6 +164,9 @@ contract SelfHostedApplicationFactoryTest is TestBase { assertEq(address(application.getConsensus()), authorityAddr); assertEq(application.owner(), appOwner); assertEq(application.getTemplateHash(), templateHash); - assertEq(address(application.getDataAvailability()), address(dataAvailability)); + assertEq( + address(application.getDataAvailability()), + address(dataAvailability) + ); } } diff --git a/test/inputs/InputBox.t.sol b/test/inputs/InputBox.t.sol index 4c56ffeb..0d30501d 100644 --- a/test/inputs/InputBox.t.sol +++ b/test/inputs/InputBox.t.sol @@ -3,6 +3,8 @@ pragma solidity ^0.8.22; +import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; + import {Test} from "forge-std/Test.sol"; import {InputBox} from "contracts/inputs/InputBox.sol"; import {IInputBox} from "contracts/inputs/IInputBox.sol"; @@ -24,6 +26,21 @@ contract InputBoxTest is Test { assertEq(_inputBox.getDeploymentBlockNumber(), blockNumber); } + function testSupportsInterface() external view { + assertEq( + _inputBox.supportsInterface(type(IInputBox).interfaceId), + true + ); + assertEq(_inputBox.supportsInterface(type(IERC165).interfaceId), true); + assertEq(_inputBox.supportsInterface(bytes4(0xffffffff)), false); + } + + function testSupportsInterface(bytes4 interfaceId) external view { + vm.assume(interfaceId != type(IInputBox).interfaceId); + vm.assume(interfaceId != type(IERC165).interfaceId); + assertEq(_inputBox.supportsInterface(interfaceId), false); + } + function testNoInputs(address appContract) public view { assertEq(_inputBox.getNumberOfInputs(appContract), 0); }