test: add more token role hardhat tests
This commit is contained in:
parent
ea3a50f2a8
commit
f6510106cd
|
|
@ -59,7 +59,7 @@ abstract contract FleekAccessControl {
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
Roles role,
|
Roles role,
|
||||||
address account
|
address account
|
||||||
) public requireCollectionRole(Roles.Owner) {
|
) public requireTokenRole(tokenId, Roles.Owner) {
|
||||||
_grantTokenRole(tokenId, role, account);
|
_grantTokenRole(tokenId, role, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ abstract contract FleekAccessControl {
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
Roles role,
|
Roles role,
|
||||||
address account
|
address account
|
||||||
) public requireCollectionRole(Roles.Owner) {
|
) public requireTokenRole(tokenId, Roles.Owner) {
|
||||||
_revokeTokenRole(tokenId, role, account);
|
_revokeTokenRole(tokenId, role, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,8 +224,25 @@ describe('FleekERC721', () => {
|
||||||
expect(hasRole).to.be.true;
|
expect(hasRole).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add a new controller', async () => {
|
||||||
|
const { contract, owner, otherAccount } = fixture;
|
||||||
|
await contract.grantTokenRole(
|
||||||
|
tokenId,
|
||||||
|
ROLES.CONTROLLER,
|
||||||
|
otherAccount.address
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await contract.hasTokenRole(
|
||||||
|
tokenId,
|
||||||
|
ROLES.CONTROLLER,
|
||||||
|
otherAccount.address
|
||||||
|
)
|
||||||
|
).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
it('should add a list of controllers', async () => {
|
it('should add a list of controllers', async () => {
|
||||||
const { contract, owner } = fixture;
|
const { contract } = fixture;
|
||||||
await contract.grantTokenRole(
|
await contract.grantTokenRole(
|
||||||
tokenId,
|
tokenId,
|
||||||
ROLES.CONTROLLER,
|
ROLES.CONTROLLER,
|
||||||
|
|
@ -245,6 +262,26 @@ describe('FleekERC721', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add a list of owners', async () => {
|
||||||
|
const { contract, owner } = fixture;
|
||||||
|
await contract.grantTokenRole(
|
||||||
|
tokenId,
|
||||||
|
ROLES.OWNER,
|
||||||
|
'0x7ED735b7095C05d78dF169F991f2b7f1A1F1A049'
|
||||||
|
);
|
||||||
|
await contract.grantTokenRole(
|
||||||
|
tokenId,
|
||||||
|
ROLES.OWNER,
|
||||||
|
'0x2FEd6Ef3c495922263B403319FA6DDB323DD49E3'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(await contract.getTokenRoleMembers(tokenId, ROLES.OWNER)).to.eql([
|
||||||
|
owner.address,
|
||||||
|
'0x7ED735b7095C05d78dF169F991f2b7f1A1F1A049',
|
||||||
|
'0x2FEd6Ef3c495922263B403319FA6DDB323DD49E3',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should not match the owner role for other account', async () => {
|
it('should not match the owner role for other account', async () => {
|
||||||
const { contract, otherAccount } = fixture;
|
const { contract, otherAccount } = fixture;
|
||||||
const hasRole = await contract.hasTokenRole(
|
const hasRole = await contract.hasTokenRole(
|
||||||
|
|
@ -256,13 +293,18 @@ describe('FleekERC721', () => {
|
||||||
expect(hasRole).to.be.false;
|
expect(hasRole).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add a new controller', async () => {
|
it('should remove an added controller', async () => {
|
||||||
const { contract, owner, otherAccount } = fixture;
|
const { contract, owner, otherAccount } = fixture;
|
||||||
await contract.grantTokenRole(
|
await contract.grantTokenRole(
|
||||||
tokenId,
|
tokenId,
|
||||||
ROLES.CONTROLLER,
|
ROLES.CONTROLLER,
|
||||||
otherAccount.address
|
otherAccount.address
|
||||||
);
|
);
|
||||||
|
await contract.revokeTokenRole(
|
||||||
|
tokenId,
|
||||||
|
ROLES.CONTROLLER,
|
||||||
|
otherAccount.address
|
||||||
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await contract.hasTokenRole(
|
await contract.hasTokenRole(
|
||||||
|
|
@ -270,7 +312,7 @@ describe('FleekERC721', () => {
|
||||||
ROLES.CONTROLLER,
|
ROLES.CONTROLLER,
|
||||||
otherAccount.address
|
otherAccount.address
|
||||||
)
|
)
|
||||||
).to.be.true;
|
).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transfer the token owner role', async () => {
|
it('should transfer the token owner role', async () => {
|
||||||
|
|
@ -296,6 +338,47 @@ describe('FleekERC721', () => {
|
||||||
|
|
||||||
expect(await contract.getTokenRoleMembers(tokenId, 1)).to.eql([]);
|
expect(await contract.getTokenRoleMembers(tokenId, 1)).to.eql([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not be able to add address role', async () => {
|
||||||
|
const { contract, owner, otherAccount } = fixture;
|
||||||
|
await expect(
|
||||||
|
contract
|
||||||
|
.connect(otherAccount)
|
||||||
|
.grantTokenRole(tokenId, ROLES.OWNER, otherAccount.address)
|
||||||
|
).to.be.revertedWith('FleekAccessControl: must have token role');
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
contract
|
||||||
|
.connect(otherAccount)
|
||||||
|
.grantTokenRole(tokenId, ROLES.CONTROLLER, otherAccount.address)
|
||||||
|
).to.be.revertedWith('FleekAccessControl: must have token role');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not be able to remove address role', async () => {
|
||||||
|
const { contract, owner, otherAccount } = fixture;
|
||||||
|
await expect(
|
||||||
|
contract
|
||||||
|
.connect(otherAccount)
|
||||||
|
.revokeTokenRole(tokenId, ROLES.OWNER, otherAccount.address)
|
||||||
|
).to.be.revertedWith('FleekAccessControl: must have token role');
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
contract
|
||||||
|
.connect(otherAccount)
|
||||||
|
.revokeTokenRole(tokenId, ROLES.CONTROLLER, otherAccount.address)
|
||||||
|
).to.be.revertedWith('FleekAccessControl: must have token role');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to add token role after owner role granted', async () => {
|
||||||
|
const { contract, owner, otherAccount } = fixture;
|
||||||
|
await contract.grantTokenRole(tokenId, ROLES.OWNER, otherAccount.address);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await contract
|
||||||
|
.connect(otherAccount)
|
||||||
|
.grantTokenRole(tokenId, ROLES.CONTROLLER, otherAccount.address)
|
||||||
|
).to.not.be.reverted;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Collection Roles', () => {
|
describe('Collection Roles', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue