Skip to content

Commit

Permalink
feat: full test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Oct 16, 2023
1 parent 2b47f7c commit a21129b
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions test/utils/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ describe('Roles', () => {
);
});

it('should revert on transferRoles if transferred to an invalid account', async () => {
const roles = [1, 2, 3];

await expectRevert(
(gasOptions) => testRoles.transferRoles(AddressZero, roles, gasOptions),
testRoles,
'InvalidProposedAccount',
{
account: AddressZero,
},
);

await expectRevert(
(gasOptions) =>
testRoles.transferRoles(ownerWallet.address, roles, gasOptions),
testRoles,
'InvalidProposedAccount',
{
account: ownerWallet.address,
},
);
});

it('should revert on proposeRoles if called by an account without all the proposed roles', async () => {
const roles = [1, 2, 3];

Expand All @@ -207,7 +230,7 @@ describe('Roles', () => {
);
});

it('should revert on proposeRoles if proposed to a wrong account', async () => {
it('should revert on proposeRoles if proposed to an invalid account', async () => {
const roles = [1, 2, 3];

await expectRevert(
Expand Down Expand Up @@ -260,9 +283,11 @@ describe('Roles', () => {
});

describe('positive tests', () => {
let roleSets;

beforeEach(async () => {
const accounts = [ownerWallet.address];
const roleSets = [[1, 2, 3]];
roleSets = [[1, 2, 3]];

testRoles = await testRolesFactory
.deploy(accounts, roleSets)
Expand All @@ -275,6 +300,54 @@ describe('Roles', () => {
expect(currentRoles).to.equal(14); // 14 is the binary representation of roles [1, 2, 3]
});

it('should return if an account has a specific role', async () => {
const hasRole = await testRoles.hasRole(
ownerWallet.address,
roleSets[0][0],
);

expect(hasRole).to.be.true;

const hasRoleNegative = await testRoles.hasRole(
userWallet.address,
roleSets[0][0],
);

expect(hasRoleNegative).to.be.false;
});

it('should return if an account has all the roles', async () => {
const hasAllTheRoles = await testRoles.hasAllTheRoles(
ownerWallet.address,
roleSets[0],
);

expect(hasAllTheRoles).to.be.true;

const hasAllTheRolesNegative = await testRoles.hasAllTheRoles(
userWallet.address,
roleSets[0],
);

expect(hasAllTheRolesNegative).to.be.false;
});

it('should return if an account has any of the roles', async () => {
const hasAnyRoles = await testRoles.hasAnyOfRoles(
ownerWallet.address,
roleSets[0],
);

expect(hasAnyRoles).to.be.true;

const hasAnyRolesNegative = await testRoles.hasAnyOfRoles(
userWallet.address,
roleSets[0],
);

expect(hasAnyRolesNegative).to.be.false;
});

it('should transfer roles in one step', async () => {
const roles = [1, 2];

Expand Down

0 comments on commit a21129b

Please sign in to comment.