Skip to content

Commit

Permalink
feat: make InputBox implement ERC-165
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Dec 20, 2024
1 parent 90d475f commit 0664183
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
7 changes: 1 addition & 6 deletions contracts/dapp/Application.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 11 additions & 1 deletion contracts/inputs/InputBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
12 changes: 10 additions & 2 deletions test/dapp/Application.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
);
}

// -------------------
Expand Down
10 changes: 8 additions & 2 deletions test/dapp/ApplicationFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion test/dapp/SelfHostedApplicationFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
17 changes: 17 additions & 0 deletions test/inputs/InputBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down

0 comments on commit 0664183

Please sign in to comment.