Skip to content

Commit

Permalink
fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ernanirst committed Dec 19, 2023
1 parent c9c21d9 commit 7c66a2f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
6 changes: 3 additions & 3 deletions contracts/RolesRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity 0.8.9;

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

contract RolesRegistry is IERC7432 {
// grantee => tokenAddress => tokenId => role => struct(expirationDate, data)
Expand Down
12 changes: 7 additions & 5 deletions contracts/RolesRegistry/SftRolesRegistrySingleRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ contract SftRolesRegistrySingleRole is ISftRolesRegistry, ERC1155Holder {
'SftRolesRegistry: tokenAmount mismatch'
);

RoleData storage _roleData = roleAssignments[_grantRoleData.grantor][_grantRoleData.nonce][_grantRoleData.role];
RoleData storage _roleData = roleAssignments[_grantRoleData.grantor][_grantRoleData.nonce][
_grantRoleData.role
];
require(
_roleData.expirationDate < block.timestamp || _roleData.revocable,
'SftRolesRegistry: nonce is not expired or is not revocable'
Expand Down Expand Up @@ -129,12 +131,13 @@ contract SftRolesRegistrySingleRole is ISftRolesRegistry, ERC1155Holder {
}

function withdrawFrom(
address _grantor, uint256 _nonce
address _grantor,
uint256 _nonce
) public onlyOwnerOrApproved(_grantor, deposits[_grantor][_nonce].tokenAddress) {
require(deposits[_grantor][_nonce].tokenAmount != 0, "SftRolesRegistry: nonce does not exist");
require(deposits[_grantor][_nonce].tokenAmount != 0, 'SftRolesRegistry: nonce does not exist');
require(
roleAssignments[_grantor][_nonce][UNIQUE_ROLE].expirationDate < block.timestamp ||
roleAssignments[_grantor][_nonce][UNIQUE_ROLE].revocable,
roleAssignments[_grantor][_nonce][UNIQUE_ROLE].revocable,
'SftRolesRegistry: token has an active role'
);

Expand Down Expand Up @@ -250,5 +253,4 @@ contract SftRolesRegistrySingleRole is ISftRolesRegistry, ERC1155Holder {
}
revert('SftRolesRegistry: sender must be approved');
}

}
8 changes: 7 additions & 1 deletion contracts/RolesRegistry/interfaces/IERCXXXX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ interface IERCXXXX is IERC165 {
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _tokenAmount The token amount withdrawn.
event Withdrew(uint256 indexed _nonce, address indexed _grantor, address _tokenAddress, uint256 _tokenId, uint256 _tokenAmount);
event Withdrew(
uint256 indexed _nonce,
address indexed _grantor,
address _tokenAddress,
uint256 _tokenId,
uint256 _tokenAmount
);

/** External Functions **/

Expand Down
2 changes: 1 addition & 1 deletion contracts/RolesRegistry/interfaces/ISftRolesRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.9;

import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import { IERC165 } from '@openzeppelin/contracts/utils/introspection/IERC165.sol';

/// @title ERC-XXXX Semi-Fungible Token Roles
/// @dev See https://eips.ethereum.org/EIPS/eip-XXXX
Expand Down
10 changes: 2 additions & 8 deletions contracts/interfaces/IImmutableOwnerCreate2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
pragma solidity 0.8.9;

interface IImmutableOwnerCreate2Factory {
function deploy(
bytes32 salt,
bytes memory bytecode
) external returns (address addr);
function deploy(bytes32 salt, bytes memory bytecode) external returns (address addr);

function computeAddress(
bytes32 salt,
bytes32 bytecodeHash
) external view returns (address);
function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address);
}
39 changes: 26 additions & 13 deletions test/SftRolesRegistry/SftRolesRegistrySingleRole.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ describe('SftRolesRegistrySingleRole', async () => {
await expect(SftRolesRegistry.connect(grantor).grantRoleFrom(newRoleAssignment))

await expect(
SftRolesRegistry.connect(grantor).revokeRoleFrom(newRevokeRoleData.grantor, newRevokeRoleData.nonce, newRevokeRoleData.role, AddressZero),
SftRolesRegistry.connect(grantor).revokeRoleFrom(
newRevokeRoleData.grantor,
newRevokeRoleData.nonce,
newRevokeRoleData.role,
AddressZero,
),
).to.be.revertedWith('SftRolesRegistry: grantee mismatch')
})

Expand Down Expand Up @@ -511,13 +516,15 @@ describe('SftRolesRegistrySingleRole', async () => {
})

it('should revert when nonce has a role is not expired', async () => {
await expect(SftRolesRegistry.connect(grantor).withdrawFrom(RoleAssignment.grantor, RoleAssignment.nonce))
.to.be.revertedWith('SftRolesRegistry: token has an active role')
await expect(
SftRolesRegistry.connect(grantor).withdrawFrom(RoleAssignment.grantor, RoleAssignment.nonce),
).to.be.revertedWith('SftRolesRegistry: token has an active role')
})

it('should revert if nonce does not exist', async () => {
await expect(SftRolesRegistry.connect(grantor).withdrawFrom(RevokeRoleData.grantor, generateRandomInt()))
.to.be.revertedWith('SftRolesRegistry: nonce does not exist')
await expect(
SftRolesRegistry.connect(grantor).withdrawFrom(RevokeRoleData.grantor, generateRandomInt()),
).to.be.revertedWith('SftRolesRegistry: nonce does not exist')
})

it('should not revert if nonce is expired', async () => {
Expand Down Expand Up @@ -567,7 +574,6 @@ describe('SftRolesRegistrySingleRole', async () => {
})

describe('RoleData', async () => {

it('should return the role data', async () => {
const roleData = await SftRolesRegistry.roleData(
RoleAssignment.grantor,
Expand All @@ -583,7 +589,12 @@ describe('SftRolesRegistrySingleRole', async () => {

it('should revert if role is not UNIQUE_ROLE', async () => {
await expect(
SftRolesRegistry.roleData(RoleAssignment.grantor, RoleAssignment.nonce, generateRoleId('NOT_UNIQUE_ROLE'), RoleAssignment.grantee),
SftRolesRegistry.roleData(
RoleAssignment.grantor,
RoleAssignment.nonce,
generateRoleId('NOT_UNIQUE_ROLE'),
RoleAssignment.grantee,
),
).to.be.revertedWith('SftRolesRegistry: role not supported')
})

Expand All @@ -592,19 +603,17 @@ describe('SftRolesRegistrySingleRole', async () => {
SftRolesRegistry.roleData(RoleAssignment.grantor, RoleAssignment.nonce, RoleAssignment.role, AddressZero),
).to.be.revertedWith('SftRolesRegistry: grantee mismatch')
})

})

describe('RoleExpirationDate', async () => {

it('should return the expiration date', async () => {
expect(
await SftRolesRegistry.roleExpirationDate(
RoleAssignment.grantor,
RoleAssignment.nonce,
RoleAssignment.role,
RoleAssignment.grantee
)
RoleAssignment.grantee,
),
).to.be.equal(RoleAssignment.expirationDate)
})

Expand All @@ -621,10 +630,14 @@ describe('SftRolesRegistrySingleRole', async () => {

it('should revert if grantee is invalid', async () => {
await expect(
SftRolesRegistry.roleExpirationDate(RoleAssignment.grantor, RoleAssignment.nonce, RoleAssignment.role, AddressZero),
SftRolesRegistry.roleExpirationDate(
RoleAssignment.grantor,
RoleAssignment.nonce,
RoleAssignment.role,
AddressZero,
),
).to.be.revertedWith('SftRolesRegistry: grantee mismatch')
})

})
})

Expand Down

0 comments on commit 7c66a2f

Please sign in to comment.