Merge branch 'master' into quazia-comments

This commit is contained in:
Arthur Lunn 2017-11-18 17:53:57 +00:00 committed by GitHub
commit 7c2faf5e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 272 additions and 44 deletions

View File

@ -237,9 +237,6 @@ contract LiquidPledging is LiquidPledgingBase {
require(n.paymentState == PaymentState.Paying); require(n.paymentState == PaymentState.Paying);
// Check the project is not canceled in the while.
require(!isProjectCanceled(n.owner));
uint64 idNewPledge = findOrCreatePledge( uint64 idNewPledge = findOrCreatePledge(
n.owner, n.owner,
n.delegationChain, n.delegationChain,

View File

@ -18,6 +18,7 @@ pragma solidity ^0.4.11;
*/ */
import "./ILiquidPledgingPlugin.sol"; import "./ILiquidPledgingPlugin.sol";
import "../node_modules/giveth-common-contracts/contracts/Owned.sol";
/// @dev `Vault` serves as an interface to allow the `LiquidPledgingBase` /// @dev `Vault` serves as an interface to allow the `LiquidPledgingBase`
/// contract to interface with a `Vault` contract /// contract to interface with a `Vault` contract
@ -29,8 +30,7 @@ contract LPVault {
/// @dev `LiquidPledgingBase` is the base level contract used to carry out /// @dev `LiquidPledgingBase` is the base level contract used to carry out
/// liquid pledging. This function mostly handles the data structures /// liquid pledging. This function mostly handles the data structures
/// and basic CRUD methods for liquid pledging. /// and basic CRUD methods for liquid pledging.
contract LiquidPledgingBase { contract LiquidPledgingBase is Owned {
// Limits inserted to prevent large loops that could prevent canceling // Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20; uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20; uint constant MAX_SUBPROJECT_LEVEL = 20;
@ -75,6 +75,9 @@ contract LiquidPledgingBase {
// this mapping allows you to search for a specific pledge's // this mapping allows you to search for a specific pledge's
// index number by the hash of that pledge // index number by the hash of that pledge
mapping (bytes32 => uint64) hPledge2idx;//TODO Fix typo mapping (bytes32 => uint64) hPledge2idx;//TODO Fix typo
mapping (bytes32 => bool) pluginWhitelist;
bool public usePluginWhitelist = true;
///// /////
@ -103,7 +106,7 @@ contract LiquidPledgingBase {
/////// ///////
// Adminss functions // Admin functions
////// //////
/// @notice `addGiver` Creates a giver and adds them to the list of admins. /// @notice `addGiver` Creates a giver and adds them to the list of admins.
@ -118,7 +121,7 @@ contract LiquidPledgingBase {
uint64 commitTime, uint64 commitTime,
ILiquidPledgingPlugin plugin ILiquidPledgingPlugin plugin
) returns (uint64 idGiver) { ) returns (uint64 idGiver) {
require(isValidPlugin(plugin));
idGiver = uint64(admins.length); idGiver = uint64(admins.length);
admins.push(PledgeAdmin( admins.push(PledgeAdmin(
@ -174,8 +177,8 @@ contract LiquidPledgingBase {
string url, string url,
uint64 commitTime, uint64 commitTime,
ILiquidPledgingPlugin plugin ILiquidPledgingPlugin plugin
) returns (uint64 idxDelegate) { //TODO return index number ) returns (uint64 idDelegate) { //TODO return index number
require(isValidPlugin(plugin));
idxDelegate = uint64(admins.length); idxDelegate = uint64(admins.length);
admins.push(PledgeAdmin( admins.push(PledgeAdmin(
@ -218,7 +221,7 @@ contract LiquidPledgingBase {
DelegateUpdated(idxDelegate); DelegateUpdated(idxDelegate);
} }
event DelegateUpdated(uint64 indexed idxDelegate); event DelegateUpdated(uint64 indexed idDelegate);
/// @notice `addProject` Creates a project and adds it to the list of admins. /// @notice `addProject` Creates a project and adds it to the list of admins.
/// @param name This is the name used to identify the project. /// @param name This is the name used to identify the project.
@ -236,6 +239,8 @@ contract LiquidPledgingBase {
uint64 commitTime, uint64 commitTime,
ILiquidPledgingPlugin plugin ILiquidPledgingPlugin plugin
) returns (uint64 idProject) { ) returns (uint64 idProject) {
require(isValidPlugin(plugin));
if (parentProject != 0) { if (parentProject != 0) {
PledgeAdmin storage pa = findAdmin(parentProject); PledgeAdmin storage pa = findAdmin(parentProject);
require(pa.adminType == PledgeAdminType.Project); require(pa.adminType == PledgeAdminType.Project);
@ -502,4 +507,46 @@ contract LiquidPledgingBase {
function checkAdminOwner(PledgeAdmin m) internal constant { function checkAdminOwner(PledgeAdmin m) internal constant {
require((msg.sender == m.addr) || (msg.sender == address(m.plugin))); require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
} }
////////
// Plugin Whitelist Methods
///////
function addValidPlugin(bytes32 contractHash) external onlyOwner {
pluginWhitelist[contractHash] = true;
}
function removeValidPlugin(bytes32 contractHash) external onlyOwner {
pluginWhitelist[contractHash] = false;
}
function useWhitelist(bool useWhitelist) external onlyOwner {
usePluginWhitelist = useWhitelist;
}
function isValidPlugin(address addr) public returns(bool) {
if (!usePluginWhitelist || addr == 0x0) return true;
bytes32 contractHash = getCodeHash(addr);
return pluginWhitelist[contractHash];
}
function getCodeHash(address addr) public returns(bytes32) {
bytes memory o_code;
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(addr)
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
o_code := mload(0x40)
// new "memory end" including padding
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
// store length in memory
mstore(o_code, size)
// actually retrieve the code, this needs assembly
extcodecopy(addr, add(o_code, 0x20), 0, size)
}
return keccak256(o_code);
}
} }

View File

@ -0,0 +1,52 @@
pragma solidity ^0.4.11;
import "../LiquidPledging.sol";
// simple liquidPledging plugin contract for testing whitelist
contract TestSimpleProjectPlugin {
uint64 public idProject;
bool initPending;
event BeforeTransfer(uint64 pledgeAdmin, uint64 pledgeFrom, uint64 pledgeTo, uint64 context, uint amount);
event AfterTransfer(uint64 pledgeAdmin, uint64 pledgeFrom, uint64 pledgeTo, uint64 context, uint amount);
function TestSimpleProjectPlugin() {
require(msg.sender != tx.origin); // Avoids being created directly by mistake.
initPending = true;
}
function init(
LiquidPledging liquidPledging,
string name,
string url,
uint64 parentProject
) {
require(initPending);
idProject = liquidPledging.addProject(name, url, address(this), parentProject, 0, ILiquidPledgingPlugin(this));
initPending = false;
}
function beforeTransfer(
uint64 pledgeAdmin,
uint64 pledgeFrom,
uint64 pledgeTo,
uint64 context,
uint amount
) external returns (uint maxAllowed) {
require(!initPending);
BeforeTransfer(pledgeAdmin, pledgeFrom, pledgeTo, context, amount);
}
function afterTransfer(
uint64 pledgeAdmin,
uint64 pledgeFrom,
uint64 pledgeTo,
uint64 context,
uint amount
) external {
require(!initPending);
AfterTransfer(pledgeAdmin, pledgeFrom, pledgeTo, context, amount);
}
}

View File

@ -0,0 +1,19 @@
pragma solidity ^0.4.11;
import "./TestSimpleProjectPlugin.sol";
import "../LiquidPledging.sol";
// simple factory for deploying TestSimpleProjectPlugin.sol contract
contract TestSimpleProjectPluginFactory {
function deploy(
LiquidPledging liquidPledging,
string name,
string url,
uint64 parentProject
) {
TestSimpleProjectPlugin p = new TestSimpleProjectPlugin();
p.init(liquidPledging, name, url, parentProject);
}
}

View File

@ -7,8 +7,8 @@
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"build": "solcpiler", "build": "solcpiler -i './contracts/**/*.sol'",
"test": "solcpiler; mocha --harmony" "test": "npm run build; mocha --harmony"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -38,13 +38,14 @@
"lerna": "^2.2.0", "lerna": "^2.2.0",
"random-bytes": "^1.0.0", "random-bytes": "^1.0.0",
"mocha": "^3.5.0", "mocha": "^3.5.0",
"solcpiler": "0.0.4", "solcpiler": "0.0.7",
"web3": "1.0.0-beta.24" "web3": "1.0.0-beta.24"
}, },
"homepage": "https://github.com/Giveth/liquidpledging#readme", "homepage": "https://github.com/Giveth/liquidpledging#readme",
"dependencies": { "dependencies": {
"async": "^2.4.0", "async": "^2.4.0",
"chai": "^4.1.0", "chai": "^4.1.0",
"eth-contract-class": "0.0.6" "eth-contract-class": "0.0.6",
"giveth-common-contracts": "^0.4.0"
} }
} }

117
test/AdminPlugins.js Normal file
View File

@ -0,0 +1,117 @@
/* eslint-env mocha */
/* eslint-disable no-await-in-loop */
const TestRPC = require('ethereumjs-testrpc');
const Web3 = require('web3');
const chai = require('chai');
const liquidpledging = require('../index.js');
const assertFail = require('./helpers/assertFail');
const LiquidPledging = liquidpledging.LiquidPledgingMock;
const LiquidPledgingState = liquidpledging.LiquidPledgingState;
const simpleProjectPluginFactoryAbi = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginFactoryAbi;
const simpleProjectPluginFactoryByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginFactoryByteCode;
const simpleProjectPluginRuntimeByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginRuntimeByteCode;
const Vault = liquidpledging.Vault;
const assert = chai.assert;
const printState = async (liquidPledgingState) => {
const st = await liquidPledgingState.getState();
console.log(JSON.stringify(st, null, 2));
};
describe('LiquidPledging plugins test', function () {
this.timeout(0);
let testrpc;
let web3;
let accounts;
let liquidPledging;
let liquidPledgingState;
let vault;
let giver1;
let adminProject1;
let adminDelegate1;
before(async () => {
testrpc = TestRPC.server({
ws: true,
gasLimit: 6500000,
total_accounts: 10,
});
testrpc.listen(8546, '127.0.0.1');
web3 = new Web3('ws://localhost:8546');
accounts = await web3.eth.getAccounts();
giver1 = accounts[ 1 ];
adminProject1 = accounts[ 2 ];
adminDelegate1 = accounts[ 3 ];
});
after((done) => {
testrpc.close();
done();
});
it('Should deploy LiquidPledging contract', async function() {
vault = await Vault.new(web3);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 6500000 });
await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging);
});
it('Should create create giver with no plugin', async function() {
await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: adminProject1 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 1);
});
it('Should fail to create giver with invalid plugin', async function() {
await assertFail(async () => {
await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1 });
});
});
it('Should fail to create delegate with invalid plugin', async function() {
await assertFail(async () => {
await liquidPledging.addDelegate('delegate1', '', 0, liquidPledging.$address, { from: adminDelegate1});
});
});
it('Should fail to create project with invalid plugin', async function() {
await assertFail(async () => {
await liquidPledging.addProject('Project1', '', giver1, 0, 0, vault.$address, { from: adminProject1});
});
});
it('Should deploy TestSimpleProjectPlugin and add project', async function() {
// add plugin as valid plugin
const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode);
await liquidPledging.addValidPlugin(codeHash);
// deploy new plugin
const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi)
.deploy({
data: simpleProjectPluginFactoryByteCode,
arguments: []
}).send({ from: adminProject1, gas: 5000000 });
await factoryContract.methods
.deploy(liquidPledging.$address, "SimplePlugin1", "", 0)
.send({ from: adminProject1, gas: 4000000 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 2);
});
it('Should allow all plugins', async function() {
await liquidPledging.useWhitelist(false, { gas: 100000 });
await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1, gas: 200000 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 3);
});
});

View File

@ -79,7 +79,7 @@ describe('LiquidPledging test', function () {
assert.equal(res[4], 86400); assert.equal(res[4], 86400);
}); });
it('Should make a donation', async () => { it('Should make a donation', async () => {
await liquidPledging.donate(1, 1, { from: giver1, value: utils.toWei(1) }); await liquidPledging.donate(1, 1, { from: giver1, value: utils.toWei('1') });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 1); assert.equal(nPledges, 1);
await liquidPledging.getPledge(1); await liquidPledging.getPledge(1);
@ -96,13 +96,13 @@ describe('LiquidPledging test', function () {
assert.equal(res[4], 0); assert.equal(res[4], 0);
}); });
it('Giver should delegate on the delegate', async () => { it('Giver should delegate on the delegate', async () => {
await liquidPledging.transfer(1, 1, utils.toWei(0.5), 2, { from: giver1 }); await liquidPledging.transfer(1, 1, utils.toWei('0.5'), 2, { from: giver1 });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 2); assert.equal(nPledges, 2);
const res1 = await liquidPledging.getPledge(1); const res1 = await liquidPledging.getPledge(1);
assert.equal(res1[0], utils.toWei(0.5)); assert.equal(res1[0], utils.toWei('0.5'));
const res2 = await liquidPledging.getPledge(2); const res2 = await liquidPledging.getPledge(2);
assert.equal(res2[0], utils.toWei(0.5)); assert.equal(res2[0], utils.toWei('0.5'));
assert.equal(res2[1], 1); // One delegate assert.equal(res2[1], 1); // One delegate
const d = await liquidPledging.getPledgeDelegate(2, 1); const d = await liquidPledging.getPledgeDelegate(2, 1);
@ -139,11 +139,11 @@ describe('LiquidPledging test', function () {
}); });
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, utils.toWei(0.2), 3, { from: delegate1 }); await liquidPledging.transfer(2, 2, utils.toWei('0.2'), 3, { from: delegate1 });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 3); assert.equal(nPledges, 3);
const res3 = await liquidPledging.getPledge(3); const res3 = await liquidPledging.getPledge(3);
assert.equal(res3[0], utils.toWei(0.2)); assert.equal(res3[0], utils.toWei('0.2'));
assert.equal(res3[1], 1); // Owner assert.equal(res3[1], 1); // Owner
assert.equal(res3[2], 1); // Delegates assert.equal(res3[2], 1); // Delegates
assert.equal(res3[3], 3); // Proposed Project assert.equal(res3[3], 3); // Proposed Project
@ -152,11 +152,11 @@ describe('LiquidPledging test', function () {
assert.equal(res3[6], 0); // Not Paid assert.equal(res3[6], 0); // Not Paid
}); });
it('Giver should change his mind and assign half of it to project2', async () => { it('Giver should change his mind and assign half of it to project2', async () => {
await liquidPledging.transfer(1, 3, utils.toWei(0.1), 4, { from: giver1 }); await liquidPledging.transfer(1, 3, utils.toWei('0.1'), 4, { from: giver1 });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 4); assert.equal(nPledges, 4);
const res3 = await liquidPledging.getPledge(3); const res3 = await liquidPledging.getPledge(3);
assert.equal(res3[0], utils.toWei(0.1)); assert.equal(res3[0], utils.toWei('0.1'));
const res4 = await liquidPledging.getPledge(4); const res4 = await liquidPledging.getPledge(4);
assert.equal(res4[1], 4); // Owner assert.equal(res4[1], 4); // Owner
assert.equal(res4[2], 0); // Delegates assert.equal(res4[2], 0); // Delegates
@ -168,11 +168,11 @@ describe('LiquidPledging test', function () {
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, utils.toWei(0.05), { from: adminProject1 }); await liquidPledging.withdraw(3, utils.toWei('0.05'), { from: adminProject1 });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 6); assert.equal(nPledges, 6);
const res5 = await liquidPledging.getPledge(5); const res5 = await liquidPledging.getPledge(5);
assert.equal(res5[0], utils.toWei(0.05)); assert.equal(res5[0], utils.toWei('0.05'));
assert.equal(res5[1], 3); // Owner assert.equal(res5[1], 3); // Owner
assert.equal(res5[2], 0); // Delegates assert.equal(res5[2], 0); // Delegates
assert.equal(res5[3], 0); // Proposed Project assert.equal(res5[3], 0); // Proposed Project
@ -180,7 +180,7 @@ describe('LiquidPledging test', function () {
assert.equal(res5[5], 2); // Old Node assert.equal(res5[5], 2); // Old Node
assert.equal(res5[6], 0); // Not Paid assert.equal(res5[6], 0); // Not Paid
const res6 = await liquidPledging.getPledge(6); const res6 = await liquidPledging.getPledge(6);
assert.equal(res6[0], utils.toWei(0.05)); assert.equal(res6[0], utils.toWei('0.05'));
assert.equal(res6[1], 3); // Owner assert.equal(res6[1], 3); // Owner
assert.equal(res6[2], 0); // Delegates assert.equal(res6[2], 0); // Delegates
assert.equal(res6[3], 0); // Proposed Project assert.equal(res6[3], 0); // Proposed Project
@ -201,7 +201,7 @@ describe('LiquidPledging test', function () {
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 7); assert.equal(nPledges, 7);
const res7 = await liquidPledging.getPledge(7); const res7 = await liquidPledging.getPledge(7);
assert.equal(res7[0], utils.toWei(0.05)); assert.equal(res7[0], utils.toWei('0.05'));
assert.equal(res7[1], 3); // Owner assert.equal(res7[1], 3); // Owner
assert.equal(res7[2], 0); // Delegates assert.equal(res7[2], 0); // Delegates
assert.equal(res7[3], 0); // Proposed Project assert.equal(res7[3], 0); // Proposed Project
@ -218,11 +218,11 @@ describe('LiquidPledging test', function () {
const st = await liquidPledgingState.getState(liquidPledging); const st = await liquidPledgingState.getState(liquidPledging);
assert.equal(utils.fromWei(st.pledges[5].amount), 0.05); assert.equal(utils.fromWei(st.pledges[5].amount), 0.05);
await assertFail(async () => { await assertFail(async () => {
await liquidPledging.withdraw(5, utils.toWei(0.01), { from: adminProject1 }); await liquidPledging.withdraw(5, utils.toWei('0.01'), { from: adminProject1 });
}); });
}); });
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, utils.toWei(0.03), 4, { await liquidPledging.transfer(2, 5, utils.toWei('0.03'), 4, {
$extraGas: 100000, $extraGas: 100000,
from: delegate1, from: delegate1,
}); });
@ -235,7 +235,7 @@ describe('LiquidPledging test', function () {
assert.equal(st.pledges[8].intendedProject, 4); assert.equal(st.pledges[8].intendedProject, 4);
}); });
it('Giver should be able to send the remaining to project2', async () => { it('Giver should be able to send the remaining to project2', async () => {
await liquidPledging.transfer(1, 5, utils.toWei(0.02), 4, { from: giver1, $extraGas: 100000 }); await liquidPledging.transfer(1, 5, utils.toWei('0.02'), 4, { from: giver1, $extraGas: 100000 });
const st = await liquidPledgingState.getState(liquidPledging); const st = await liquidPledgingState.getState(liquidPledging);
assert.equal(st.pledges.length, 9); assert.equal(st.pledges.length, 9);
assert.equal(utils.fromWei(st.pledges[5].amount), 0); assert.equal(utils.fromWei(st.pledges[5].amount), 0);
@ -248,14 +248,14 @@ describe('LiquidPledging test', function () {
assert.equal(nAdmins, 6); assert.equal(nAdmins, 6);
}); });
it('Project 2 delegate in delegate2', async () => { it('Project 2 delegate in delegate2', async () => {
await liquidPledging.transfer(4, 4, utils.toWei(0.02), 6, { from: adminProject2 }); await liquidPledging.transfer(4, 4, utils.toWei('0.02'), 6, { from: adminProject2 });
const st = await liquidPledgingState.getState(liquidPledging); const st = await liquidPledgingState.getState(liquidPledging);
assert.equal(st.pledges.length, 10); assert.equal(st.pledges.length, 10);
assert.equal(utils.fromWei(st.pledges[9].amount), 0.02); assert.equal(utils.fromWei(st.pledges[9].amount), 0.02);
assert.equal(utils.fromWei(st.pledges[4].amount), 0.1); assert.equal(utils.fromWei(st.pledges[4].amount), 0.1);
}); });
it('delegate2 assigns to projec2a', async () => { it('delegate2 assigns to projec2a', async () => {
await liquidPledging.transfer(6, 9, utils.toWei(0.01), 5, { from: delegate2 }); await liquidPledging.transfer(6, 9, utils.toWei('0.01'), 5, { from: delegate2 });
const st = await liquidPledgingState.getState(liquidPledging); const st = await liquidPledgingState.getState(liquidPledging);
assert.equal(st.pledges.length, 11); assert.equal(st.pledges.length, 11);
assert.equal(utils.fromWei(st.pledges[9].amount), 0.01); assert.equal(utils.fromWei(st.pledges[9].amount), 0.01);
@ -264,7 +264,7 @@ describe('LiquidPledging test', function () {
it('project2a authorize to spend a litle', 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, utils.toWei(0.005), { from: adminProject2a }); await liquidPledging.withdraw(10, utils.toWei('0.005'), { from: adminProject2a });
const st = await liquidPledgingState.getState(liquidPledging); const st = await liquidPledgingState.getState(liquidPledging);
assert.equal(st.pledges.length, 13); assert.equal(st.pledges.length, 13);
assert.equal(utils.fromWei(st.pledges[10].amount), 0); assert.equal(utils.fromWei(st.pledges[10].amount), 0);
@ -274,14 +274,9 @@ describe('LiquidPledging test', function () {
it('project2 is canceled', async () => { it('project2 is canceled', async () => {
await liquidPledging.cancelProject(4, { from: adminProject2 }); await liquidPledging.cancelProject(4, { from: adminProject2 });
}); });
it('project2 should not be able to confirm payment', async () => {
await assertFail(async () => {
await vault.confirmPayment(1);
});
});
it('Should not be able to withdraw it', async () => { it('Should not be able to withdraw it', async () => {
await assertFail(async () => { await assertFail(async () => {
await liquidPledging.withdraw(12, utils.toWei(0.005), { from: giver1 }); await liquidPledging.withdraw(12, utils.toWei('0.005'), { from: giver1 });
}); });
}); });
it('Should be able to cancel payment', async () => { it('Should be able to cancel payment', async () => {
@ -295,11 +290,11 @@ describe('LiquidPledging test', function () {
}); });
it('original owner should recover the remaining funds', async () => { it('original owner should recover the remaining funds', async () => {
const pledges = [ const pledges = [
{ amount: utils.toWei(0.5), id: 1 }, { amount: utils.toWei('0.5'), id: 1 },
{ amount: utils.toWei(0.31), id: 2 }, { amount: utils.toWei('0.31'), id: 2 },
{ amount: utils.toWei(0.1), id: 4 }, { amount: utils.toWei('0.1'), id: 4 },
{ amount: utils.toWei(0.03), id: 8 }, { amount: utils.toWei('0.03'), id: 8 },
{ amount: utils.toWei(0.01), id: 9 }, { amount: utils.toWei('0.01'), id: 9 },
]; ];
// .substring is to remove the 0x prefix on the toHex result // .substring is to remove the 0x prefix on the toHex result
@ -320,7 +315,7 @@ describe('LiquidPledging test', function () {
it('Should make a donation and create giver', async () => { it('Should make a donation and create giver', async () => {
const oldNPledges = await liquidPledging.numberOfPledges(); const oldNPledges = await liquidPledging.numberOfPledges();
const oldNAdmins = await liquidPledging.numberOfPledgeAdmins(); const oldNAdmins = await liquidPledging.numberOfPledgeAdmins();
await liquidPledging.donate(0, 1, { from: giver2, value: utils.toWei(1) }); await liquidPledging.donate(0, 1, { from: giver2, value: utils.toWei('1') });
const nPledges = await liquidPledging.numberOfPledges(); const nPledges = await liquidPledging.numberOfPledges();
assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 1); assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 1);
const nAdmins = await liquidPledging.numberOfPledgeAdmins(); const nAdmins = await liquidPledging.numberOfPledgeAdmins();