Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Sep 13, 2023
1 parent b193c61 commit 0b4e92e
Showing 1 changed file with 100 additions and 8 deletions.
108 changes: 100 additions & 8 deletions test/RolesRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('RolesRegistry', () => {
let grantor: SignerWithAddress
let userOne: SignerWithAddress
let userTwo: SignerWithAddress
let operator: SignerWithAddress

const PROPERTY_MANAGER = solidityKeccak256(['string'], ['PROPERTY_MANAGER'])
const PROPERTY_TENANT = solidityKeccak256(['string'], ['PROPERTY_TENANT'])
Expand All @@ -28,7 +29,7 @@ describe('RolesRegistry', () => {

before(async function () {
// prettier-ignore
[deployer, grantor, userOne, userTwo] = await ethers.getSigners()
[deployer, grantor, userOne, userTwo, operator] = await ethers.getSigners()

const metadata: NftMetadata = {
name: 'Nft name',
Expand Down Expand Up @@ -73,8 +74,8 @@ describe('RolesRegistry', () => {
})

beforeEach(async () => {
const RolesRegistryFactory = await ethers.getContractFactory('RolesRegistry')
RolesRegistry = await RolesRegistryFactory.deploy()
const ERC7432Factory = await ethers.getContractFactory('RolesRegistry')
RolesRegistry = await ERC7432Factory.deploy()

const NftFactory = await ethers.getContractFactory('Nft')
nft = await NftFactory.deploy()
Expand Down Expand Up @@ -166,7 +167,7 @@ describe('RolesRegistry', () => {
.withArgs(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userTwo.address, expirationDate, HashZero)
})

describe('Single User Roles', async () => {
describe('Unique Roles', async () => {
it('should return true for the last user granted, and false for the others', async () => {
expect(
await RolesRegistry.hasUniqueRole(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userOne.address),
Expand All @@ -186,7 +187,7 @@ describe('RolesRegistry', () => {
})
})

describe('Multiple Users Roles', async () => {
describe('Non-Unique Roles', async () => {
it('should return true for all users', async () => {
expect(
await RolesRegistry.hasRole(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userOne.address),
Expand All @@ -201,11 +202,11 @@ describe('RolesRegistry', () => {
await hre.ethers.provider.send('evm_mine', [])

expect(
await RolesRegistry.hasRole(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userOne.address),
await RolesRegistry.hasRole(PROPERTY_TENANT, AddressZero, tokenId, grantor.address, userOne.address),
).to.be.equal(false)

expect(
await RolesRegistry.hasRole(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userTwo.address),
await RolesRegistry.hasRole(PROPERTY_TENANT, AddressZero, tokenId, grantor.address, userTwo.address),
).to.be.equal(false)
})
})
Expand Down Expand Up @@ -310,9 +311,100 @@ describe('RolesRegistry', () => {
})

describe('ERC165', async function () {
it(`should return true for IRolesRegistry interface id (${ERC7432InterfaceId})`, async function () {
it(`should return true for IERC7432 interface id (${ERC7432InterfaceId})`, async function () {
expect(await RolesRegistry.supportsInterface(ERC7432InterfaceId)).to.be.true
})
})

describe('Approvals', async () => {
const approvals = ['Approval for TokenId', 'Approval for All']
for (const approval of approvals) {
describe(approval, async () => {
beforeEach(async () => {
if (approval === 'Approval for TokenId') {
await RolesRegistry.connect(grantor).approveRole(AddressZero, tokenId, operator.address, true)
} else {
await RolesRegistry.connect(grantor).setRoleApprovalForAll(AddressZero, operator.address, true)
}
})
describe('Grant role from', async () => {
it('should grant role from', async () => {
await expect(
RolesRegistry.connect(operator).grantRoleFrom(
PROPERTY_MANAGER,
AddressZero,
tokenId,
grantor.address,
userOne.address,
expirationDate,
HashZero,
),
)
.to.emit(RolesRegistry, 'RoleGranted')
.withArgs(
PROPERTY_MANAGER,
AddressZero,
tokenId,
grantor.address,
userOne.address,
expirationDate,
HashZero,
)
})
it('should NOT grant role from if operator is not approved', async () => {
if (approval === 'Approval for TokenId') {
await RolesRegistry.connect(grantor).approveRole(AddressZero, tokenId, operator.address, false)
} else {
await RolesRegistry.connect(grantor).setRoleApprovalForAll(AddressZero, operator.address, false)
}

await expect(
RolesRegistry.connect(operator).grantRoleFrom(
PROPERTY_MANAGER,
AddressZero,
tokenId,
grantor.address,
userOne.address,
expirationDate,
HashZero,
),
).to.be.revertedWith('RolesRegistry: sender must be approved')
})
})

describe('Revoke role from', async () => {
it('should revoke role from', async () => {
await expect(
RolesRegistry.connect(operator).revokeRoleFrom(
PROPERTY_MANAGER,
AddressZero,
tokenId,
grantor.address,
userOne.address,
),
)
.to.emit(RolesRegistry, 'RoleRevoked')
.withArgs(PROPERTY_MANAGER, AddressZero, tokenId, grantor.address, userOne.address)
})
it('should NOT revoke role from if operator is not approved', async () => {
if (approval === 'Approval for TokenId') {
await RolesRegistry.connect(grantor).approveRole(AddressZero, tokenId, operator.address, false)
} else {
await RolesRegistry.connect(grantor).setRoleApprovalForAll(AddressZero, operator.address, false)
}
await expect(
RolesRegistry.connect(operator).revokeRoleFrom(
PROPERTY_MANAGER,
AddressZero,
tokenId,
grantor.address,
userOne.address,
),
).to.be.revertedWith('RolesRegistry: sender must be approved')
})
})
})
}
})
})
})

0 comments on commit 0b4e92e

Please sign in to comment.