2017-10-19 16:49:16 +00:00
|
|
|
/* eslint-env mocha */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
2018-04-24 20:39:58 +00:00
|
|
|
const TestRPC = require('ganache-cli');
|
2017-10-19 16:49:16 +00:00
|
|
|
const Web3 = require('web3');
|
2018-04-24 20:39:58 +00:00
|
|
|
const { assert } = require('chai');
|
|
|
|
const { LPVault, LPFactory, LiquidPledgingState, test } = require('../index');
|
2017-10-19 16:49:16 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
const { StandardTokenTest, assertFail, LiquidPledgingMock } = test;
|
2017-10-19 16:49:16 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
const printState = async liquidPledgingState => {
|
2017-10-19 16:49:16 +00:00
|
|
|
const st = await liquidPledgingState.getState();
|
|
|
|
console.log(JSON.stringify(st, null, 2));
|
|
|
|
};
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
describe('LiquidPledging cancelPledge normal scenario', function() {
|
2017-10-19 16:49:16 +00:00
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
let testrpc;
|
|
|
|
let web3;
|
|
|
|
let accounts;
|
|
|
|
let liquidPledging;
|
|
|
|
let liquidPledgingState;
|
|
|
|
let vault;
|
|
|
|
let giver1;
|
|
|
|
let adminProject1;
|
|
|
|
let adminProject2;
|
2018-02-16 21:44:44 +00:00
|
|
|
let token;
|
2017-10-19 16:49:16 +00:00
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
testrpc = TestRPC.server({
|
2018-01-22 19:00:30 +00:00
|
|
|
gasLimit: 6700000,
|
2017-10-19 16:49:16 +00:00
|
|
|
total_accounts: 10,
|
|
|
|
});
|
|
|
|
|
2018-02-12 23:24:26 +00:00
|
|
|
testrpc.listen(8545, '127.0.0.1');
|
2017-10-19 16:49:16 +00:00
|
|
|
|
2018-02-12 23:24:26 +00:00
|
|
|
web3 = new Web3('http://localhost:8545');
|
2017-10-19 16:49:16 +00:00
|
|
|
accounts = await web3.eth.getAccounts();
|
2018-04-24 20:39:58 +00:00
|
|
|
giver1 = accounts[1];
|
|
|
|
adminProject1 = accounts[2];
|
|
|
|
adminProject2 = accounts[3];
|
2017-10-19 16:49:16 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
after(done => {
|
2017-10-19 16:49:16 +00:00
|
|
|
testrpc.close();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should deploy LiquidPledging contract', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
const baseVault = await LPVault.new(web3, accounts[0]);
|
|
|
|
const baseLP = await LiquidPledgingMock.new(web3, accounts[0]);
|
|
|
|
lpFactory = await LPFactory.new(web3, baseVault.$address, baseLP.$address);
|
2018-01-22 19:00:30 +00:00
|
|
|
|
2018-02-12 22:55:11 +00:00
|
|
|
const r = await lpFactory.newLP(accounts[0], accounts[0]);
|
2018-01-22 19:00:30 +00:00
|
|
|
|
2018-02-12 22:55:11 +00:00
|
|
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
2018-04-24 20:39:58 +00:00
|
|
|
vault = new LPVault(web3, vaultAddress);
|
2018-02-12 22:55:11 +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
|
|
|
|
2017-10-19 16:49:16 +00:00
|
|
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
2018-02-16 21:44:44 +00:00
|
|
|
|
2018-04-24 20:39:58 +00:00
|
|
|
token = await StandardTokenTest.new(web3);
|
2018-02-16 21:44:44 +00:00
|
|
|
await token.mint(giver1, web3.utils.toWei('1000'));
|
2018-04-24 20:39:58 +00:00
|
|
|
await token.approve(liquidPledging.$address, '0xFFFFFFFFFFFFFFFF', { from: giver1 });
|
2017-10-19 16:49:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should add project and donate ', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await liquidPledging.addProject('Project1', 'URLProject1', adminProject1, 0, 0, '0x0', {
|
|
|
|
from: adminProject1,
|
|
|
|
});
|
2018-02-16 21:44:44 +00:00
|
|
|
await liquidPledging.addGiverAndDonate(1, token.$address, 1000, { from: giver1 });
|
2017-10-19 16:49:16 +00:00
|
|
|
|
|
|
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
|
|
|
assert.equal(nAdmins, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should only allow pledge owner to cancel pledge', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await assertFail(liquidPledging.cancelPledge(2, 1000, { from: giver1, gas: 4000000 }));
|
2017-10-19 16:49:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should cancel pledge and return to oldPledge', async () => {
|
2018-02-12 22:55:11 +00:00
|
|
|
await liquidPledging.cancelPledge(2, 1000, { from: adminProject1, $extraGas: 200000 });
|
2017-10-19 16:49:16 +00:00
|
|
|
|
|
|
|
const st = await liquidPledgingState.getState();
|
|
|
|
|
|
|
|
assert.equal(st.pledges[1].amount, 1000);
|
|
|
|
assert.equal(st.pledges[2].amount, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should not allow to cancel pledge if oldPledge === 0', async () => {
|
2018-04-24 20:39:58 +00:00
|
|
|
await assertFail(liquidPledging.cancelPledge(1, 1000, { from: giver1, gas: 4000000 }));
|
|
|
|
});
|
2017-10-19 16:49:16 +00:00
|
|
|
});
|