dievardump / EIP2981-implementation

Repository that shows how to easily implement EIP2981

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mocks supportsInterface mistake??

jellohouse opened this issue · comments

In this mock https://github.com/dievardump/EIP2981-implementation/blob/main/contracts/mocks/ERC721WithRoyalties.sol

at line 27, can we not simply write:

return super.supportsInterface(interfaceId);

instead of:

return ERC721.supportsInterface(interfaceId) || ERC2981PerTokenRoyalties.supportsInterface(interfaceId);

I'm actually unsure.

super will use the "most derived contract" from all the overrode ones.

If ERC2981PerTokenRoyalties was extending ERC721 it would work, but here I think one of the two would not be called.

I'll try with some tests on the mock

Hmm I see.... Ok let us know what you figure out. Thanks so much!

So, after doing tests, super.supportsInterface(interfaceId) works. At my astonishement.

I needed to understand, and the last code + explanation of this section in the doc helped: https://docs.soliditylang.org/en/v0.8.3/contracts.html?highlight=super#inheritance

ERC721WithRoyalties inheritance tree is:

ERC721WithRoyalties, ERC2981PerTokenRoyalties, ERC721, ERC165

so ERC721WithRoyalties.supportsInterface() super calls ERC2981PerTokenRoyalties.supportsInterface which also uses super, which calls ERC721.supportsInterface()

I was expecting ERC2981PerTokenRoyalties.supportsInterface() super to call ERC165.supportsIntrface since that's the contract it extends (mor elike a tree with several branches, instead of a tree with only one).

just pushed the version using super.

Ok that's amazing! Nice and clean - thanks!