Skip to content

Conversation

MilGard91
Copy link
Contributor

@MilGard91 MilGard91 commented Dec 13, 2022

Context

Issue: #345

Changes proposed in this pull request

Added unit test to increase the coverage of MomberRoles.

Test plan

N/A

Checklist

  • Rebased the base branch
  • Attached corresponding Github issue
  • Prefixed the name with the type of change (i.e. feat, chore, test)
  • Performed a self-review of my own code
  • Followed the style guidelines of this project
  • Made corresponding changes to the documentation
  • Didn't generate new warnings
  • Didn't generate failures on existing tests
  • Added tests that prove my fix is effective or that my feature works

Review

When reviewing a PR, please indicate intention in comments using the following emojis:

  • 🍰 = Nice to have but not essential.
  • 💡 = Suggestion or a comment based on personal opinion
  • 🔨 = I believe this should be changed.
  • 🤔 = I don’t understand something, do you mind giving me more context?
  • 🚀 = Feedback

@MilGard91 MilGard91 changed the title Add test for Member Role Test: Unit tests for Member Role Dec 13, 2022
@MilGard91 MilGard91 force-pushed the test/member-roles branch 2 times, most recently from 3c92d33 to 8725772 Compare December 13, 2022 22:37
@MilGard91 MilGard91 marked this pull request as ready for review December 13, 2022 22:38
await memberRoles.connect(governanceContracts[0]).changeAuthorized(Role.AdvisoryBoard, defaultSender.address);
const authorizedAddressAfter = await memberRoles.authorized(Role.AdvisoryBoard);

expect(authorizedAddressBefore).not.to.be.eq(defaultSender.address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but we've been spelling out eq as equal in other tests

const { defaultSender, governanceContracts } = this.accounts;

const authorizedAddressBefore = await memberRoles.authorized(Role.AdvisoryBoard);
await memberRoles.connect(governanceContracts[0]).changeAuthorized(Role.AdvisoryBoard, defaultSender.address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use something else other than defaultSender.address

When you write tests, look to make the values arbitrary for generality, whatever that thing that you are switching to is. Arbitrary within constraints of course (eg. arbitrary member)

).to.be.reverted;
await expect(
memberRoles.connect(defaultSender).changeAuthorized(Role.AdvisoryBoard, governanceContracts[0].address),
).to.not.reverted;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to.not.be.reverted

const { governanceContracts } = this.accounts;

const maxABCountBefore = await memberRoles.maxABCount();
await memberRoles.connect(governanceContracts[0]).changeMaxABCount(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use named constants

const newMaxABCount = 2;

}
// Setting AB Member
const [abMember] = accounts.advisoryBoardMembers;
await master.enrollMember(abMember.address, 2);
Copy link
Contributor

@danoctavian danoctavian Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the right constant instead of the 2. Role.whatever

same as below

} = this.accounts;

const [memberAddress, isActive] = await memberRoles.memberAtIndex(Role.Member, 0);
expect(member.address).to.be.equal(memberAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the other way around.

expect(memberAddress).to.be.equal(member.address)

it('should clear storage', async function () {
const { memberRoles } = this.contracts;

await expect(memberRoles.storageCleanup()).to.not.reverted;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to.not.be.reverted

const isMemberABMember = await memberRoles.checkRole(member.address, Role.AdvisoryBoard);

expect(isMemberMember).to.be.equal(true);
expect(isMemberNonMember).to.be.equal(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is odd why is this true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const isABMemberABMember = await memberRoles.checkRole(advisoryBoardMember.address, Role.AdvisoryBoard);

expect(isABMemberMember).to.be.equal(true);
expect(isABMemberNonMember).to.be.equal(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also odd that it's true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be "correct" but warrants at least a comment to clarify why since it looks counterintuitive

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@danoctavian danoctavian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes necessary

@roxdanila roxdanila linked an issue Dec 15, 2022 that may be closed by this pull request
Copy link
Contributor

@danoctavian danoctavian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

enum Role {
NonMember,
Member,
AdvisoryBord,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mispelling here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Unassigned (capitalization) and AdvisoryBoard (missing "a").

Copy link
Contributor

@danoctavian danoctavian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but let's fix that mispelling as well since we're here

const { InternalContractsIDs } = require('../utils').constants;
const { expect } = require('chai');
const { hex } = require('../../../lib/helpers');
const { ZERO_ADDRESS } = require('../../../lib/constants');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use AddressZero from ethers.constants instead

Comment on lines 7 to 16
before(async function () {
const { quotationData, memberRoles } = this.contracts;
const { governanceContracts, defaultSender } = this.accounts;
await quotationData.connect(governanceContracts[0]).setKycAuthAddress(defaultSender.address);
await memberRoles.connect(governanceContracts[0]).setKycAuthAddress(quotationData.address);
});

it('should change authorized address for the role', async function () {
const { memberRoles, master } = this.contracts;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given there's only one test here, move the contents of the before in the test itself

@MilGard91 MilGard91 force-pushed the test/member-roles branch 2 times, most recently from a100367 to bd9c68f Compare January 4, 2023 15:44
@roxdanila roxdanila force-pushed the test/member-roles branch 2 times, most recently from 5caf4db to 08d767e Compare January 5, 2023 11:57
Copy link
Contributor

@roxdanila roxdanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still open questions

@roxdanila roxdanila merged commit 9b86db3 into nexus-v2 Jan 6, 2023
@roxdanila roxdanila deleted the test/member-roles branch January 6, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MemberRoles unit tests: Increase coverage to 100%
4 participants