2017-08-13 12:12:45 +00:00
|
|
|
/* eslint-env mocha */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
2017-07-13 17:12:45 +00:00
|
|
|
const ethConnector = require('ethconnector');
|
|
|
|
const chai = require('chai');
|
2017-08-13 12:12:45 +00:00
|
|
|
const getBalance = require('runethtx').getBalance;
|
2017-08-26 19:31:26 +00:00
|
|
|
const liquidpledging = require('../index.js');
|
2017-08-13 12:12:45 +00:00
|
|
|
const assertFail = require('./helpers/assertFail');
|
|
|
|
|
2017-08-26 19:31:26 +00:00
|
|
|
const LiquidPledging = liquidpledging.LiquidPledging(true);
|
|
|
|
const Vault = liquidpledging.Vault;
|
2017-08-13 12:12:45 +00:00
|
|
|
const assert = chai.assert;
|
2017-06-27 11:08:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
const printState = async(liquidPledging) => {
|
2017-08-18 16:47:22 +00:00
|
|
|
console.log(liquidPledging.b);
|
|
|
|
const st = await liquidPledging.getState();
|
2017-08-13 12:12:45 +00:00
|
|
|
console.log(JSON.stringify(st, null, 2));
|
2017-06-27 11:08:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const printBalances = async(liquidPledging) => {
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState();
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 13);
|
|
|
|
for (let i = 1; i <= 12; i += 1) {
|
|
|
|
console.log(i, ethConnector.web3.fromWei(st.notes[i].amount).toNumber());
|
|
|
|
}
|
2017-06-27 11:08:23 +00:00
|
|
|
};
|
2017-08-18 16:47:22 +00:00
|
|
|
|
|
|
|
const readTest = async(liquidPledging) => {
|
2017-09-14 06:03:36 +00:00
|
|
|
const t1 = await liquidPledging.test1();
|
|
|
|
const t2 = await liquidPledging.test2();
|
|
|
|
const t3 = await liquidPledging.test3();
|
|
|
|
const t4 = await liquidPledging.test4();
|
|
|
|
console.log('t1: ', t1.toNumber());
|
|
|
|
console.log('t2: ', t2.toNumber());
|
|
|
|
console.log('t3: ', t3.toNumber());
|
|
|
|
console.log('t4: ', t4.toNumber());
|
|
|
|
};
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
describe('LiquidPledging test', () => {
|
|
|
|
let web3;
|
|
|
|
let accounts;
|
|
|
|
let liquidPledging;
|
|
|
|
let vault;
|
2017-10-03 10:20:23 +00:00
|
|
|
let giver1;
|
|
|
|
let giver2;
|
2017-08-13 12:12:45 +00:00
|
|
|
let delegate1;
|
2017-10-03 11:37:45 +00:00
|
|
|
let adminCampaign1;
|
|
|
|
let adminCampaign2;
|
|
|
|
let adminCampaign2a;
|
2017-08-13 12:12:45 +00:00
|
|
|
let delegate2;
|
|
|
|
before((done) => {
|
2017-09-18 13:43:09 +00:00
|
|
|
ethConnector.init('testrpc', { gasLimit: 5200000 }, () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
web3 = ethConnector.web3;
|
|
|
|
accounts = ethConnector.accounts;
|
2017-10-03 10:20:23 +00:00
|
|
|
giver1 = accounts[1];
|
2017-08-13 12:12:45 +00:00
|
|
|
delegate1 = accounts[2];
|
2017-10-03 11:37:45 +00:00
|
|
|
adminCampaign1 = accounts[3];
|
|
|
|
adminCampaign2 = accounts[4];
|
|
|
|
adminCampaign2a = accounts[5];
|
2017-08-13 12:12:45 +00:00
|
|
|
delegate2 = accounts[6];
|
2017-10-03 10:20:23 +00:00
|
|
|
giver2 = accounts[7];
|
2017-08-13 12:12:45 +00:00
|
|
|
done();
|
2017-06-26 17:54:28 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
});
|
2017-09-28 15:49:10 +00:00
|
|
|
it('Should deploy LiquidPledging contract', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
vault = await Vault.new(web3);
|
2017-09-18 13:43:09 +00:00
|
|
|
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5200000 });
|
2017-08-13 12:12:45 +00:00
|
|
|
await vault.setLiquidPledging(liquidPledging.$address);
|
|
|
|
}).timeout(6000);
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Should create a giver', async () => {
|
|
|
|
await liquidPledging.addGiver('Giver1', 86400, 0, { from: giver1 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
|
|
|
assert.equal(nManagers, 1);
|
|
|
|
const res = await liquidPledging.getNoteManager(1);
|
2017-10-03 10:20:23 +00:00
|
|
|
assert.equal(res[0], 0); // Giver
|
|
|
|
assert.equal(res[1], giver1);
|
|
|
|
assert.equal(res[2], 'Giver1');
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res[3], 86400);
|
|
|
|
}).timeout(6000);
|
|
|
|
it('Should make a donation', async () => {
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.donate(1, 1, { from: giver1, value: web3.toWei(1) });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 1);
|
|
|
|
await liquidPledging.getNote(1);
|
|
|
|
}).timeout(6000);
|
|
|
|
it('Should create a delegate', async () => {
|
2017-09-13 12:41:08 +00:00
|
|
|
await liquidPledging.addDelegate('Delegate1', 0, 0, { from: delegate1 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
|
|
|
assert.equal(nManagers, 2);
|
|
|
|
const res = await liquidPledging.getNoteManager(2);
|
2017-10-03 10:20:23 +00:00
|
|
|
assert.equal(res[0], 1); // Giver
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res[1], delegate1);
|
|
|
|
assert.equal(res[2], 'Delegate1');
|
|
|
|
}).timeout(6000);
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Giver should delegate on the delegate', async () => {
|
|
|
|
await liquidPledging.transfer(1, 1, web3.toWei(0.5), 2, { from: giver1 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 2);
|
|
|
|
const res1 = await liquidPledging.getNote(1);
|
|
|
|
assert.equal(res1[0].toNumber(), web3.toWei(0.5));
|
|
|
|
const res2 = await liquidPledging.getNote(2);
|
|
|
|
assert.equal(res2[0].toNumber(), web3.toWei(0.5));
|
|
|
|
assert.equal(res2[1].toNumber(), 1); // One delegate
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
const d = await liquidPledging.getNoteDelegate(2, 1);
|
|
|
|
assert.equal(d[0], 2);
|
|
|
|
assert.equal(d[1], delegate1);
|
|
|
|
assert.equal(d[2], 'Delegate1');
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Should create a 2 campaigns', async () => {
|
|
|
|
await liquidPledging.addCampaign('Campaign1', adminCampaign1, 0, 86400, 0, { from: adminCampaign1 });
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
|
|
|
assert.equal(nManagers, 3);
|
|
|
|
const res = await liquidPledging.getNoteManager(3);
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res[0], 2); // Campaign type
|
|
|
|
assert.equal(res[1], adminCampaign1);
|
|
|
|
assert.equal(res[2], 'Campaign1');
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res[3], 86400);
|
2017-08-18 16:47:22 +00:00
|
|
|
assert.equal(res[4], 0);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res[5], false);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-10-03 11:37:45 +00:00
|
|
|
await liquidPledging.addCampaign('Campaign2', adminCampaign2, 0, 86400, 0, { from: adminCampaign2 });
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
const nManagers2 = await liquidPledging.numberOfNoteManagers();
|
|
|
|
assert.equal(nManagers2, 4);
|
|
|
|
const res4 = await liquidPledging.getNoteManager(4);
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res4[0], 2); // Campaign type
|
|
|
|
assert.equal(res4[1], adminCampaign2);
|
|
|
|
assert.equal(res4[2], 'Campaign2');
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res4[3], 86400);
|
2017-08-18 16:47:22 +00:00
|
|
|
assert.equal(res4[4], 0);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res4[5], false);
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Delegate should assign to campaign2', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
const n = Math.floor(new Date().getTime() / 1000);
|
|
|
|
await liquidPledging.transfer(2, 2, web3.toWei(0.2), 3, { from: delegate1 });
|
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 3);
|
|
|
|
const res3 = await liquidPledging.getNote(3);
|
|
|
|
assert.equal(res3[0].toNumber(), web3.toWei(0.2));
|
|
|
|
assert.equal(res3[1].toNumber(), 1); // Owner
|
|
|
|
assert.equal(res3[2].toNumber(), 1); // Delegates
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res3[3].toNumber(), 3); // Proposed Campaign
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.isAbove(res3[4].toNumber(), n + 86000);
|
|
|
|
assert.equal(res3[5].toNumber(), 0); // Old Node
|
|
|
|
assert.equal(res3[6].toNumber(), 0); // Not Paid
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Giver should change his mind and assign half of it to campaign2', async () => {
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.transfer(1, 3, web3.toWei(0.1), 4, { from: giver1 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 4);
|
|
|
|
const res3 = await liquidPledging.getNote(3);
|
|
|
|
assert.equal(res3[0].toNumber(), web3.toWei(0.1));
|
|
|
|
const res4 = await liquidPledging.getNote(4);
|
|
|
|
assert.equal(res4[1].toNumber(), 4); // Owner
|
|
|
|
assert.equal(res4[2].toNumber(), 0); // Delegates
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res4[3].toNumber(), 0); // Proposed Campaign
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res4[4], 0);
|
|
|
|
assert.equal(res4[5].toNumber(), 2); // Old Node
|
|
|
|
assert.equal(res4[6].toNumber(), 0); // Not Paid
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('After the time, the campaign1 should be able to spend part of it', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
const n = Math.floor(new Date().getTime() / 1000);
|
|
|
|
await liquidPledging.setMockedTime(n + 86401);
|
2017-10-03 11:37:45 +00:00
|
|
|
await liquidPledging.withdraw(3, web3.toWei(0.05), { from: adminCampaign1 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 6);
|
|
|
|
const res5 = await liquidPledging.getNote(5);
|
|
|
|
assert.equal(res5[0].toNumber(), web3.toWei(0.05));
|
|
|
|
assert.equal(res5[1].toNumber(), 3); // Owner
|
|
|
|
assert.equal(res5[2].toNumber(), 0); // Delegates
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res5[3].toNumber(), 0); // Proposed Campaign
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res5[4], 0); // commit time
|
|
|
|
assert.equal(res5[5].toNumber(), 2); // Old Node
|
|
|
|
assert.equal(res5[6].toNumber(), 0); // Not Paid
|
|
|
|
const res6 = await liquidPledging.getNote(6);
|
|
|
|
assert.equal(res6[0].toNumber(), web3.toWei(0.05));
|
|
|
|
assert.equal(res6[1].toNumber(), 3); // Owner
|
|
|
|
assert.equal(res6[2].toNumber(), 0); // Delegates
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res6[3].toNumber(), 0); // Proposed Campaign
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res6[4], 0); // commit time
|
|
|
|
assert.equal(res6[5].toNumber(), 2); // Old Node
|
|
|
|
assert.equal(res6[6].toNumber(), 1); // Peinding paid Paid
|
|
|
|
}).timeout(6000);
|
|
|
|
it('Should collect the Ether', async () => {
|
2017-10-03 11:37:45 +00:00
|
|
|
const initialBalance = await getBalance(web3, adminCampaign1);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
await vault.confirmPayment(0);
|
2017-10-03 11:37:45 +00:00
|
|
|
const finalBalance = await getBalance(web3, adminCampaign1);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(collected, 0.05);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
|
|
|
assert.equal(nNotes.toNumber(), 7);
|
|
|
|
const res7 = await liquidPledging.getNote(7);
|
|
|
|
assert.equal(res7[0].toNumber(), web3.toWei(0.05));
|
|
|
|
assert.equal(res7[1].toNumber(), 3); // Owner
|
|
|
|
assert.equal(res7[2].toNumber(), 0); // Delegates
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(res7[3].toNumber(), 0); // Proposed Campaign
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(res7[4], 0); // commit time
|
|
|
|
assert.equal(res7[5].toNumber(), 2); // Old Node
|
|
|
|
assert.equal(res7[6].toNumber(), 2); // Peinding paid Paid
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Admin of the campaign1 should be able to cancel campaign1', async () => {
|
|
|
|
await liquidPledging.cancelCampaign(3, { from: adminCampaign1 });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.managers[3].canceled, true);
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Should not allow to withdraw from a canceled campaign', async () => {
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0.05);
|
|
|
|
await assertFail(async () => {
|
2017-10-03 11:37:45 +00:00
|
|
|
await liquidPledging.withdraw(5, web3.toWei(0.01), { from: adminCampaign1 });
|
2017-06-27 11:08:23 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Delegate should send part of this ETH to campaign2', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
await liquidPledging.transfer(2, 5, web3.toWei(0.03), 4,
|
|
|
|
{ $extraGas: 100000 },
|
|
|
|
{ from: delegate1 });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 9);
|
|
|
|
assert.equal(web3.fromWei(st.notes[8].amount).toNumber(), 0.03);
|
|
|
|
assert.equal(st.notes[8].owner, 1);
|
|
|
|
assert.equal(st.notes[8].delegates.length, 1);
|
|
|
|
assert.equal(st.notes[8].delegates[0].id, 2);
|
2017-10-03 11:37:45 +00:00
|
|
|
assert.equal(st.notes[8].proposedCampaign, 4);
|
2017-08-13 12:12:45 +00:00
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Giver should be able to send the remaining to campaign2', async () => {
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.transfer(1, 5, web3.toWei(0.02), 4, { from: giver1 });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 9);
|
|
|
|
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0);
|
|
|
|
assert.equal(web3.fromWei(st.notes[4].amount).toNumber(), 0.12);
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('A subcampaign 2a and a delegate2 is created', async () => {
|
|
|
|
await liquidPledging.addCampaign('Campaign2a', adminCampaign2a, 4, 86400, 0, { from: adminCampaign2 });
|
2017-09-13 12:41:08 +00:00
|
|
|
await liquidPledging.addDelegate('Delegate2', 0, 0, { from: delegate2 });
|
2017-08-13 12:12:45 +00:00
|
|
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
|
|
|
assert.equal(nManagers, 6);
|
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('Campaign 2 delegate in delegate2', async () => {
|
|
|
|
await liquidPledging.transfer(4, 4, web3.toWei(0.02), 6, { from: adminCampaign2 });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 10);
|
|
|
|
assert.equal(web3.fromWei(st.notes[9].amount).toNumber(), 0.02);
|
|
|
|
assert.equal(web3.fromWei(st.notes[4].amount).toNumber(), 0.1);
|
|
|
|
}).timeout(6000);
|
|
|
|
it('delegate2 assigns to projec2a', async () => {
|
|
|
|
await liquidPledging.transfer(6, 9, web3.toWei(0.01), 5, { from: delegate2 });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 11);
|
|
|
|
assert.equal(web3.fromWei(st.notes[9].amount).toNumber(), 0.01);
|
|
|
|
assert.equal(web3.fromWei(st.notes[10].amount).toNumber(), 0.01);
|
|
|
|
}).timeout(4000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('campaign2a authorize to spend a litle', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
const n = Math.floor(new Date().getTime() / 1000);
|
|
|
|
await liquidPledging.setMockedTime(n + (86401 * 3));
|
2017-10-03 11:37:45 +00:00
|
|
|
await liquidPledging.withdraw(10, web3.toWei(0.005), { from: adminCampaign2a });
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 13);
|
|
|
|
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[12].amount).toNumber(), 0.005);
|
|
|
|
}).timeout(4000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('campaign2 is canceled', async () => {
|
|
|
|
await liquidPledging.cancelCampaign(4, { from: adminCampaign2 });
|
2017-08-13 12:12:45 +00:00
|
|
|
}).timeout(6000);
|
2017-10-03 11:37:45 +00:00
|
|
|
it('campaign2 should not be able to confirm payment', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
await assertFail(async () => {
|
|
|
|
await vault.confirmPayment(1);
|
2017-06-27 11:08:23 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
}).timeout(6000);
|
|
|
|
it('Should not be able to withdraw it', async () => {
|
|
|
|
await assertFail(async () => {
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.withdraw(12, web3.toWei(0.005), { from: giver1 });
|
2017-06-26 17:54:28 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
}).timeout(6000);
|
|
|
|
it('Should not be able to cancel payment', async () => {
|
|
|
|
await vault.cancelPayment(1);
|
2017-08-18 16:47:22 +00:00
|
|
|
const st = await liquidPledging.getState(liquidPledging);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(st.notes.length, 13);
|
|
|
|
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[12].amount).toNumber(), 0);
|
|
|
|
}).timeout(6000);
|
|
|
|
it('original owner should recover the remaining funds', async () => {
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.withdraw(1, web3.toWei(0.5), { from: giver1 });
|
|
|
|
await liquidPledging.withdraw(2, web3.toWei(0.31), { from: giver1 });
|
|
|
|
await liquidPledging.withdraw(4, web3.toWei(0.1), { from: giver1 });
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.withdraw(8, web3.toWei(0.03), { $extraGas: 100000 }, { from: giver1 });
|
|
|
|
await liquidPledging.withdraw(9, web3.toWei(0.01), { from: giver1 });
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2017-10-03 10:20:23 +00:00
|
|
|
const initialBalance = await getBalance(web3, giver1);
|
2017-08-13 12:12:45 +00:00
|
|
|
await vault.multiConfirm([2, 3, 4, 5, 6]);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-10-03 10:20:23 +00:00
|
|
|
const finalBalance = await getBalance(web3, giver1);
|
2017-08-13 12:12:45 +00:00
|
|
|
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(collected, 0.95);
|
|
|
|
}).timeout(8000);
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Should make a donation and create giver', async () => {
|
2017-10-03 10:08:47 +00:00
|
|
|
const oldNNotes = await liquidPledging.numberOfNotes();
|
|
|
|
const oldNManagers = await liquidPledging.numberOfNoteManagers();
|
2017-10-03 10:20:23 +00:00
|
|
|
await liquidPledging.donate(0, 1, { from: giver2, value: web3.toWei(1) });
|
2017-09-28 15:49:10 +00:00
|
|
|
const nNotes = await liquidPledging.numberOfNotes();
|
2017-10-03 10:08:47 +00:00
|
|
|
assert.equal(nNotes.toNumber(), oldNNotes.toNumber() + 1);
|
2017-09-28 15:49:10 +00:00
|
|
|
const nManagers = await liquidPledging.numberOfNoteManagers();
|
2017-10-03 10:08:47 +00:00
|
|
|
assert.equal(nManagers.toNumber(), oldNManagers.toNumber() + 1);
|
|
|
|
const res = await liquidPledging.getNoteManager(nManagers);
|
2017-10-03 10:20:23 +00:00
|
|
|
assert.equal(res[0], 0); // Giver
|
|
|
|
assert.equal(res[1], giver2);
|
2017-09-28 15:49:10 +00:00
|
|
|
assert.equal(res[2], '');
|
|
|
|
assert.equal(res[3], 259200); // default to 3 day commitTime
|
|
|
|
}).timeout(6000);
|
2017-06-26 17:54:28 +00:00
|
|
|
});
|