2017-08-13 12:12:45 +00:00
|
|
|
/* eslint-env mocha */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
2018-11-15 20:22:12 +00:00
|
|
|
const generateClass = require('eth-contract-class').default;
|
2018-06-16 00:27:47 +00:00
|
|
|
const Ganache = require('ganache-cli');
|
2017-10-03 13:06:58 +00:00
|
|
|
const Web3 = require('web3');
|
2018-04-24 20:39:58 +00:00
|
|
|
const { assert } = require('chai');
|
|
|
|
const { LPVault, LPFactory, LiquidPledgingState, Kernel, ACL, test } = require('../index');
|
2017-08-13 12:12:45 +00:00
|
|
|
|
2018-06-16 19:04:36 +00:00
|
|
|
const { StandardTokenTest, assertFail, LiquidPledgingMock, RecoveryVault } = test;
|
2017-10-03 13:06:58 +00:00
|
|
|
const { utils } = Web3;
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
const printState = async liquidPledgingState => {
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState();
|
2017-08-13 12:12:45 +00:00
|
|
|
console.log(JSON.stringify(st, null, 2));
|
2017-06-27 11:08:23 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
|
|
|
|
// const _RecoveryVault = embark.require('Embark/contracts/RecoveryVault');
|
|
|
|
// const RecoveryVault = ge
|
|
|
|
// const _LPVault = embark.require('Embark/contracts/LPVault');
|
|
|
|
// const _LiquidPledgingMock = embark.require('Embark/contracts/LiquidPledgingMock');
|
|
|
|
|
|
|
|
let accounts;
|
|
|
|
|
|
|
|
config({
|
|
|
|
// contracts: {
|
|
|
|
// RecoveryVault: {},
|
|
|
|
// LPVault: {},
|
|
|
|
// LiquidPledgingMock: {}
|
|
|
|
|
|
|
|
// "SimpleStorage": {
|
|
|
|
// args: [100],
|
|
|
|
// onDeploy: ["SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()"] // example
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}, (err, theAccounts) => {
|
|
|
|
accounts = theAccounts;
|
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
describe('LiquidPledging test', function() {
|
2017-10-23 21:25:06 +00:00
|
|
|
this.timeout(0);
|
2018-06-16 00:27:47 +00:00
|
|
|
let ganache;
|
2018-11-15 20:22:12 +00:00
|
|
|
// let web3;
|
|
|
|
// let accounts;
|
2017-08-13 12:12:45 +00:00
|
|
|
let liquidPledging;
|
2017-10-14 10:46:04 +00:00
|
|
|
let liquidPledgingState;
|
2017-08-13 12:12:45 +00:00
|
|
|
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-04 23:27:23 +00:00
|
|
|
let adminProject1;
|
|
|
|
let adminProject2;
|
|
|
|
let adminProject2a;
|
2017-10-05 19:51:23 +00:00
|
|
|
let adminProject3;
|
2017-08-13 12:12:45 +00:00
|
|
|
let delegate2;
|
2018-06-16 17:54:30 +00:00
|
|
|
let recoveryVault;
|
2018-02-12 22:55:11 +00:00
|
|
|
let escapeHatchCaller;
|
|
|
|
let acl;
|
2018-02-16 21:44:44 +00:00
|
|
|
let giver1Token;
|
|
|
|
let giver2Token;
|
2018-02-12 22:55:11 +00:00
|
|
|
|
2017-10-03 13:06:58 +00:00
|
|
|
before(async () => {
|
2018-11-15 20:22:12 +00:00
|
|
|
// ganache = Ganache.server({
|
|
|
|
// gasLimit: 6700000,
|
|
|
|
// total_accounts: 11,
|
|
|
|
// });
|
2017-10-04 08:24:35 +00:00
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
// ganache.listen(8545, '127.0.0.1');
|
2017-10-03 13:06:58 +00:00
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
// web3 = new Web3('http://localhost:8545');
|
|
|
|
// accounts = await web3.eth.getAccounts();
|
2017-10-03 13:15:05 +00:00
|
|
|
giver1 = accounts[1];
|
2017-10-03 13:06:58 +00:00
|
|
|
delegate1 = accounts[2];
|
2017-10-04 23:27:23 +00:00
|
|
|
adminProject1 = accounts[3];
|
|
|
|
adminProject2 = accounts[4];
|
|
|
|
adminProject2a = accounts[5];
|
2017-10-03 13:06:58 +00:00
|
|
|
delegate2 = accounts[6];
|
2017-10-03 13:15:05 +00:00
|
|
|
giver2 = accounts[7];
|
2017-10-05 19:51:23 +00:00
|
|
|
adminProject3 = accounts[8];
|
2018-06-16 17:54:30 +00:00
|
|
|
recoveryVault = (await RecoveryVault.new(web3)).$address;
|
2018-02-12 22:55:11 +00:00
|
|
|
escapeHatchCaller = accounts[10];
|
2017-10-06 10:07:25 +00:00
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
// baseLP = new LPVault(web3, _LPVault)
|
2017-10-06 10:07:25 +00:00
|
|
|
});
|
2017-10-23 21:25:06 +00:00
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
// after(done => {
|
|
|
|
// ganache.close();
|
|
|
|
// done();
|
|
|
|
// });
|
|
|
|
|
2017-09-28 15:49:10 +00:00
|
|
|
it('Should deploy LiquidPledging contract', async () => {
|
2018-06-16 00:27:47 +00:00
|
|
|
const baseVault = await LPVault.new(web3);
|
|
|
|
const baseLP = await LiquidPledgingMock.new(web3, {
|
2018-04-24 20:39:58 +00:00
|
|
|
gas: 6700000,
|
|
|
|
});
|
2018-06-16 00:27:47 +00:00
|
|
|
lpFactory = await LPFactory.new(web3, baseVault.$address, baseLP.$address, { gas: 6700000 });
|
2018-01-22 19:00:30 +00:00
|
|
|
|
2018-06-16 17:54:30 +00:00
|
|
|
const r = await lpFactory.newLP(accounts[0], recoveryVault);
|
2018-01-22 19:00:30 +00:00
|
|
|
|
2018-02-10 14:14:52 +00:00
|
|
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
2018-04-24 20:39:58 +00:00
|
|
|
vault = new LPVault(web3, vaultAddress);
|
2018-02-10 14:14:52 +00:00
|
|
|
|
|
|
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging = new LiquidPledgingMock(web3, lpAddress);
|
2018-01-25 16:31:13 +00:00
|
|
|
|
2018-06-16 17:54:30 +00:00
|
|
|
assert.isAbove(Number(await vault.getInitializationBlock()), 0);
|
|
|
|
assert.isAbove(Number(await liquidPledging.getInitializationBlock()), 0);
|
|
|
|
|
2017-10-14 10:46:04 +00:00
|
|
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
2018-02-12 22:55:11 +00:00
|
|
|
|
|
|
|
// set permissions
|
2018-04-24 20:39:58 +00:00
|
|
|
const kernel = new Kernel(web3, await liquidPledging.kernel());
|
|
|
|
acl = new ACL(web3, await kernel.acl());
|
|
|
|
await acl.createPermission(
|
|
|
|
accounts[0],
|
|
|
|
vault.$address,
|
|
|
|
await vault.CANCEL_PAYMENT_ROLE(),
|
|
|
|
accounts[0],
|
|
|
|
{ $extraGas: 200000 },
|
|
|
|
);
|
|
|
|
await acl.createPermission(
|
|
|
|
accounts[0],
|
|
|
|
vault.$address,
|
|
|
|
await vault.CONFIRM_PAYMENT_ROLE(),
|
|
|
|
accounts[0],
|
|
|
|
{ $extraGas: 200000 },
|
|
|
|
);
|
|
|
|
await acl.grantPermission(
|
|
|
|
escapeHatchCaller,
|
|
|
|
vault.$address,
|
|
|
|
await vault.ESCAPE_HATCH_CALLER_ROLE(),
|
|
|
|
{ $extraGas: 200000 },
|
|
|
|
);
|
|
|
|
await acl.revokePermission(
|
|
|
|
accounts[0],
|
|
|
|
vault.$address,
|
|
|
|
await vault.ESCAPE_HATCH_CALLER_ROLE(),
|
|
|
|
{ $extraGas: 200000 },
|
|
|
|
);
|
2018-02-16 21:44:44 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
giver1Token = await StandardTokenTest.new(web3);
|
|
|
|
giver2Token = await StandardTokenTest.new(web3);
|
2018-02-16 21:44:44 +00:00
|
|
|
|
|
|
|
await giver1Token.mint(giver1, web3.utils.toWei('1000'));
|
|
|
|
await giver2Token.mint(giver2, web3.utils.toWei('1000'));
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
await giver1Token.approve(liquidPledging.$address, '0xFFFFFFFFFFFFFFFF', { from: giver1 });
|
|
|
|
await giver2Token.approve(liquidPledging.$address, '0xFFFFFFFFFFFFFFFF', { from: giver2 });
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Should create a giver', async () => {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.addGiver('Giver1', 'URLGiver1', 86400, 0, { from: giver1, gas: 1000000 });
|
2018-02-20 16:12:01 +00:00
|
|
|
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 1);
|
|
|
|
const res = await liquidPledging.getPledgeAdmin(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-10-04 09:40:26 +00:00
|
|
|
assert.equal(res[3], 'URLGiver1');
|
|
|
|
assert.equal(res[4], 86400);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
it('Should make a donation', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
const r = await liquidPledging.donate(1, 1, giver1Token.$address, utils.toWei('1'), {
|
|
|
|
from: giver1,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 1);
|
2018-02-12 22:55:11 +00:00
|
|
|
const p = await liquidPledging.getPledge(1);
|
|
|
|
assert.equal(p.amount, utils.toWei('1'));
|
|
|
|
assert.equal(p.owner, 1);
|
2018-02-16 21:44:44 +00:00
|
|
|
const vaultBal = await giver1Token.balanceOf(vault.$address);
|
|
|
|
const giver1Bal = await giver1Token.balanceOf(giver1);
|
2018-04-24 20:39:58 +00:00
|
|
|
assert.equal(vaultBal, web3.utils.toWei('1'));
|
|
|
|
assert.equal(giver1Bal, web3.utils.toWei('999'));
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
it('Should create a delegate', async () => {
|
2017-10-04 09:40:26 +00:00
|
|
|
await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 });
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 2);
|
|
|
|
const res = await liquidPledging.getPledgeAdmin(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');
|
2017-10-04 09:40:26 +00:00
|
|
|
assert.equal(res[3], 'URLDelegate1');
|
|
|
|
assert.equal(res[4], 0);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Giver should delegate on the delegate', async () => {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.transfer(1, 1, utils.toWei('0.5'), 2, { from: giver1, $extraGas: 100000 });
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 2);
|
2017-10-03 12:42:21 +00:00
|
|
|
const res1 = await liquidPledging.getPledge(1);
|
2017-11-16 23:30:29 +00:00
|
|
|
assert.equal(res1[0], utils.toWei('0.5'));
|
2017-10-03 12:42:21 +00:00
|
|
|
const res2 = await liquidPledging.getPledge(2);
|
2017-11-16 23:30:29 +00:00
|
|
|
assert.equal(res2[0], utils.toWei('0.5'));
|
2017-10-03 13:06:58 +00:00
|
|
|
assert.equal(res2[1], 1); // One delegate
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2018-02-12 22:55:11 +00:00
|
|
|
const d = await liquidPledging.getPledgeDelegate(2, 1);
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(d[0], 2);
|
|
|
|
assert.equal(d[1], delegate1);
|
|
|
|
assert.equal(d[2], 'Delegate1');
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Should create a 2 projects', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('Project1', 'URLProject1', adminProject1, 0, 86400, 0, {
|
|
|
|
from: adminProject1,
|
|
|
|
});
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 3);
|
|
|
|
const res = await liquidPledging.getPledgeAdmin(3);
|
2017-10-04 23:27:23 +00:00
|
|
|
assert.equal(res[0], 2); // Project type
|
|
|
|
assert.equal(res[1], adminProject1);
|
|
|
|
assert.equal(res[2], 'Project1');
|
|
|
|
assert.equal(res[3], 'URLProject1');
|
2017-10-04 09:40:26 +00:00
|
|
|
assert.equal(res[4], 86400);
|
|
|
|
assert.equal(res[5], 0);
|
|
|
|
assert.equal(res[6], false);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('Project2', 'URLProject2', adminProject2, 0, 86400, 0, {
|
|
|
|
from: adminProject2,
|
|
|
|
});
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins2 = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins2, 4);
|
|
|
|
const res4 = await liquidPledging.getPledgeAdmin(4);
|
2017-10-04 23:27:23 +00:00
|
|
|
assert.equal(res4[0], 2); // Project type
|
|
|
|
assert.equal(res4[1], adminProject2);
|
|
|
|
assert.equal(res4[2], 'Project2');
|
|
|
|
assert.equal(res4[3], 'URLProject2');
|
2017-10-04 09:40:26 +00:00
|
|
|
assert.equal(res4[4], 86400);
|
|
|
|
assert.equal(res4[5], 0);
|
|
|
|
assert.equal(res4[6], false);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Delegate should assign to project1', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
const n = Math.floor(new Date().getTime() / 1000);
|
2017-11-16 23:30:29 +00:00
|
|
|
await liquidPledging.transfer(2, 2, utils.toWei('0.2'), 3, { from: delegate1 });
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 3);
|
2017-10-03 12:42:21 +00:00
|
|
|
const res3 = await liquidPledging.getPledge(3);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res3.amount, utils.toWei('0.2'));
|
|
|
|
assert.equal(res3.owner, 1);
|
|
|
|
assert.equal(res3.nDelegates, 1);
|
|
|
|
assert.equal(res3.intendedProject, 3);
|
|
|
|
assert.isAbove(utils.toDecimal(res3.commitTime), n + 86000);
|
|
|
|
assert.equal(res3.oldPledge, 0);
|
|
|
|
assert.equal(res3.token, giver1Token.$address);
|
|
|
|
assert.equal(res3.pledgeState, 0); // Not Paid
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Giver should change his mind and assign half of it to project2', async () => {
|
2017-11-16 23:30:29 +00:00
|
|
|
await liquidPledging.transfer(1, 3, utils.toWei('0.1'), 4, { from: giver1 });
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 4);
|
2017-10-03 12:42:21 +00:00
|
|
|
const res3 = await liquidPledging.getPledge(3);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res3.amount, utils.toWei('0.1'));
|
2017-10-03 12:42:21 +00:00
|
|
|
const res4 = await liquidPledging.getPledge(4);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res4.owner, 4);
|
|
|
|
assert.equal(res4.nDelegates, 0);
|
|
|
|
assert.equal(res4.intendedProject, 0);
|
|
|
|
assert.equal(res4.commitTime, 0);
|
|
|
|
assert.equal(res4.oldPledge, 2);
|
|
|
|
assert.equal(res4.token, giver1Token.$address);
|
|
|
|
assert.equal(res4.pledgeState, 0); // Not Paid
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('After the time, the project1 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);
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.setMockedTime(n + 86401, { $extraGas: 100000 });
|
2017-11-16 23:30:29 +00:00
|
|
|
await liquidPledging.withdraw(3, utils.toWei('0.05'), { from: adminProject1 });
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 6);
|
2017-10-03 12:42:21 +00:00
|
|
|
const res5 = await liquidPledging.getPledge(5);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res5.amount, utils.toWei('0.05'));
|
|
|
|
assert.equal(res5.owner, 3);
|
|
|
|
assert.equal(res5.nDelegates, 0);
|
|
|
|
assert.equal(res5.intendedProject, 0);
|
|
|
|
assert.equal(res5.commitTime, 0);
|
|
|
|
assert.equal(res5.oldPledge, 2);
|
|
|
|
assert.equal(res5.token, giver1Token.$address);
|
|
|
|
assert.equal(res5.pledgeState, 0); // Not Paid
|
2017-10-03 12:42:21 +00:00
|
|
|
const res6 = await liquidPledging.getPledge(6);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res6.amount, utils.toWei('0.05'));
|
|
|
|
assert.equal(res6.owner, 3);
|
|
|
|
assert.equal(res6.nDelegates, 0);
|
|
|
|
assert.equal(res6.intendedProject, 0);
|
|
|
|
assert.equal(res6.commitTime, 0);
|
|
|
|
assert.equal(res6.oldPledge, 2);
|
|
|
|
assert.equal(res6.token, giver1Token.$address);
|
|
|
|
assert.equal(res6.pledgeState, 1); // Pending
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2018-02-16 21:44:44 +00:00
|
|
|
it('Should collect the token', async () => {
|
|
|
|
const initialBalance = await giver1Token.balanceOf(adminProject1);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
await vault.confirmPayment(0, { $extraGas: 200000 });
|
2018-02-16 21:44:44 +00:00
|
|
|
const finalBalance = await giver1Token.balanceOf(adminProject1);
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-10-03 13:06:58 +00:00
|
|
|
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
|
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-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(nPledges, 7);
|
2017-10-03 12:42:21 +00:00
|
|
|
const res7 = await liquidPledging.getPledge(7);
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(res7.amount, utils.toWei('0.05'));
|
|
|
|
assert.equal(res7.owner, 3);
|
|
|
|
assert.equal(res7.nDelegates, 0);
|
|
|
|
assert.equal(res7.intendedProject, 0);
|
|
|
|
assert.equal(res7.commitTime, 0);
|
|
|
|
assert.equal(res7.oldPledge, 2);
|
|
|
|
assert.equal(res7.token, giver1Token.$address);
|
2018-12-07 11:52:02 +00:00
|
|
|
assert.equal(res7.pledgeState, 2); // Paid
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Admin of the project1 should be able to cancel project1', async () => {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.cancelProject(3, { from: adminProject1, $extraGas: 100000 });
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState(liquidPledging);
|
2017-10-04 08:24:35 +00:00
|
|
|
assert.equal(st.admins[3].canceled, true);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Should not allow to withdraw from a canceled project', async () => {
|
2018-01-22 19:00:30 +00:00
|
|
|
const p = await liquidPledging.getPledge(5);
|
|
|
|
assert.equal(utils.fromWei(p.amount), 0.05);
|
|
|
|
|
2018-01-25 23:09:58 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.withdraw(5, utils.toWei('0.01'), { from: adminProject1, gas: 4000000 }),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2018-02-16 21:44:44 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Delegate should send part of this ETH to project2', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.transfer(2, 5, utils.toWei('0.03'), 4, {
|
|
|
|
from: delegate1,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState(liquidPledging);
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 9);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[8].amount), 0.03);
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges[8].owner, 1);
|
|
|
|
assert.equal(st.pledges[8].delegates.length, 1);
|
|
|
|
assert.equal(st.pledges[8].delegates[0].id, 2);
|
2017-10-04 23:27:23 +00:00
|
|
|
assert.equal(st.pledges[8].intendedProject, 4);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Giver should be able to send the remaining to project2', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.transfer(1, 5, utils.toWei('0.02'), 4, {
|
|
|
|
from: giver1,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState(liquidPledging);
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 9);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[5].amount), 0);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[4].amount), 0.12);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('A subproject 2a and a delegate2 is created', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('Project2a', 'URLProject2a', adminProject2a, 4, 86400, 0, {
|
|
|
|
from: adminProject2,
|
|
|
|
});
|
2017-10-04 09:40:26 +00:00
|
|
|
await liquidPledging.addDelegate('Delegate2', 'URLDelegate2', 0, 0, { from: delegate2 });
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 6);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('Project 2 delegate in delegate2', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.transfer(4, 4, utils.toWei('0.02'), 6, {
|
|
|
|
from: adminProject2,
|
|
|
|
$extraGas: 200000,
|
|
|
|
});
|
2018-02-12 22:55:11 +00:00
|
|
|
const st = await liquidPledgingState.getState();
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 10);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[9].amount), 0.02);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[4].amount), 0.1);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
it('delegate2 assigns to projec2a', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.transfer(6, 9, utils.toWei('0.01'), 5, {
|
|
|
|
from: delegate2,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState(liquidPledging);
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 11);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[9].amount), 0.01);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[10].amount), 0.01);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('project2a authorize to spend a litle', async () => {
|
2017-08-13 12:12:45 +00:00
|
|
|
const n = Math.floor(new Date().getTime() / 1000);
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.setMockedTime(n + 86401 * 3, { $extraGas: 200000 });
|
|
|
|
await liquidPledging.withdraw(10, utils.toWei('0.005'), {
|
|
|
|
from: adminProject2a,
|
|
|
|
$extraGas: 200000,
|
|
|
|
});
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState(liquidPledging);
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 13);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[10].amount), 0);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[11].amount), 0.005);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[12].amount), 0.005);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-04 23:27:23 +00:00
|
|
|
it('project2 is canceled', async () => {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.cancelProject(4, { from: adminProject2, $extraGas: 100000 });
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
it('Should not be able to withdraw it', async () => {
|
2018-01-25 23:09:58 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.withdraw(12, utils.toWei('0.005'), { from: giver1, gas: 4000000 }),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-03 13:06:58 +00:00
|
|
|
it('Should be able to cancel payment', async () => {
|
|
|
|
// bug somewhere which will throw invalid op_code if we don't provide gas or extraGas
|
|
|
|
await vault.cancelPayment(1, { $extraGas: 100000 });
|
2017-10-14 10:46:04 +00:00
|
|
|
const st = await liquidPledgingState.getState();
|
2017-10-03 12:42:21 +00:00
|
|
|
assert.equal(st.pledges.length, 13);
|
2017-10-03 13:15:05 +00:00
|
|
|
assert.equal(utils.fromWei(st.pledges[2].amount), 0.31);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[11].amount), 0);
|
|
|
|
assert.equal(utils.fromWei(st.pledges[12].amount), 0);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-08-13 12:12:45 +00:00
|
|
|
it('original owner should recover the remaining funds', async () => {
|
2017-10-24 15:34:06 +00:00
|
|
|
const pledges = [
|
2017-11-16 23:30:29 +00:00
|
|
|
{ amount: utils.toWei('0.5'), id: 1 },
|
|
|
|
{ amount: utils.toWei('0.31'), id: 2 },
|
|
|
|
{ amount: utils.toWei('0.1'), id: 4 },
|
|
|
|
{ amount: utils.toWei('0.03'), id: 8 },
|
|
|
|
{ amount: utils.toWei('0.01'), id: 9 },
|
2017-10-24 15:34:06 +00:00
|
|
|
];
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2017-10-24 15:34:06 +00:00
|
|
|
// .substring is to remove the 0x prefix on the toHex result
|
|
|
|
const encodedPledges = pledges.map(p => {
|
2018-04-24 20:39:58 +00:00
|
|
|
return (
|
|
|
|
'0x' +
|
|
|
|
utils.padLeft(utils.toHex(p.amount).substring(2), 48) +
|
|
|
|
utils.padLeft(utils.toHex(p.id).substring(2), 16)
|
|
|
|
);
|
2017-10-24 15:34:06 +00:00
|
|
|
});
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.mWithdraw(encodedPledges, { from: giver1, $extraGas: 200000 });
|
2017-06-27 11:08:23 +00:00
|
|
|
|
2018-02-16 21:44:44 +00:00
|
|
|
const initialBalance = await giver1Token.balanceOf(giver1);
|
2018-04-24 20:39:58 +00:00
|
|
|
await vault.multiConfirm([2, 3, 4, 5, 6], { $extraGas: 200000 });
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2018-02-16 21:44:44 +00:00
|
|
|
const finalBalance = await giver1Token.balanceOf(giver1);
|
2017-10-03 13:06:58 +00:00
|
|
|
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
|
2017-06-26 17:54:28 +00:00
|
|
|
|
2017-08-13 12:12:45 +00:00
|
|
|
assert.equal(collected, 0.95);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-03 10:20:23 +00:00
|
|
|
it('Should make a donation and create giver', async () => {
|
2017-10-03 12:42:21 +00:00
|
|
|
const oldNPledges = await liquidPledging.numberOfPledges();
|
2017-10-04 08:24:35 +00:00
|
|
|
const oldNAdmins = await liquidPledging.numberOfPledgeAdmins();
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addGiverAndDonate(1, giver2Token.$address, utils.toWei('1'), {
|
|
|
|
from: giver2,
|
|
|
|
$extraGas: 200000,
|
|
|
|
});
|
2017-10-03 12:42:21 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
2018-02-16 21:44:44 +00:00
|
|
|
assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 2);
|
2017-10-04 08:24:35 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(utils.toDecimal(nAdmins), utils.toDecimal(oldNAdmins) + 1);
|
|
|
|
const res = await liquidPledging.getPledgeAdmin(nAdmins);
|
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], '');
|
2017-10-04 09:40:26 +00:00
|
|
|
assert.equal(res[3], '');
|
|
|
|
assert.equal(res[4], 259200); // default to 3 day commitTime
|
2018-02-16 21:44:44 +00:00
|
|
|
const giver2Bal = await giver2Token.balanceOf(giver2);
|
|
|
|
assert.equal(giver2Bal, utils.toWei('999'));
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-10-05 19:51:23 +00:00
|
|
|
it('Should allow childProject with different parentProject owner', async () => {
|
|
|
|
const nAdminsBefore = await liquidPledging.numberOfPledgeAdmins();
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('Project3', 'URLProject3', adminProject3, 4, 86400, 0, {
|
|
|
|
from: adminProject3,
|
|
|
|
});
|
2017-10-05 19:51:23 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, utils.toDecimal(nAdminsBefore) + 1);
|
2017-10-23 21:25:06 +00:00
|
|
|
});
|
2017-11-24 16:21:07 +00:00
|
|
|
|
|
|
|
it('should throw if projectLevel > 20', async () => {
|
|
|
|
let nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('ProjectLevel0', '', adminProject1, 0, 86400, 0, {
|
|
|
|
from: adminProject1,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2018-02-07 11:52:08 +00:00
|
|
|
|
|
|
|
for (let i = 2; i <= 20; i++) {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject(`ProjectLevel${i}`, '', adminProject1, ++nAdmins, 86400, 0, {
|
|
|
|
from: adminProject1,
|
|
|
|
$extraGas: 100000,
|
|
|
|
});
|
2018-02-07 11:52:08 +00:00
|
|
|
}
|
2017-11-24 16:21:07 +00:00
|
|
|
|
2018-03-28 22:32:02 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.addProject('ProjectLevel21', '', adminProject1, ++nAdmins, 86400, 0, {
|
|
|
|
from: adminProject1,
|
|
|
|
gas: 4000000,
|
|
|
|
}),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2018-03-28 22:32:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should prevent donation to 0 receiverId', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await assertFail(
|
|
|
|
liquidPledging.donate(1, 0, giver1Token.$address, 1, { from: giver1, gas: 6700000 }),
|
|
|
|
);
|
2018-03-28 22:32:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should prevent donation from 0 giverId', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await assertFail(
|
|
|
|
liquidPledging.donate(0, 1, giver1Token.$address, 1, { from: giver1, gas: 6700000 }),
|
|
|
|
);
|
2018-03-28 22:32:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should donate on behalf of another addy', async () => {
|
|
|
|
const oldNPledges = await liquidPledging.numberOfPledges();
|
|
|
|
const oldNAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
const preGiver1Bal = await giver1Token.balanceOf(giver1);
|
2018-03-28 22:52:32 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addGiverAndDonate(1, accounts[8], giver1Token.$address, 11, {
|
|
|
|
from: giver1,
|
|
|
|
$extraGas: 200000,
|
|
|
|
});
|
2018-03-28 22:52:32 +00:00
|
|
|
|
2018-03-28 22:32:02 +00:00
|
|
|
const nPledges = await liquidPledging.numberOfPledges();
|
|
|
|
assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 1);
|
2018-03-28 22:52:32 +00:00
|
|
|
|
2018-03-28 22:32:02 +00:00
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(utils.toDecimal(nAdmins), utils.toDecimal(oldNAdmins) + 1);
|
2018-03-28 22:52:32 +00:00
|
|
|
|
2018-03-28 22:32:02 +00:00
|
|
|
const res = await liquidPledging.getPledgeAdmin(nAdmins);
|
|
|
|
assert.equal(res[0], 0); // Giver
|
|
|
|
assert.equal(res[1], accounts[8]);
|
|
|
|
assert.equal(res[2], '');
|
|
|
|
assert.equal(res[3], '');
|
|
|
|
assert.equal(res[4], 259200); // default to 3 day commitTime
|
2018-03-28 22:52:32 +00:00
|
|
|
|
2018-03-28 22:32:02 +00:00
|
|
|
const giver1Bal = await giver1Token.balanceOf(giver1);
|
|
|
|
assert.equal(new utils.BN(preGiver1Bal).subn(11).toString(), giver1Bal);
|
|
|
|
});
|
2018-06-16 17:54:30 +00:00
|
|
|
|
|
|
|
it('Should recover funds from contract instances', async function() {
|
|
|
|
assert.equal(await giver1Token.balanceOf(recoveryVault), 0);
|
|
|
|
assert.equal(await giver1Token.balanceOf(liquidPledging.$address), 0);
|
|
|
|
|
|
|
|
// shouldn't be able to send eth to contract
|
|
|
|
await assertFail(
|
|
|
|
web3.eth.sendTransaction({
|
|
|
|
to: liquidPledging.$address,
|
|
|
|
value: 1000,
|
|
|
|
from: giver1,
|
|
|
|
gas: 6700000,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// however, we can't stop tokens, so lets make sure we can recover them
|
|
|
|
await giver1Token.transfer(liquidPledging.$address, 1000, { from: giver1 });
|
|
|
|
assert.equal(await giver1Token.balanceOf(liquidPledging.$address), 1000);
|
|
|
|
|
|
|
|
const kernel = new Kernel(web3, await liquidPledging.kernel());
|
|
|
|
await liquidPledging.transferToVault(giver1Token.$address, { $extraGas: 100000 });
|
|
|
|
|
|
|
|
assert.equal(await giver1Token.balanceOf(recoveryVault), 1000);
|
|
|
|
assert.equal(await giver1Token.balanceOf(liquidPledging.$address), 0);
|
|
|
|
});
|
2017-06-26 17:54:28 +00:00
|
|
|
});
|