Skip to content

Commit

Permalink
Categorize proposal fixed, claim reward test case updated
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsam4 committed Aug 25, 2018
1 parent 80a0044 commit 4596919
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion contracts/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ contract Governance is Upgradeable {
checkProposalValidity(_proposalId)
{
uint dappIncentive = proposalCategory.getCatIncentive(_categoryId);
require(memberRole.checkRoleIdByAddress(msg.sender, 2) || msg.sender == governanceDat.getProposalOwner(_proposalId));
require(memberRole.checkRoleIdByAddress(msg.sender, 1) || msg.sender == governanceDat.getProposalOwner(_proposalId));
require(dappIncentive <= govBlocksToken.balanceOf(poolAddress));

uint category = proposalCategory.getCategoryIdBySubId(_categoryId);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ProposalCategory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ contract ProposalCategory is Governed {
)
public
{
if (allSubCategory.length < 18) {
if (allSubCategory.length < 17) {
allSubIdByCategory[_mainCategoryId].push(allSubCategory.length);
allSubCategory.push(SubCategory(
_subCategoryName,
Expand Down
31 changes: 23 additions & 8 deletions test/04_BasicGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ contract('Proposal, solution and voting', function([owner, ab, member]) {
'New Category',
[1, 3],
[1, 1],
[1, 3],
[0],
[48548564156864, 645564561546]
);
let c2 = await pc.getCategoryLength();
Expand All @@ -214,7 +214,7 @@ contract('Proposal, solution and voting', function([owner, ab, member]) {
cat.toNumber() - 1,
sampleAddress,
'0x4164',
[1, 1, 1],
[100, 100, 100],
[40, 40, 20]
);
let c2 = await pc.getSubCategoryLength();
Expand All @@ -224,14 +224,13 @@ contract('Proposal, solution and voting', function([owner, ab, member]) {
it('Should create a proposal with solution', async function() {
this.timeout(100000);
p1 = await gd.getAllProposalIdsLengthByAddress(owner);
let c1 = await pc.getSubCategoryLength();
let c = c1.toNumber() - 1;
const c = await pc.getSubCategoryLength();
await gv.createProposalwithSolution(
'Add new member',
'Add new member',
'Addnewmember',
0,
c,
c.toNumber() - 1,
'Add new member',
'0x5465'
);
Expand Down Expand Up @@ -304,9 +303,16 @@ contract('Proposal, solution and voting', function([owner, ab, member]) {
this.timeout(100000);
p = await gd.getAllProposalIdsLengthByAddress(owner);
p = p.toNumber();
await sv.proposalVoting(p, [0], { from: member });
await sv.proposalVoting.call(p, [0], { from: member });
});

it('Should allow to vote for same solution as AB', async function() {
this.timeout(100000);
p = await gd.getAllProposalIdsLengthByAddress(owner);
p = p.toNumber();
await sv.proposalVoting(p, [2], { from: member });
let vid = await sv.getVoteIdAgainstMember(member, p);
assert.isAtLeast(vid.toNumber(), 1, 'Vote not added');
assert.isAtLeast(vid.toNumber(), 2, 'Vote not added');
});

it('Should close the proposal once all members have voted', async function() {
Expand All @@ -315,12 +321,21 @@ contract('Proposal, solution and voting', function([owner, ab, member]) {
p = p.toNumber();
await sv.closeProposalVote(p);
let iv = await gd.getProposalFinalVerdict(p);
assert.equal(iv.toNumber(), 0, 'Incorrect final Verdict');
assert.equal(iv.toNumber(), 2, 'Incorrect final Verdict');
});

it('Should claim pending reward/reputation', async function() {
this.timeout(100000);
let rep1 = await gd.getMemberReputation(owner);
let pr = await pl.getPendingReward(owner);
assert.equal(pr[1].toNumber(), 0);
assert.isAtLeast(pr[0].toNumber(), 40);
pr = await pl.getPendingReward(ab);
assert.equal(pr[1].toNumber(), 0);
assert.isAtLeast(pr[0].toNumber(), 40);
pr = await pl.getPendingReward(member);
assert.equal(pr[1].toNumber(), 0);
assert.isAtLeast(pr[0].toNumber(), 0);
await pl.claimReward(owner);
await pl.claimReward(ab);
await pl.claimReward(member);
Expand Down
20 changes: 17 additions & 3 deletions test/07_Governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,35 @@ contract('Governance', ([owner, notOwner]) => {
);
p1 = await gd.getAllProposalIdsLengthByAddress(owner);
await catchRevert(
gv.categorizeProposal(p1.toNumber() + 1, 9, { from: notOwner })
gv.categorizeProposal(p1.toNumber(), 9, { from: notOwner })
);
await catchRevert(
gv.categorizeProposal(p1.toNumber() + 1, 10, { from: notOwner })
gv.categorizeProposal(p1.toNumber(), 10, { from: notOwner })
);
});

it('Should allow authorized people to categorize multiple times', async () => {
await mr.updateMemberRole(notOwner, 1, true, 356800000054);
await gbt.transfer(notOwner, amount);
await gbt.lock('GOV', amount, 54685456133563456, { from: notOwner });
await gv.categorizeProposal(p1.toNumber(), 10, { from: notOwner });
p1 = await gd.getAllProposalIdsLengthByAddress(owner);
await gv.categorizeProposal(p1.toNumber(), 9, { from: notOwner });
await gv.categorizeProposal(p1.toNumber(), 4);
const category = await gd.getProposalCategory(p1.toNumber());
assert.equal(category.toNumber(), 4, 'Category not set properly');
});

it('Should claim rewards', async () => {
const b1 = await gbt.balanceOf(owner);
const g1 = await gv.getMemberDetails(owner);
let pr = await pl.getPendingReward(owner);
assert.equal(pr[0].toNumber(), 0);
assert.isAtLeast(pr[1].toNumber(), 100000);
pr = await pl.getPendingReward(notOwner);
assert.equal(pr[0].toNumber(), 0);
assert.isAtLeast(pr[1].toNumber(), 0);
await pl.claimReward(owner);
await pl.claimReward(notOwner);
const b2 = await gbt.balanceOf(owner);
const g2 = await gv.getMemberDetails(owner);
b2.should.be.bignumber.above(b1);
Expand Down
21 changes: 6 additions & 15 deletions test/11_ProposalCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ contract('Proposal Category', function([owner, taker]) {
assert.equal(g11[1].toNumber(), 1);
const g12 = await pc.getCategoryIncentive(0);
assert.equal(g12[1].toNumber(), 0);
await pc.addInitialSubC(
'Yo',
'yo',
1,
sampleAddress,
'0x4164',
[1, 1, 1],
[1, 1, 1]
);
const g14 = await pc.getMinStake(9);
assert.isAbove(g14.toNumber(), 1);
const g15 = await pc.getRoleMajorityVoteAtIndex(4, 0);
Expand All @@ -64,15 +55,15 @@ contract('Proposal Category', function([owner, taker]) {
// will throw once owner's permissions are revoked
await pc.addNewCategory('Yo', [1], [1], [1], [1]);
await catchRevert(pc.addNewCategory('Yo', [1, 2], [1], [1], [1]));
let c2 = await pc.getCategoryLength();
const c2 = await pc.getCategoryLength();
assert.isAbove(c2.toNumber(), c1.toNumber(), 'category not added');
});

it('Should update a proposal category', async function() {
this.timeout(100000);
let c1 = await pc.getCategoryLength();
c1 = c1.toNumber() - 1;
let cat1 = await pc.getCategoryName(c1);
const cat1 = await pc.getCategoryName(c1);
// will throw once owner's permissions are revoked
await pc.updateCategory(c1, 'YoYo', [1], [1], [1], [1]);
await catchRevert(pc.updateCategory(c1, 'YoYo', [1, 1], [1], [1], [1]));
Expand All @@ -82,7 +73,7 @@ contract('Proposal Category', function([owner, taker]) {

it('Should add a proposal sub category', async function() {
this.timeout(100000);
let c1 = await pc.getSubCategoryLength();
const c1 = await pc.getSubCategoryLength();
// will throw once owner's permissions are revoked
await pc.addNewSubCategory(
'Yo',
Expand All @@ -93,15 +84,15 @@ contract('Proposal Category', function([owner, taker]) {
[1, 1, 1],
[1, 1, 1]
);
let c2 = await pc.getSubCategoryLength();
const c2 = await pc.getSubCategoryLength();
assert.isAbove(c2.toNumber(), c1.toNumber(), 'Sub category not added');
});

it('Should update a proposal category', async function() {
this.timeout(100000);
let c1 = await pc.getCategoryLength();
c1 = c1.toNumber() - 1;
let cat1 = await pc.getSubCategoryName(c1);
const cat1 = await pc.getSubCategoryName(c1);
// will throw once owner's permissions are revoked
await pc.updateSubCategory(
'YoYo',
Expand All @@ -112,7 +103,7 @@ contract('Proposal Category', function([owner, taker]) {
[1, 1, 1],
[1, 1, 1]
);
let cat2 = await pc.getSubCategoryName(c1);
const cat2 = await pc.getSubCategoryName(c1);
assert.notEqual(cat1, cat2, 'Sub category not updated');
});
});

0 comments on commit 4596919

Please sign in to comment.