Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ON-483: Remove ERC1155 support #10

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions contracts/RolesRegistry/RolesRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity 0.8.9;

import { IERC7432 } from "./interfaces/IERC7432.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";

Expand Down Expand Up @@ -31,7 +30,7 @@ contract RolesRegistry is IERC7432 {
address _account
) {
require(
_isOwner(_tokenAddress, _tokenId, msg.sender) ||
msg.sender == IERC721(_tokenAddress).ownerOf(_tokenId) ||
_isRoleApproved(_tokenAddress, _tokenId, _account, msg.sender),
"RolesRegistry: sender must be token owner or approved"
);
Expand All @@ -43,7 +42,7 @@ contract RolesRegistry is IERC7432 {
uint256 _tokenId,
address _account
) {
require(_isOwner(_tokenAddress, _tokenId, _account), "RolesRegistry: account must be token owner");
require(_account == IERC721(_tokenAddress).ownerOf(_tokenId), "RolesRegistry: account must be token owner");
_;
}

Expand Down Expand Up @@ -118,7 +117,7 @@ contract RolesRegistry is IERC7432 {
address _revoker,
address _grantee
) external override isTokenOwner(_tokenAddress, _tokenId, _revoker) {
address _caller = _isOwner(_tokenAddress, _tokenId, msg.sender) ? _revoker : _getApprovedCaller(_tokenAddress, _tokenId, _revoker, _grantee);
address _caller = msg.sender == IERC721(_tokenAddress).ownerOf(_tokenId) ? _revoker : _getApprovedCaller(_tokenAddress, _tokenId, _revoker, _grantee);
_revokeRole(_role, _tokenAddress, _tokenId, _revoker, _grantee, _caller);
}

Expand Down Expand Up @@ -239,13 +238,4 @@ contract RolesRegistry is IERC7432 {
isRoleApprovedForAll(_tokenAddress, _grantor, _operator) ||
getApprovedRole(_tokenAddress, _tokenId, _grantor, _operator);
}

function _isERC1155(address _tokenAddress) internal view returns (bool) {
return ERC165Checker.supportsInterface(_tokenAddress, type(IERC1155).interfaceId);
}

function _isOwner(address _tokenAddress, uint256 _tokenId, address _account) internal view returns (bool) {
if (_isERC1155(_tokenAddress)) return IERC1155(_tokenAddress).balanceOf(_account, _tokenId) > 0;
else return _account == IERC721(_tokenAddress).ownerOf(_tokenId); // Assuming that the token implements ERC721
}
}
13 changes: 0 additions & 13 deletions contracts/mocks/MockERC1155.sol

This file was deleted.

43 changes: 0 additions & 43 deletions test/RolesRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ONE_DAY = 60 * 60 * 24
describe('RolesRegistry', () => {
let RolesRegistry: Contract
let mockERC721: Contract
let mockERC1155: Contract

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let deployer: SignerWithAddress
Expand Down Expand Up @@ -83,12 +82,7 @@ describe('RolesRegistry', () => {
mockERC721 = await MockERC721Factory.deploy()
await mockERC721.deployed()

const MockERC1155Factory = await ethers.getContractFactory('MockERC1155')
mockERC1155 = await MockERC1155Factory.deploy()
await mockERC1155.deployed()

await mockERC721.mint(grantor.address, tokenId)
await mockERC1155.mint(grantor.address, tokenId, 1, HashZero)
})

describe('Main Functions', async () => {
Expand Down Expand Up @@ -131,30 +125,6 @@ describe('RolesRegistry', () => {
data,
)
})
it('should grant role for ERC1155', async () => {
await expect(
RolesRegistry.connect(grantor).grantRole(
PROPERTY_MANAGER,
mockERC1155.address,
tokenId,
userOne.address,
expirationDate,
revocable,
data,
),
)
.to.emit(RolesRegistry, 'RoleGranted')
.withArgs(
PROPERTY_MANAGER,
mockERC1155.address,
tokenId,
grantor.address,
userOne.address,
expirationDate,
revocable,
data,
)
})
it('should NOT grant role if expiration date is in the past', async () => {
const blockNumber = await hre.ethers.provider.getBlockNumber()
const block = await hre.ethers.provider.getBlock(blockNumber)
Expand Down Expand Up @@ -185,19 +155,6 @@ describe('RolesRegistry', () => {
),
).to.be.revertedWith(`RolesRegistry: account must be token owner`)
})
it.skip('should NOT grant role if token is neither ERC721 nor ERC1155', async () => {
await expect(
RolesRegistry.connect(grantor).grantRole(
PROPERTY_MANAGER,
deployer.address,
tokenId,
userOne.address,
expirationDate,
revocable,
HashZero,
),
).to.be.revertedWith(`RolesRegistry: token address is not ERC1155 or ERC721`)
})
})

describe('Revoke role', async () => {
Expand Down