eslint fix and test timeout longer
This commit is contained in:
parent
a12ade05d9
commit
526630f7f4
|
@ -37,13 +37,13 @@
|
||||||
"ethereumjs-testrpc": "^3.0.5",
|
"ethereumjs-testrpc": "^3.0.5",
|
||||||
"random-bytes": "^1.0.0",
|
"random-bytes": "^1.0.0",
|
||||||
"mocha": "^3.5.0",
|
"mocha": "^3.5.0",
|
||||||
"chai": "^4.1.0",
|
|
||||||
"solcpiler": "0.0.4"
|
"solcpiler": "0.0.4"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/Giveth/liquidpledging#readme",
|
"homepage": "https://github.com/Giveth/liquidpledging#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.4.0",
|
"async": "^2.4.0",
|
||||||
"ethconnector": "0.0.25",
|
"ethconnector": "0.0.25",
|
||||||
"runethtx": "0.1.0"
|
"runethtx": "0.1.0",
|
||||||
|
"chai": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
|
/* eslint-env mocha */
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
const ethConnector = require('ethconnector');
|
const ethConnector = require('ethconnector');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const assert = chai.assert;
|
const getBalance = require('runethtx').getBalance;
|
||||||
const LiquidPledging = require('../js/liquidPledging.js')(true);
|
const LiquidPledging = require('../js/liquidPledging.js')(true);
|
||||||
const Vault = require('../js/vault.js');
|
const Vault = require('../js/vault.js');
|
||||||
const assertFail = require("./helpers/assertFail");
|
const assertFail = require('./helpers/assertFail');
|
||||||
const getBalance = require("runethtx").getBalance;
|
|
||||||
|
const assert = chai.assert;
|
||||||
|
|
||||||
const getNote = async (liquidPledging, idNote) => {
|
const getNote = async (liquidPledging, idNote) => {
|
||||||
const note = {
|
const note = {
|
||||||
|
@ -13,7 +16,7 @@ const getNote = async (liquidPledging, idNote) => {
|
||||||
const res = await liquidPledging.getNote(idNote);
|
const res = await liquidPledging.getNote(idNote);
|
||||||
note.amount = res[0];
|
note.amount = res[0];
|
||||||
note.owner = res[1];
|
note.owner = res[1];
|
||||||
for (let i=1; i <= res[2].toNumber(); i += 1) {
|
for (let i = 1; i <= res[2].toNumber(); i += 1) {
|
||||||
const delegate = {};
|
const delegate = {};
|
||||||
const resd = await liquidPledging.getNoteDelegate(idNote, i);
|
const resd = await liquidPledging.getNoteDelegate(idNote, i);
|
||||||
delegate.id = resd[0].toNumber();
|
delegate.id = resd[0].toNumber();
|
||||||
|
@ -28,14 +31,14 @@ const getNote = async (liquidPledging, idNote) => {
|
||||||
if (res[5].toNumber()) {
|
if (res[5].toNumber()) {
|
||||||
note.oldProject = res[5].toNumber();
|
note.oldProject = res[5].toNumber();
|
||||||
}
|
}
|
||||||
if (res[6].toNumber() == 0) {
|
if (res[6].toNumber() === 0) {
|
||||||
note.paymentState = "NotPaid";
|
note.paymentState = 'NotPaid';
|
||||||
} else if (res[6].toNumber() == 1) {
|
} else if (res[6].toNumber() === 1) {
|
||||||
note.paymentState = "Paying";
|
note.paymentState = 'Paying';
|
||||||
} else if (res[6].toNumber() == 2) {
|
} else if (res[6].toNumber() === 2) {
|
||||||
note.paymentState = "Paid";
|
note.paymentState = 'Paid';
|
||||||
} else {
|
} else {
|
||||||
note.paymentState = "Unknown";
|
note.paymentState = 'Unknown';
|
||||||
}
|
}
|
||||||
return note;
|
return note;
|
||||||
};
|
};
|
||||||
|
@ -43,19 +46,19 @@ const getNote = async (liquidPledging, idNote) => {
|
||||||
const getManager = async (liquidPledging, idManager) => {
|
const getManager = async (liquidPledging, idManager) => {
|
||||||
const manager = {};
|
const manager = {};
|
||||||
const res = await liquidPledging.getNoteManager(idManager);
|
const res = await liquidPledging.getNoteManager(idManager);
|
||||||
if (res[0].toNumber() == 0) {
|
if (res[0].toNumber() === 0) {
|
||||||
manager.paymentState = "Donor";
|
manager.paymentState = 'Donor';
|
||||||
} else if (res[0].toNumber() === 1) {
|
} else if (res[0].toNumber() === 1) {
|
||||||
manager.paymentState = "Delegate";
|
manager.paymentState = 'Delegate';
|
||||||
} else if (res[0].toNumber() === 2) {
|
} else if (res[0].toNumber() === 2) {
|
||||||
manager.paymentState = "Project";
|
manager.paymentState = 'Project';
|
||||||
} else {
|
} else {
|
||||||
manager.paymentState = "Unknown";
|
manager.paymentState = 'Unknown';
|
||||||
}
|
}
|
||||||
manager.addr = res[1];
|
manager.addr = res[1];
|
||||||
manager.name = res[2];
|
manager.name = res[2];
|
||||||
manager.commitTime = res[3].toNumber();
|
manager.commitTime = res[3].toNumber();
|
||||||
if (manager.paymentState == "Project") {
|
if (manager.paymentState === 'Project') {
|
||||||
manager.reviewer = res[4];
|
manager.reviewer = res[4];
|
||||||
manager.canceled = res[5];
|
manager.canceled = res[5];
|
||||||
}
|
}
|
||||||
|
@ -68,19 +71,20 @@ const getState = async (liquidPledging) => {
|
||||||
managers: [null],
|
managers: [null],
|
||||||
};
|
};
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
for (let i=1; i <= nNotes; i += 1) {
|
for (let i = 1; i <= nNotes; i += 1) {
|
||||||
const note = await getNote(liquidPledging, i);
|
const note = await getNote(liquidPledging, i);
|
||||||
st.notes.push(note);
|
st.notes.push(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||||
for (let i=1; i <= nManagers; i += 1) {
|
for (let i = 1; i <= nManagers; i += 1) {
|
||||||
const manager = await getManager(liquidPledging, i);
|
const manager = await getManager(liquidPledging, i);
|
||||||
st.managers.push(manager);
|
st.managers.push(manager);
|
||||||
}
|
}
|
||||||
return st;
|
return st;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
const printState = async(liquidPledging) => {
|
const printState = async(liquidPledging) => {
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
console.log(JSON.stringify(st, null, 2));
|
console.log(JSON.stringify(st, null, 2));
|
||||||
|
@ -89,12 +93,13 @@ const printState = async(liquidPledging) => {
|
||||||
const printBalances = async(liquidPledging) => {
|
const printBalances = async(liquidPledging) => {
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 13);
|
assert.equal(st.notes.length, 13);
|
||||||
for (let i=1; i<=12; i++) {
|
for (let i = 1; i <= 12; i += 1) {
|
||||||
console.log(i, web3.fromWei(st.notes[ i ].amount).toNumber() )
|
console.log(i, ethConnector.web3.fromWei(st.notes[i].amount).toNumber());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
describe("LiquidPledging test", () => {
|
describe('LiquidPledging test', () => {
|
||||||
let web3;
|
let web3;
|
||||||
let accounts;
|
let accounts;
|
||||||
let liquidPledging;
|
let liquidPledging;
|
||||||
|
@ -107,7 +112,7 @@ describe("LiquidPledging test", () => {
|
||||||
let delegate2;
|
let delegate2;
|
||||||
let reviewer;
|
let reviewer;
|
||||||
before((done) => {
|
before((done) => {
|
||||||
ethConnector.init("testrpc", { gasLimit: 4000000 }, () => {
|
ethConnector.init('testrpc', { gasLimit: 4000000 }, () => {
|
||||||
web3 = ethConnector.web3;
|
web3 = ethConnector.web3;
|
||||||
accounts = ethConnector.accounts;
|
accounts = ethConnector.accounts;
|
||||||
donor1 = accounts[1];
|
donor1 = accounts[1];
|
||||||
|
@ -120,38 +125,38 @@ describe("LiquidPledging test", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should deploy LiquidPledgin contract", async () => {
|
it('Should deploy LiquidPledgin contract', async () => {
|
||||||
vault = await Vault.new(web3);
|
vault = await Vault.new(web3);
|
||||||
liquidPledging = await LiquidPledging.new(web3, vault.$address);
|
liquidPledging = await LiquidPledging.new(web3, vault.$address);
|
||||||
await vault.setLiquidPledging(liquidPledging.$address);
|
await vault.setLiquidPledging(liquidPledging.$address);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should create a donor", async () => {
|
it('Should create a donor', async () => {
|
||||||
await liquidPledging.addDonor("Donor1", 86400, {from: donor1});
|
await liquidPledging.addDonor('Donor1', 86400, { from: donor1 });
|
||||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||||
assert.equal(nManagers, 1);
|
assert.equal(nManagers, 1);
|
||||||
const res = await liquidPledging.getNoteManager(1);
|
const res = await liquidPledging.getNoteManager(1);
|
||||||
assert.equal(res[0], 0); // Donor
|
assert.equal(res[0], 0); // Donor
|
||||||
assert.equal(res[1], donor1);
|
assert.equal(res[1], donor1);
|
||||||
assert.equal(res[2], "Donor1");
|
assert.equal(res[2], 'Donor1');
|
||||||
assert.equal(res[3], 86400);
|
assert.equal(res[3], 86400);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should make a donation", async () => {
|
it('Should make a donation', async () => {
|
||||||
await liquidPledging.donate(1, 1, {from: donor1, value: web3.toWei(1)});
|
await liquidPledging.donate(1, 1, { from: donor1, value: web3.toWei(1) });
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
assert.equal(nNotes.toNumber(), 1);
|
assert.equal(nNotes.toNumber(), 1);
|
||||||
const res = await liquidPledging.getNote(1);
|
await liquidPledging.getNote(1);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should create a delegate", async () => {
|
it('Should create a delegate', async () => {
|
||||||
await liquidPledging.addDelegate("Delegate1", {from: delegate1});
|
await liquidPledging.addDelegate('Delegate1', { from: delegate1 });
|
||||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||||
assert.equal(nManagers, 2);
|
assert.equal(nManagers, 2);
|
||||||
const res = await liquidPledging.getNoteManager(2);
|
const res = await liquidPledging.getNoteManager(2);
|
||||||
assert.equal(res[0], 1); // Donor
|
assert.equal(res[0], 1); // Donor
|
||||||
assert.equal(res[1], delegate1);
|
assert.equal(res[1], delegate1);
|
||||||
assert.equal(res[2], "Delegate1");
|
assert.equal(res[2], 'Delegate1');
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Donor should delegate on the delegate ", async () => {
|
it('Donor should delegate on the delegate', async () => {
|
||||||
await liquidPledging.transfer(1, 1, web3.toWei(0.5), 2, {from: donor1});
|
await liquidPledging.transfer(1, 1, web3.toWei(0.5), 2, { from: donor1 });
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
assert.equal(nNotes.toNumber(), 2);
|
assert.equal(nNotes.toNumber(), 2);
|
||||||
const res1 = await liquidPledging.getNote(1);
|
const res1 = await liquidPledging.getNote(1);
|
||||||
|
@ -163,36 +168,36 @@ describe("LiquidPledging test", () => {
|
||||||
const d = await liquidPledging.getNoteDelegate(2, 1);
|
const d = await liquidPledging.getNoteDelegate(2, 1);
|
||||||
assert.equal(d[0], 2);
|
assert.equal(d[0], 2);
|
||||||
assert.equal(d[1], delegate1);
|
assert.equal(d[1], delegate1);
|
||||||
assert.equal(d[2], "Delegate1");
|
assert.equal(d[2], 'Delegate1');
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should create a 2 projects", async () => {
|
it('Should create a 2 projects', async () => {
|
||||||
await liquidPledging.addProject("Project1", reviewer, 86400, {from: adminProject1});
|
await liquidPledging.addProject('Project1', reviewer, 86400, { from: adminProject1 });
|
||||||
|
|
||||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||||
assert.equal(nManagers, 3);
|
assert.equal(nManagers, 3);
|
||||||
const res = await liquidPledging.getNoteManager(3);
|
const res = await liquidPledging.getNoteManager(3);
|
||||||
assert.equal(res[0], 2); // Project type
|
assert.equal(res[0], 2); // Project type
|
||||||
assert.equal(res[1], adminProject1);
|
assert.equal(res[1], adminProject1);
|
||||||
assert.equal(res[2], "Project1");
|
assert.equal(res[2], 'Project1');
|
||||||
assert.equal(res[3], 86400);
|
assert.equal(res[3], 86400);
|
||||||
assert.equal(res[4], reviewer);
|
assert.equal(res[4], reviewer);
|
||||||
assert.equal(res[5], false);
|
assert.equal(res[5], false);
|
||||||
|
|
||||||
await liquidPledging.addProject("Project2", reviewer, 86400, {from: adminProject2});
|
await liquidPledging.addProject('Project2', reviewer, 86400, { from: adminProject2 });
|
||||||
|
|
||||||
const nManagers2 = await liquidPledging.numberOfNoteManagers();
|
const nManagers2 = await liquidPledging.numberOfNoteManagers();
|
||||||
assert.equal(nManagers2, 4);
|
assert.equal(nManagers2, 4);
|
||||||
const res4 = await liquidPledging.getNoteManager(4);
|
const res4 = await liquidPledging.getNoteManager(4);
|
||||||
assert.equal(res4[0], 2); // Project type
|
assert.equal(res4[0], 2); // Project type
|
||||||
assert.equal(res4[1], adminProject2);
|
assert.equal(res4[1], adminProject2);
|
||||||
assert.equal(res4[2], "Project2");
|
assert.equal(res4[2], 'Project2');
|
||||||
assert.equal(res4[3], 86400);
|
assert.equal(res4[3], 86400);
|
||||||
assert.equal(res4[4], reviewer);
|
assert.equal(res4[4], reviewer);
|
||||||
assert.equal(res4[5], false);
|
assert.equal(res4[5], false);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Delegate should assign to project1", async () => {
|
it('Delegate should assign to project1', async () => {
|
||||||
const n = Math.floor(new Date().getTime() / 1000);
|
const n = Math.floor(new Date().getTime() / 1000);
|
||||||
await liquidPledging.transfer(2, 2, web3.toWei(0.2), 3, {from: delegate1});
|
await liquidPledging.transfer(2, 2, web3.toWei(0.2), 3, { from: delegate1 });
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
assert.equal(nNotes.toNumber(), 3);
|
assert.equal(nNotes.toNumber(), 3);
|
||||||
const res3 = await liquidPledging.getNote(3);
|
const res3 = await liquidPledging.getNote(3);
|
||||||
|
@ -203,10 +208,9 @@ describe("LiquidPledging test", () => {
|
||||||
assert.isAbove(res3[4].toNumber(), n + 86000);
|
assert.isAbove(res3[4].toNumber(), n + 86000);
|
||||||
assert.equal(res3[5].toNumber(), 0); // Old Node
|
assert.equal(res3[5].toNumber(), 0); // Old Node
|
||||||
assert.equal(res3[6].toNumber(), 0); // Not Paid
|
assert.equal(res3[6].toNumber(), 0); // Not Paid
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Donor should change his mind and assign half of it to project2", async () => {
|
it('Donor should change his mind and assign half of it to project2', async () => {
|
||||||
const n = Math.floor(new Date().getTime() / 1000);
|
await liquidPledging.transfer(1, 3, web3.toWei(0.1), 4, { from: donor1 });
|
||||||
await liquidPledging.transfer(1, 3, web3.toWei(0.1), 4, {from: donor1});
|
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
assert.equal(nNotes.toNumber(), 4);
|
assert.equal(nNotes.toNumber(), 4);
|
||||||
const res3 = await liquidPledging.getNote(3);
|
const res3 = await liquidPledging.getNote(3);
|
||||||
|
@ -218,11 +222,11 @@ describe("LiquidPledging test", () => {
|
||||||
assert.equal(res4[4], 0);
|
assert.equal(res4[4], 0);
|
||||||
assert.equal(res4[5].toNumber(), 2); // Old Node
|
assert.equal(res4[5].toNumber(), 2); // Old Node
|
||||||
assert.equal(res4[6].toNumber(), 0); // Not Paid
|
assert.equal(res4[6].toNumber(), 0); // Not Paid
|
||||||
});
|
}).timeout(6000);
|
||||||
it("After the time, the project1 should be able to spend part of it", async () => {
|
it('After the time, the project1 should be able to spend part of it', async () => {
|
||||||
const n = Math.floor(new Date().getTime() / 1000);
|
const n = Math.floor(new Date().getTime() / 1000);
|
||||||
await liquidPledging.setMockedTime(n + 86401);
|
await liquidPledging.setMockedTime(n + 86401);
|
||||||
await liquidPledging.withdraw(3, web3.toWei(0.05), {from: adminProject1});
|
await liquidPledging.withdraw(3, web3.toWei(0.05), { from: adminProject1 });
|
||||||
const nNotes = await liquidPledging.numberOfNotes();
|
const nNotes = await liquidPledging.numberOfNotes();
|
||||||
assert.equal(nNotes.toNumber(), 6);
|
assert.equal(nNotes.toNumber(), 6);
|
||||||
const res5 = await liquidPledging.getNote(5);
|
const res5 = await liquidPledging.getNote(5);
|
||||||
|
@ -241,8 +245,8 @@ describe("LiquidPledging test", () => {
|
||||||
assert.equal(res6[4], 0); // commit time
|
assert.equal(res6[4], 0); // commit time
|
||||||
assert.equal(res6[5].toNumber(), 2); // Old Node
|
assert.equal(res6[5].toNumber(), 2); // Old Node
|
||||||
assert.equal(res6[6].toNumber(), 1); // Peinding paid Paid
|
assert.equal(res6[6].toNumber(), 1); // Peinding paid Paid
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should collect the Ether", async () => {
|
it('Should collect the Ether', async () => {
|
||||||
const initialBalance = await getBalance(web3, adminProject1);
|
const initialBalance = await getBalance(web3, adminProject1);
|
||||||
|
|
||||||
await vault.confirmPayment(0);
|
await vault.confirmPayment(0);
|
||||||
|
@ -262,103 +266,103 @@ describe("LiquidPledging test", () => {
|
||||||
assert.equal(res7[4], 0); // commit time
|
assert.equal(res7[4], 0); // commit time
|
||||||
assert.equal(res7[5].toNumber(), 2); // Old Node
|
assert.equal(res7[5].toNumber(), 2); // Old Node
|
||||||
assert.equal(res7[6].toNumber(), 2); // Peinding paid Paid
|
assert.equal(res7[6].toNumber(), 2); // Peinding paid Paid
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Reviewer should be able to cancel project1", async () => {
|
it('Reviewer should be able to cancel project1', async () => {
|
||||||
await liquidPledging.cancelProject(3, {from: reviewer});
|
await liquidPledging.cancelProject(3, { from: reviewer });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.managers[3].canceled , true);
|
assert.equal(st.managers[3].canceled, true);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Should not allow to withdraw from a canceled project", async () => {
|
it('Should not allow to withdraw from a canceled project', async () => {
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0.05);
|
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0.05);
|
||||||
await assertFail(async function() {
|
await assertFail(async () => {
|
||||||
await liquidPledging.withdraw(5, web3.toWei(0.01), {from: adminProject1});
|
await liquidPledging.withdraw(5, web3.toWei(0.01), { from: adminProject1 });
|
||||||
});
|
});
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Delegate should send part of this ETH to project2", async () => {
|
it('Delegate should send part of this ETH to project2', async () => {
|
||||||
await liquidPledging.transfer(2, 5, web3.toWei(0.03), 4,{$extraGas: 100000}, {from: delegate1});
|
await liquidPledging.transfer(2, 5, web3.toWei(0.03), 4,
|
||||||
|
{ $extraGas: 100000 },
|
||||||
|
{ from: delegate1 });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 9);
|
assert.equal(st.notes.length, 9);
|
||||||
assert.equal(web3.fromWei(st.notes[ 8 ].amount).toNumber(), 0.03);
|
assert.equal(web3.fromWei(st.notes[8].amount).toNumber(), 0.03);
|
||||||
assert.equal(st.notes[8].owner, 1);
|
assert.equal(st.notes[8].owner, 1);
|
||||||
assert.equal(st.notes[8].delegates.length, 1);
|
assert.equal(st.notes[8].delegates.length, 1);
|
||||||
assert.equal(st.notes[8].delegates[0].id, 2);
|
assert.equal(st.notes[8].delegates[0].id, 2);
|
||||||
assert.equal(st.notes[8].proposedProject, 4);
|
assert.equal(st.notes[8].proposedProject, 4);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Donor should be able to send the remaining to project2", async () => {
|
it('Donor should be able to send the remaining to project2', async () => {
|
||||||
await liquidPledging.transfer(1, 5, web3.toWei(0.02), 4, {from: donor1});
|
await liquidPledging.transfer(1, 5, web3.toWei(0.02), 4, { from: donor1 });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 9);
|
assert.equal(st.notes.length, 9);
|
||||||
assert.equal(web3.fromWei(st.notes[ 5 ].amount).toNumber(), 0);
|
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0);
|
||||||
assert.equal(web3.fromWei(st.notes[ 4 ].amount).toNumber(), 0.12);
|
assert.equal(web3.fromWei(st.notes[4].amount).toNumber(), 0.12);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("A subproject 2a and a delegate2 is created", async () => {
|
it('A subproject 2a and a delegate2 is created', async () => {
|
||||||
await liquidPledging.addProject("Project2a", reviewer, 86400, {from: adminProject2a});
|
await liquidPledging.addProject('Project2a', reviewer, 86400, { from: adminProject2a });
|
||||||
await liquidPledging.addDelegate("Delegate2", {from: delegate2});
|
await liquidPledging.addDelegate('Delegate2', { from: delegate2 });
|
||||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||||
assert.equal(nManagers, 6);
|
assert.equal(nManagers, 6);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("Project 2 delegate in delegate2", async () => {
|
it('Project 2 delegate in delegate2', async () => {
|
||||||
await liquidPledging.transfer(4, 4, web3.toWei(0.02), 6, {from: adminProject2});
|
await liquidPledging.transfer(4, 4, web3.toWei(0.02), 6, { from: adminProject2 });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 10);
|
assert.equal(st.notes.length, 10);
|
||||||
assert.equal(web3.fromWei(st.notes[ 9 ].amount).toNumber(), 0.02);
|
assert.equal(web3.fromWei(st.notes[9].amount).toNumber(), 0.02);
|
||||||
assert.equal(web3.fromWei(st.notes[ 4 ].amount).toNumber(), 0.1);
|
assert.equal(web3.fromWei(st.notes[4].amount).toNumber(), 0.1);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("delegate2 assigns to projec2a", async () => {
|
it('delegate2 assigns to projec2a', async () => {
|
||||||
await liquidPledging.transfer(6, 9, web3.toWei(0.01), 5, {from: delegate2});
|
await liquidPledging.transfer(6, 9, web3.toWei(0.01), 5, { from: delegate2 });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 11);
|
assert.equal(st.notes.length, 11);
|
||||||
assert.equal(web3.fromWei(st.notes[ 9 ].amount).toNumber(), 0.01);
|
assert.equal(web3.fromWei(st.notes[9].amount).toNumber(), 0.01);
|
||||||
assert.equal(web3.fromWei(st.notes[ 10 ].amount).toNumber(), 0.01);
|
assert.equal(web3.fromWei(st.notes[10].amount).toNumber(), 0.01);
|
||||||
}).timeout(4000);
|
}).timeout(4000);
|
||||||
it("project2a authorize to spend a little", async () => {
|
it('project2a authorize to spend a litle', async () => {
|
||||||
const n = Math.floor(new Date().getTime() / 1000);
|
const n = Math.floor(new Date().getTime() / 1000);
|
||||||
await liquidPledging.setMockedTime(n + 86401*3);
|
await liquidPledging.setMockedTime(n + (86401 * 3));
|
||||||
await liquidPledging.withdraw(10, web3.toWei(0.005), {from: adminProject2a});
|
await liquidPledging.withdraw(10, web3.toWei(0.005), { from: adminProject2a });
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 13);
|
assert.equal(st.notes.length, 13);
|
||||||
assert.equal(web3.fromWei(st.notes[ 10 ].amount).toNumber(), 0);
|
assert.equal(web3.fromWei(st.notes[10].amount).toNumber(), 0);
|
||||||
assert.equal(web3.fromWei(st.notes[ 11 ].amount).toNumber(), 0.005);
|
assert.equal(web3.fromWei(st.notes[11].amount).toNumber(), 0.005);
|
||||||
assert.equal(web3.fromWei(st.notes[ 12 ].amount).toNumber(), 0.005);
|
assert.equal(web3.fromWei(st.notes[12].amount).toNumber(), 0.005);
|
||||||
}).timeout(4000);
|
}).timeout(4000);
|
||||||
it("project2 is canceled", async () => {
|
it('project2 is canceled', async () => {
|
||||||
await liquidPledging.cancelProject(4, {from: reviewer});
|
await liquidPledging.cancelProject(4, { from: reviewer });
|
||||||
});
|
}).timeout(6000);
|
||||||
it("project2 should not be able to confirm payment", async () => {
|
it('project2 should not be able to confirm payment', async () => {
|
||||||
await assertFail(async function() {
|
await assertFail(async () => {
|
||||||
await vault.confirmPayment(1);
|
await vault.confirmPayment(1);
|
||||||
});
|
});
|
||||||
|
}).timeout(6000);
|
||||||
|
it('Should not be able to withdraw it', async () => {
|
||||||
|
await assertFail(async () => {
|
||||||
|
await liquidPledging.withdraw(12, web3.toWei(0.005), { from: donor1 });
|
||||||
});
|
});
|
||||||
it("Should not be able to withdraw it", async() => {
|
}).timeout(6000);
|
||||||
await assertFail(async function() {
|
it('Should not be able to cancel payment', async () => {
|
||||||
await liquidPledging.withdraw(12, web3.toWei(0.005), {from: donor1});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("Should not be able to cancel payment", async() => {
|
|
||||||
await vault.cancelPayment(1);
|
await vault.cancelPayment(1);
|
||||||
const st = await getState(liquidPledging);
|
const st = await getState(liquidPledging);
|
||||||
assert.equal(st.notes.length, 13);
|
assert.equal(st.notes.length, 13);
|
||||||
assert.equal(web3.fromWei(st.notes[ 2 ].amount).toNumber(), 0.31);
|
assert.equal(web3.fromWei(st.notes[2].amount).toNumber(), 0.31);
|
||||||
assert.equal(web3.fromWei(st.notes[ 11 ].amount).toNumber(), 0);
|
assert.equal(web3.fromWei(st.notes[11].amount).toNumber(), 0);
|
||||||
assert.equal(web3.fromWei(st.notes[ 12 ].amount).toNumber(), 0);
|
assert.equal(web3.fromWei(st.notes[12].amount).toNumber(), 0);
|
||||||
});
|
}).timeout(6000);
|
||||||
it("original owner should recover the remaining funds", async () => {
|
it('original owner should recover the remaining funds', async () => {
|
||||||
const st = await getState(liquidPledging);
|
await liquidPledging.withdraw(1, web3.toWei(0.5), { from: donor1 });
|
||||||
await liquidPledging.withdraw(1, web3.toWei(0.5), {from: donor1});
|
await liquidPledging.withdraw(2, web3.toWei(0.31), { from: donor1 });
|
||||||
await liquidPledging.withdraw(2, web3.toWei(0.31), {from: donor1});
|
await liquidPledging.withdraw(4, web3.toWei(0.1), { from: donor1 });
|
||||||
await liquidPledging.withdraw(4, web3.toWei(0.1), {from: donor1});
|
|
||||||
|
|
||||||
await liquidPledging.withdraw(8, web3.toWei(0.03), {$extraGas: 100000}, {from: donor1});
|
await liquidPledging.withdraw(8, web3.toWei(0.03), { $extraGas: 100000 }, { from: donor1 });
|
||||||
await liquidPledging.withdraw(9, web3.toWei(0.01), {from: donor1});
|
await liquidPledging.withdraw(9, web3.toWei(0.01), { from: donor1 });
|
||||||
|
|
||||||
const initialBalance = await getBalance(web3, donor1);
|
const initialBalance = await getBalance(web3, donor1);
|
||||||
await vault.multiConfirm([2,3,4,5,6]);
|
await vault.multiConfirm([2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
const finalBalance = await getBalance(web3, donor1);
|
const finalBalance = await getBalance(web3, donor1);
|
||||||
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
|
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
|
||||||
|
|
||||||
assert.equal(collected, 0.95);
|
assert.equal(collected, 0.95);
|
||||||
}).timeout(8000);
|
}).timeout(8000);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue