-
Notifications
You must be signed in to change notification settings - Fork 0
add back code #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
contracts/CreditGuild.sol
Outdated
| } | ||
|
|
||
| function register(address newMember) public virtual { | ||
| require(membersArray.length == 3, "!3 members"); |
There was a problem hiding this comment.
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);
}
contracts/CreditGuild.sol
Outdated
| function stake() public virtual { | ||
|
|
||
| // get total DAI | ||
| uint256 DAOBalance = balanceOf(address(this)); |
There was a problem hiding this comment.
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) ? |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
contracts/CreditGuild.sol
Outdated
|
|
||
| } | ||
|
|
||
| // // calls before every ERC721 call |
There was a problem hiding this comment.
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]); | ||
|
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
|
|
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 () => {
// ....
});
});There was a problem hiding this comment.
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);
No description provided.