ERC-165 defines an interface for checking if a contract implements a given interface or not.
On @cartesi/rollups v2.0.0, several contracts will implement ERC-165.
With this, we need to test if these contracts are implementing it properly.
Testing it is pretty straightforward, given that the interface only specifies one function, supportsInterface.
We just need to make sure this function returns true for the interface ID of IERC165 and all the other supported interfaces (depends on the contract) and does not support all others, including 0xffffffff.
✔️ Solution
Define an abstract contract for testing ERC-165 contracts.
This contract should inherit from the Test contract from the forge-std library, and define two virtual functions. One provides the IERC165 contract, and the other, the list of supported interface IDs (besides ERC165, obviously).
📚 Context
ERC-165 defines an interface for checking if a contract implements a given interface or not. On
@cartesi/rollups
v2.0.0, several contracts will implement ERC-165. With this, we need to test if these contracts are implementing it properly. Testing it is pretty straightforward, given that the interface only specifies one function,supportsInterface
. We just need to make sure this function returns true for the interface ID ofIERC165
and all the other supported interfaces (depends on the contract) and does not support all others, including0xffffffff
.✔️ Solution
Define an abstract contract for testing ERC-165 contracts. This contract should inherit from the
Test
contract from theforge-std
library, and define two virtual functions. One provides theIERC165
contract, and the other, the list of supported interface IDs (besidesERC165
, obviously).