2017-11-16 23:15:32 +00:00
|
|
|
/* eslint-env mocha */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
2018-06-16 17:54:30 +00:00
|
|
|
const Ganache = require('ganache-cli');
|
2017-11-16 23:15:32 +00:00
|
|
|
const Web3 = require('web3');
|
|
|
|
const chai = require('chai');
|
2018-06-16 17:54:30 +00:00
|
|
|
const { test } = require('../index');
|
|
|
|
const deployLP = require('./helpers/deployLP');
|
2018-04-24 20:39:58 +00:00
|
|
|
|
2018-11-15 20:22:12 +00:00
|
|
|
const compilerOutput = require('../dist/contracts/TestSimpleProjectPluginFactory.json');
|
|
|
|
const simpleProjectPluginFactoryAbi = compilerOutput.abiDefinition;
|
|
|
|
const simpleProjectPluginFactoryByteCode = compilerOutput.code;
|
|
|
|
const simpleProjectPluginRuntimeByteCode = '0x' + require('../dist/contracts/TestSimpleProjectPlugin.json').code;
|
2017-11-16 23:15:32 +00:00
|
|
|
const assert = chai.assert;
|
|
|
|
|
2018-06-16 17:54:30 +00:00
|
|
|
const { assertFail } = test;
|
2018-04-24 20:39:58 +00:00
|
|
|
|
|
|
|
const printState = async liquidPledgingState => {
|
2017-11-16 23:15:32 +00:00
|
|
|
const st = await liquidPledgingState.getState();
|
|
|
|
console.log(JSON.stringify(st, null, 2));
|
|
|
|
};
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
describe('LiquidPledging plugins test', function() {
|
2017-11-16 23:15:32 +00:00
|
|
|
this.timeout(0);
|
|
|
|
|
2018-06-16 17:54:30 +00:00
|
|
|
let ganache;
|
2017-11-16 23:15:32 +00:00
|
|
|
let web3;
|
|
|
|
let accounts;
|
|
|
|
let liquidPledging;
|
|
|
|
let liquidPledgingState;
|
|
|
|
let vault;
|
|
|
|
let giver1;
|
|
|
|
let adminProject1;
|
|
|
|
let adminDelegate1;
|
|
|
|
|
|
|
|
before(async () => {
|
2018-06-16 17:54:30 +00:00
|
|
|
ganache = Ganache.server({
|
2018-01-22 19:00:30 +00:00
|
|
|
gasLimit: 6700000,
|
2017-11-16 23:15:32 +00:00
|
|
|
total_accounts: 10,
|
|
|
|
});
|
|
|
|
|
2018-06-16 17:54:30 +00:00
|
|
|
ganache.listen(8545, '127.0.0.1');
|
2017-11-16 23:15:32 +00:00
|
|
|
|
2018-02-12 23:24:26 +00:00
|
|
|
web3 = new Web3('http://localhost:8545');
|
2017-11-16 23:15:32 +00:00
|
|
|
accounts = await web3.eth.getAccounts();
|
2018-02-12 22:55:11 +00:00
|
|
|
adminProject1 = accounts[2];
|
|
|
|
adminDelegate1 = accounts[3];
|
2018-06-16 17:54:30 +00:00
|
|
|
|
|
|
|
const deployment = await deployLP(web3);
|
|
|
|
giver1 = deployment.giver1;
|
|
|
|
vault = deployment.vault;
|
|
|
|
liquidPledging = deployment.liquidPledging;
|
|
|
|
liquidPledgingState = deployment.liquidPledgingState;
|
2017-11-16 23:15:32 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
after(done => {
|
2018-06-16 17:54:30 +00:00
|
|
|
ganache.close();
|
2017-11-16 23:15:32 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should create create giver with no plugin', async function() {
|
2017-11-16 23:15:32 +00:00
|
|
|
await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: adminProject1 });
|
|
|
|
|
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 1);
|
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should fail to create giver with invalid plugin', async function() {
|
2018-01-25 23:09:58 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1, gas: 4000000 }),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2017-11-16 23:15:32 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should fail to create delegate with invalid plugin', async function() {
|
2018-01-25 23:09:58 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.addDelegate('delegate1', '', 0, liquidPledging.$address, {
|
|
|
|
from: adminDelegate1,
|
|
|
|
gas: 4000000,
|
|
|
|
}),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2017-11-16 23:15:32 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should fail to create project with invalid plugin', async function() {
|
2018-01-25 23:09:58 +00:00
|
|
|
await assertFail(
|
2018-04-24 20:39:58 +00:00
|
|
|
liquidPledging.addProject('Project1', '', giver1, 0, 0, vault.$address, {
|
|
|
|
from: adminProject1,
|
|
|
|
gas: 4000000,
|
|
|
|
}),
|
2018-01-25 23:09:58 +00:00
|
|
|
);
|
2017-11-16 23:15:32 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should deploy TestSimpleProjectPlugin and add project', async function() {
|
2017-11-16 23:15:32 +00:00
|
|
|
// add plugin as valid plugin
|
|
|
|
const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode);
|
2018-02-24 15:36:09 +00:00
|
|
|
await liquidPledging.addValidPluginContract(codeHash, { $extraGas: 200000 });
|
2017-11-16 23:15:32 +00:00
|
|
|
|
|
|
|
// deploy new plugin
|
|
|
|
const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi)
|
|
|
|
.deploy({
|
|
|
|
data: simpleProjectPluginFactoryByteCode,
|
2018-04-24 20:39:58 +00:00
|
|
|
arguments: [],
|
|
|
|
})
|
|
|
|
.send({ from: adminProject1, gas: 5000000 });
|
2018-01-22 19:00:30 +00:00
|
|
|
factoryContract.setProvider(web3.currentProvider);
|
2017-11-16 23:15:32 +00:00
|
|
|
|
|
|
|
await factoryContract.methods
|
2018-04-24 20:39:58 +00:00
|
|
|
.deploy(liquidPledging.$address, 'SimplePlugin1', '', 0)
|
|
|
|
.send({ from: adminProject1, gas: 5000000 });
|
2017-11-16 23:15:32 +00:00
|
|
|
|
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 2);
|
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
it('Should allow all plugins', async function() {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.useWhitelist(false, { $extraGas: 200000 });
|
2017-11-16 23:15:32 +00:00
|
|
|
|
2018-01-25 23:09:58 +00:00
|
|
|
await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1 });
|
2017-11-16 23:15:32 +00:00
|
|
|
|
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 3);
|
|
|
|
});
|
|
|
|
});
|