From 66f1a7cc6e63e73e73beebf1a178daa60ed505d9 Mon Sep 17 00:00:00 2001 From: Daksh Miglani Date: Mon, 10 May 2021 03:46:55 +0530 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20getRoleMember=20and=20ge?= =?UTF-8?q?tRoleMemberCount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/01_insta_access_control.js | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/01_insta_access_control.js b/test/01_insta_access_control.js index 43defdb7..cd24a164 100644 --- a/test/01_insta_access_control.js +++ b/test/01_insta_access_control.js @@ -130,4 +130,44 @@ describe("Test InstaAccessControl contract", () => { false ); }); + + it("should do role count properly", async () => { + expect(await masterAccessControl.getRoleMemberCount(TEST_ROLE)).to.eq(0); + + await masterAccessControl.grantRole(TEST_ROLE, account.address); + + expect(await masterAccessControl.getRoleMemberCount(TEST_ROLE)).to.eq(1); + + await masterAccessControl.grantRole(TEST_ROLE, instaMaster.address); + + expect(await masterAccessControl.getRoleMemberCount(TEST_ROLE)).to.eq(2); + + await masterAccessControl.revokeRole(TEST_ROLE, instaMaster.address); + + expect(await masterAccessControl.getRoleMemberCount(TEST_ROLE)).to.eq(1); + }); + + it("should get member correctly by index", async () => { + await expect( + masterAccessControl.getRoleMember(TEST_ROLE, 0) + ).to.rejectedWith(/EnumerableSet: index out of bounds/); + + await masterAccessControl.grantRole(TEST_ROLE, account.address); + + expect(await masterAccessControl.getRoleMember(TEST_ROLE, 0)).to.eq( + account.address + ); + + await masterAccessControl.grantRole(TEST_ROLE, instaMaster.address); + + expect(await masterAccessControl.getRoleMember(TEST_ROLE, 1)).to.eq( + instaMaster.address + ); + + await masterAccessControl.revokeRole(TEST_ROLE, instaMaster.address); + + await expect( + masterAccessControl.getRoleMember(TEST_ROLE, 1) + ).to.rejectedWith(/EnumerableSet: index out of bounds/); + }); });