Skip to content

Conversation

@sarahmjohnson
Copy link
Owner

No description provided.

}

function register(address newMember) public virtual {
require(membersArray.length == 3, "!3 members");
Copy link
Collaborator

@GeraldHost GeraldHost May 11, 2022

Choose a reason for hiding this comment

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

Here we need to check that at least 3 members have vouched for this user. This is just checking that there are 3 members in the DAO which will always be true after the constructor is run. You need something like this:

    function register(address[] members) {
        require(members.length == 3, "!3 members");

        for (uint i = 0; i < members.length; i++) {
            // check account is vouched for by this member
            require(userManager.getVouchingAmount(members[i], msg.sender) > 0, "!vouching");
            // check address is member
            require(members[member], "!member");
        }

        // Mint the NFT (membership NFT)
        _mint(msg.sender, id);
        // add to members
        members[msg.sender] = true;
        // Guild vouches for this new member
        userManager.updateTrust(msg.sender, vouchAmount);
        // transfer membership fee
        dai.transferFrom(msg.sender, address(this), membershipFee);
    }

function stake() public virtual {

// get total DAI
uint256 DAOBalance = balanceOf(address(this));
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to check the DAI balance as DAI is what is being staked into union:

uint bal = dai.balanceOf(address(this));
dai.approve(address(userManager), bal);
userManager.stake(bal);

address member = initialMembers[i];

// check that this member is vouching for the DAO
// TODO: shouldn't this be: getVouchingAmount(address(this), member) ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you want to check that the member is vouching for the contract. The signature is getVouchingAmount(address staker, address borrower) the staker is the member and the borrower is the contract (address(this))


bool result = balanceOf(potentialMember) > 0;
emit CheckIsMember(result);
return(result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Syntax wise this is more common return result You can look at using this formatter to provide consistent formatting to your code: https://github.com/prettier-solidity/prettier-plugin-solidity


}

// // calls before every ERC721 call
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to add this back in, in order to prevent transfers.

expect(result[0]).to.equal(array2[0]);
expect(result[1]).to.equal(array2[1]);
expect(result[2]).to.equal(array2[2]);

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should also check these address are now members. You could write this test like this.

const memberAddresses = [MEMBER1.address, MEMBER2.address, MEMBER3.address];
const tx = await creditGuild.initialize(...memberAddresses);
const resp = await tx.wait();
const initialMembers = resp.events[resp.events.length - 1].args.initialMembers;
for (let i = 0; i < memberAddresses.length; i++) {
      expect(initialMembers[i]).eq(memberAddresses[i]);
      expect(await creditGuild.checkIsMember(memberAddresses[i])).eq(true);
}

it("Should check if address is a member", async function () {

// MEMBER1 should be a member
const potentialMember = MEMBER1.address;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For both these checks you can just do

expect(await creditGuild.checkIsMember(potentialMember).eq(true);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than looking at the output event.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a few other places below where you do this that can be updated to.

const resp = await tx.wait();
result = resp.events[resp.events.length - 1].args.vouchAmount;
expect(result).to.equal(vouchAmount);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you will also need to check the UserManager... in fact there is not much point testing this in a unit test.

result4 = resp4.events[resp4.events.length - 1].args.result;
expect(result4).to.equal(false);

await expect(creditGuild.burnMembership(JACK.address)).to.be.revertedWith('!member');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would try and seperate out unhappy paths into a seperate it function ie:

describe("@method burnMembership()", () => {
  it("happy path: removes member from the DAO", async () => {
     // ....
  });

  it("happy path: burns the members NFT", async () => {
     // ....
  });

  it("unhappy path: cannot burnMembership for non member", async () => {
     // ....
  });
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this you also want to include a test to check that the NFT has been burnt something like:

const bal = await creditGuild.balanceOf(member);
expect(bal).lte(0);

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.

2 participants