From ece3355c67432cf4e6a4282bbbadcca8942484ca Mon Sep 17 00:00:00 2001 From: perissology Date: Mon, 12 Feb 2018 23:55:11 +0100 Subject: [PATCH] all tests passing --- contracts/EscapableApp.sol | 4 +- contracts/LPVault.sol | 16 +++---- contracts/LiquidPledging.sol | 33 ++++++------- contracts/LiquidPledgingBase.sol | 17 +++---- contracts/LiquidPledgingMock.sol | 5 +- contracts/PledgeAdmins.sol | 12 +---- contracts/Pledges.sol | 8 ---- js/liquidPledgingState.js | 4 +- test/AdminPlugins.js | 50 +++++++++---------- test/CancelPledge.js | 24 +++++----- test/DelegationChain.js | 82 ++++++++++++++++---------------- test/NormalOperation.js | 64 ++++++++++++++----------- test/NormalizePledge.js | 50 +++++++++---------- test/Vault.js | 53 +++++++++++++++------ 14 files changed, 213 insertions(+), 209 deletions(-) diff --git a/contracts/EscapableApp.sol b/contracts/EscapableApp.sol index ddf2b39..3a22751 100644 --- a/contracts/EscapableApp.sol +++ b/contracts/EscapableApp.sol @@ -29,7 +29,7 @@ import "@aragon/os/contracts/apps/AragonApp.sol"; /// not blacklisted contract EscapableApp is AragonApp { // warning whoever has this role can move all funds to the `escapeHatchDestination` - bytes32 constant public ESCAPE_HATCH_CALLER_ROLE = bytes32(1); + bytes32 constant public ESCAPE_HATCH_CALLER_ROLE = keccak256("ESCAPE_HATCH_CALLER_ROLE"); address public escapeHatchDestination; mapping (address=>bool) private escapeBlacklist; // Token contract addresses @@ -38,7 +38,7 @@ contract EscapableApp is AragonApp { /// Multisig) to send the ether held in this contract; if a neutral address /// is required, the WHG Multisig is an option: /// 0x8Ff920020c8AD673661c8117f2855C384758C572 - function initialize(address _escapeHatchDestination) onlyInit external { + function initialize(address _escapeHatchDestination) onlyInit public { initialized(); require(_escapeHatchDestination != 0x0); diff --git a/contracts/LPVault.sol b/contracts/LPVault.sol index 76fc2e6..ba9bfbd 100644 --- a/contracts/LPVault.sol +++ b/contracts/LPVault.sol @@ -40,10 +40,10 @@ contract ILiquidPledging { /// contract that holds funds for the liquid pledging system. contract LPVault is EscapableApp { - bytes32 constant public CONFIRM_PAYMENT_ROLE = bytes32(1); - bytes32 constant public CANCEL_PAYMENT_ROLE = bytes32(2); - bytes32 constant public AUTHORIZE_PAYMENT_ROLE = bytes32(3); - bytes32 constant public SET_AUTOPAY_ROLE = bytes32(4); + bytes32 constant public CONFIRM_PAYMENT_ROLE = keccak256("CONFIRM_PAYMENT_ROLE"); + bytes32 constant public CANCEL_PAYMENT_ROLE = keccak256("CANCEL_PAYMENT_ROLE"); + bytes32 constant public AUTHORIZE_PAYMENT_ROLE = keccak256("AUTHORIZE_PAYMENT_ROLE"); + bytes32 constant public SET_AUTOPAY_ROLE = keccak256("SET_AUTOPAY_ROLE"); event AutoPaySet(bool autoPay); event EscapeFundsCalled(address token, uint amount); @@ -85,7 +85,7 @@ contract LPVault is EscapableApp { _; } - function initialize(address _escapeHatchDestination) onlyInit external { + function initialize(address _escapeHatchDestination) onlyInit public { require(false); // overload the EscapableApp } @@ -95,11 +95,9 @@ contract LPVault is EscapableApp { /// is required, the WHG Multisig is an option: /// 0x8Ff920020c8AD673661c8117f2855C384758C572 function initialize(address _liquidPledging, address _escapeHatchDestination) onlyInit external { - initialized(); - require(_escapeHatchDestination != 0x0); - require(_liquidPledging != 0x0); + super.initialize(_escapeHatchDestination); - escapeHatchDestination = _escapeHatchDestination; + require(_liquidPledging != 0x0); liquidPledging = ILiquidPledging(_liquidPledging); } diff --git a/contracts/LiquidPledging.sol b/contracts/LiquidPledging.sol index 31c27d5..c332fd8 100644 --- a/contracts/LiquidPledging.sol +++ b/contracts/LiquidPledging.sol @@ -28,19 +28,6 @@ import "./LiquidPledgingBase.sol"; contract LiquidPledging is LiquidPledgingBase { -////// -// Constructor -////// - - /// @notice Basic constructor for LiquidPleding, also calls the - /// LiquidPledgingBase contract - /// @dev This constructor also calls the constructor - /// for `LiquidPledgingBase` - function LiquidPledging() - LiquidPledgingBase() public - { - } - /// @notice This is how value enters the system and how pledges are created; /// the ether is sent to the vault, an pledge for the Giver is created (or /// found), the amount of ETH donated in wei is added to the `amount` in @@ -49,7 +36,7 @@ contract LiquidPledging is LiquidPledgingBase { /// @param idGiver The id of the Giver donating; if 0, a new id is created /// @param idReceiver The Admin receiving the donation; can be any Admin: /// the Giver themselves, another Giver, a Delegate or a Project - function donate(uint64 idGiver, uint64 idReceiver) authP(PLEDGE_ADMIN_ROLE, arr(uint(idGiver))) + function donate(uint64 idGiver, uint64 idReceiver) public payable { // TODO: maybe need a separate role here to allow giver creation @@ -59,12 +46,15 @@ contract LiquidPledging is LiquidPledgingBase { } PledgeAdmins.PledgeAdmin storage sender = _findAdmin(idGiver); - // _checkAdminOwner(sender); require(sender.adminType == PledgeAdminType.Giver); + require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(idGiver)))); uint amount = msg.value; require(amount > 0); - vault.transfer(amount); // Sends the `msg.value` (in wei) to the `vault` + // Sends the `msg.value` (in wei) to the `vault` + // b/c the vault is a proxy, send & transfer will fail since they only provide 2300 + // gas, and the delegateProxy will sub(gas, 10000) before even making the call + require(vault.call.value(amount).gas(16000)()); uint64 idPledge = _findOrCreatePledge( idGiver, @@ -223,14 +213,14 @@ contract LiquidPledging is LiquidPledgingBase { /// intendedProject /// @param idPledge Id of the pledge that is to be redeemed into ether /// @param amount Quantity of ether (in wei) to be authorized - function withdraw(uint64 idPledge, uint amount) authP(PLEDGE_ADMIN_ROLE, arr(uint(idPledge), amount)) public { + function withdraw(uint64 idPledge, uint amount) public { idPledge = normalizePledge(idPledge); // Updates pledge info Pledges.Pledge storage p = _findPledge(idPledge); require(p.pledgeState == PledgeState.Pledged); PledgeAdmins.PledgeAdmin storage owner = _findAdmin(p.owner); - // _checkAdminOwner(owner); + require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner)))); uint64 idNewPledge = _findOrCreatePledge( p.owner, @@ -307,12 +297,13 @@ contract LiquidPledging is LiquidPledgingBase { /// @param idPledge Id of the pledge that is to be canceled /// @param amount Quantity of ether (in wei) to be transfered to the /// `oldPledge` - function cancelPledge(uint64 idPledge, uint amount) authP(PLEDGE_ADMIN_ROLE, arr(uint(idPledge))) public { + function cancelPledge(uint64 idPledge, uint amount) public {//authP(PLEDGE_ADMIN_ROLE, arr(uint(idPledge))) public { idPledge = normalizePledge(idPledge); Pledges.Pledge storage p = _findPledge(idPledge); require(p.oldPledge != 0); + require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner)))); // PledgeAdmins.PledgeAdmin storage a = _findAdmin(p.owner); // _checkAdminOwner(a); @@ -811,6 +802,10 @@ contract LiquidPledging is LiquidPledgingBase { return now; } + function getTime() public view returns(uint) { + return _getTime(); + } + // Event Declarations event Transfer(uint indexed from, uint indexed to, uint amount); event CancelProject(uint indexed idProject); diff --git a/contracts/LiquidPledgingBase.sol b/contracts/LiquidPledgingBase.sol index bc14bec..c1cea00 100644 --- a/contracts/LiquidPledgingBase.sol +++ b/contracts/LiquidPledgingBase.sol @@ -56,13 +56,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp { // Constructor /////////////// - function LiquidPledgingBase() - PledgeAdmins() - Pledges() public - { - } - - function initialize(address _escapeHatchDestination) onlyInit external { + function initialize(address _escapeHatchDestination) onlyInit public { require(false); // overload the EscapableApp } @@ -71,13 +65,14 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp { /// Multisig) to send the ether held in this contract; if a neutral address /// is required, the WHG Multisig is an option: /// 0x8Ff920020c8AD673661c8117f2855C384758C572 - function initialize(address _vault, address _escapeHatchDestination) onlyInit external { - initialized(); - require(_escapeHatchDestination != 0x0); + function initialize(address _vault, address _escapeHatchDestination) onlyInit public { + super.initialize(_escapeHatchDestination); require(_vault != 0x0); - escapeHatchDestination = _escapeHatchDestination; vault = ILPVault(_vault); + + admins.length = 1; // we reserve the 0 admin + pledges.length = 1; // we reserve the 0 pledge } diff --git a/contracts/LiquidPledgingMock.sol b/contracts/LiquidPledgingMock.sol index 0fbed3a..5052179 100644 --- a/contracts/LiquidPledgingMock.sol +++ b/contracts/LiquidPledgingMock.sol @@ -28,13 +28,14 @@ contract LiquidPledgingMock is LiquidPledging { /// @dev `LiquidPledgingMock` creates a standard `LiquidPledging` /// instance and sets the mocked time to the current blocktime. - function LiquidPledgingMock() LiquidPledging() public { + function initialize(address _vault, address _escapeHatchDestination) onlyInit public { + super.initialize(_vault, _escapeHatchDestination); mock_time = now; } /// @dev `getTime` is a basic getter function for /// the mock_time parameter - function getTime() internal view returns (uint) { + function _getTime() internal view returns (uint) { return mock_time; } diff --git a/contracts/PledgeAdmins.sol b/contracts/PledgeAdmins.sol index 1115fda..86ee7f0 100644 --- a/contracts/PledgeAdmins.sol +++ b/contracts/PledgeAdmins.sol @@ -61,16 +61,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins { PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin - -/////////////// -// Constructor -/////////////// - - function PledgeAdmins() - LiquidPledgingPlugins() public - { - } - //////////////////// // Public functions //////////////////// @@ -258,7 +248,7 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins { plugin) ); - _grantPledgeAdminPermission(msg.sender, idProject); + _grantPledgeAdminPermission(projectAdmin, idProject); if (address(plugin) != 0) { _grantPledgeAdminPermission(address(plugin), idProject); } diff --git a/contracts/Pledges.sol b/contracts/Pledges.sol index a94cc04..fcf727d 100644 --- a/contracts/Pledges.sol +++ b/contracts/Pledges.sol @@ -47,14 +47,6 @@ contract Pledges is AragonApp { /// index number by the hash of that pledge mapping (bytes32 => uint64) hPledge2idx; -/////////////// -// Constructor -/////////////// - - function Pledges() public { - pledges.length = 1; // we reserve the 0 pledge - } - ///////////////////////////// // Public constant functions diff --git a/js/liquidPledgingState.js b/js/liquidPledgingState.js index 1dea022..63c7a1e 100644 --- a/js/liquidPledgingState.js +++ b/js/liquidPledgingState.js @@ -31,9 +31,9 @@ class LiquidPledgingState { } const promises = []; - for (let i = 0; i < res.nDelegates; i += 1) { + for (let i = 1; i <= res.nDelegates; i += 1) { promises.push( - this.$lp.getDelegate(idPledge, i) + this.$lp.getPledgeDelegate(idPledge, i) .then(r => ({ id: r.idDelegate, addr: r.addr, diff --git a/test/AdminPlugins.js b/test/AdminPlugins.js index f814729..14f6712 100644 --- a/test/AdminPlugins.js +++ b/test/AdminPlugins.js @@ -3,17 +3,13 @@ const TestRPC = require("ganache-cli"); const Web3 = require('web3'); const chai = require('chai'); -const liquidpledging = require('../index.js'); -const EternalStorage = require('../js/eternalStorage'); -const PledgeAdmins = require('../js/pledgeAdmins'); const assertFail = require('./helpers/assertFail'); +const contracts = require("../build/contracts.js"); +const LiquidPledgingState = require('../index').LiquidPledgingState; -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 LPVault = liquidpledging.LPVault; const assert = chai.assert; const printState = async (liquidPledgingState) => { @@ -45,9 +41,9 @@ describe('LiquidPledging plugins test', function () { web3 = new Web3('ws://localhost:8546'); accounts = await web3.eth.getAccounts(); - giver1 = accounts[ 1 ]; - adminProject1 = accounts[ 2 ]; - adminDelegate1 = accounts[ 3 ]; + giver1 = accounts[1]; + adminProject1 = accounts[2]; + adminDelegate1 = accounts[3]; }); after((done) => { @@ -55,47 +51,51 @@ describe('LiquidPledging plugins test', function () { done(); }); - it('Should deploy LiquidPledging contract', async function() { - vault = await LPVault.new(web3, accounts[0], accounts[1]); - const storage = await EternalStorage.new(web3, accounts[0], accounts[1]); + it('Should deploy LiquidPledging contract', async function () { + const baseVault = await contracts.LPVault.new(web3); + const baseLP = await contracts.LiquidPledgingMock.new(web3); + lpFactory = await contracts.LPFactory.new(web3, baseVault.$address, baseLP.$address); - liquidPledging = await LiquidPledging.new(web3, storage.$address, vault.$address, accounts[0], accounts[0], {gas: 6700000}) + const r = await lpFactory.newLP(accounts[0], accounts[0]); - await storage.changeOwnership(liquidPledging.$address); - await vault.setLiquidPledging(liquidPledging.$address); + const vaultAddress = r.events.DeployVault.returnValues.vault; + vault = new contracts.LPVault(web3, vaultAddress); + + const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); }); - it('Should create create giver with no plugin', async function() { + 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() { + it('Should fail to create giver with invalid plugin', async function () { await assertFail( liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1, gas: 4000000 }) ); }); - it('Should fail to create delegate with invalid plugin', async function() { + it('Should fail to create delegate with invalid plugin', async function () { await assertFail( - liquidPledging.addDelegate('delegate1', '', 0, liquidPledging.$address, { from: adminDelegate1, gas: 4000000}) + liquidPledging.addDelegate('delegate1', '', 0, liquidPledging.$address, { from: adminDelegate1, gas: 4000000 }) ); }); - it('Should fail to create project with invalid plugin', async function() { + it('Should fail to create project with invalid plugin', async function () { await assertFail( - liquidPledging.addProject('Project1', '', giver1, 0, 0, vault.$address, { from: adminProject1, gas: 4000000}) + liquidPledging.addProject('Project1', '', giver1, 0, 0, vault.$address, { from: adminProject1, gas: 4000000 }) ); }); - it('Should deploy TestSimpleProjectPlugin and add project', async function() { + it('Should deploy TestSimpleProjectPlugin and add project', async function () { // add plugin as valid plugin const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode); - await liquidPledging.addValidPlugin(codeHash); + await liquidPledging.addValidPlugin(codeHash, { $extraGas: 200000 }); // deploy new plugin const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi) @@ -113,8 +113,8 @@ describe('LiquidPledging plugins test', function () { assert.equal(nAdmins, 2); }); - it('Should allow all plugins', async function() { - await liquidPledging.useWhitelist(false); + it('Should allow all plugins', async function () { + await liquidPledging.useWhitelist(false, { $extraGas: 200000 }); await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1 }); diff --git a/test/CancelPledge.js b/test/CancelPledge.js index 8dcd44c..b38f680 100644 --- a/test/CancelPledge.js +++ b/test/CancelPledge.js @@ -3,14 +3,10 @@ const TestRPC = require("ganache-cli"); const Web3 = require('web3'); const chai = require('chai'); -const liquidpledging = require('../index.js'); -const EternalStorage = require('../js/eternalStorage'); -const PledgeAdmins = require('../js/pledgeAdmins'); const assertFail = require('./helpers/assertFail'); +const contracts = require("../build/contracts.js"); +const LiquidPledgingState = require('../index').LiquidPledgingState; -const LiquidPledging = liquidpledging.LiquidPledgingMock; -const LiquidPledgingState = liquidpledging.LiquidPledgingState; -const LPVault = liquidpledging.LPVault; const assert = chai.assert; const printState = async (liquidPledgingState) => { @@ -53,13 +49,17 @@ describe('LiquidPledging cancelPledge normal scenario', function () { }); it('Should deploy LiquidPledging contract', async () => { - vault = await LPVault.new(web3, accounts[0], accounts[1]); - const storage = await EternalStorage.new(web3, accounts[0], accounts[1]); + const baseVault = await contracts.LPVault.new(web3); + const baseLP = await contracts.LiquidPledgingMock.new(web3); + lpFactory = await contracts.LPFactory.new(web3, baseVault.$address, baseLP.$address); - liquidPledging = await LiquidPledging.new(web3, storage.$address, vault.$address, accounts[0], accounts[0], {gas: 6700000}) + const r = await lpFactory.newLP(accounts[0], accounts[0]); - await storage.changeOwnership(liquidPledging.$address); - await vault.setLiquidPledging(liquidPledging.$address); + const vaultAddress = r.events.DeployVault.returnValues.vault; + vault = new contracts.LPVault(web3, vaultAddress); + + const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); }); @@ -79,7 +79,7 @@ describe('LiquidPledging cancelPledge normal scenario', function () { }); it('Should cancel pledge and return to oldPledge', async () => { - await liquidPledging.cancelPledge(2, 1000, { from: adminProject1 }); + await liquidPledging.cancelPledge(2, 1000, { from: adminProject1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); diff --git a/test/DelegationChain.js b/test/DelegationChain.js index 9f9322c..4610668 100644 --- a/test/DelegationChain.js +++ b/test/DelegationChain.js @@ -3,13 +3,9 @@ const TestRPC = require("ganache-cli"); const Web3 = require('web3'); const chai = require('chai'); -const liquidpledging = require('../index.js'); -const EternalStorage = require('../js/eternalStorage'); -const PledgeAdmins = require('../js/pledgeAdmins'); +const contracts = require("../build/contracts.js"); +const LiquidPledgingState = require('../index').LiquidPledgingState; -const LiquidPledging = liquidpledging.LiquidPledgingMock; -const LiquidPledgingState = liquidpledging.LiquidPledgingState; -const LPVault = liquidpledging.LPVault; const assertFail = require('./helpers/assertFail'); const assert = chai.assert; @@ -20,7 +16,7 @@ const printState = async (liquidPledgingState) => { describe('DelegationChain test', function () { this.timeout(0); - + let testrpc; let web3; let accounts; @@ -38,7 +34,8 @@ describe('DelegationChain test', function () { before(async () => { testrpc = TestRPC.server({ ws: true, - gasLimit: 6700000, total_accounts: 10, + gasLimit: 6700000, + total_accounts: 10, }); testrpc.listen(8545, '127.0.0.1'); @@ -55,18 +52,21 @@ describe('DelegationChain test', function () { after((done) => { testrpc.close(); - // console.log(gasUsage); done(); }); it('Should deploy LiquidPledging contract', async () => { - vault = await LPVault.new(web3, accounts[0], accounts[1]); - const storage = await EternalStorage.new(web3, accounts[0], accounts[1]); + const baseVault = await contracts.LPVault.new(web3); + const baseLP = await contracts.LiquidPledgingMock.new(web3); + lpFactory = await contracts.LPFactory.new(web3, baseVault.$address, baseLP.$address); - liquidPledging = await LiquidPledging.new(web3, storage.$address, vault.$address, accounts[0], accounts[0], {gas: 6700000}) + const r = await lpFactory.newLP(accounts[0], accounts[0]); - await storage.changeOwnership(liquidPledging.$address); - await vault.setLiquidPledging(liquidPledging.$address); + const vaultAddress = r.events.DeployVault.returnValues.vault; + vault = new contracts.LPVault(web3, vaultAddress); + + const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); }); @@ -84,11 +84,11 @@ describe('DelegationChain test', function () { }); it('Should allow previous delegate to transfer pledge', async () => { - await liquidPledging.donate(1, 2, {from: giver1, value: 1000}); + await liquidPledging.donate(1, 2, { from: giver1, value: 1000 }); // add delegate2 to chain - await liquidPledging.transfer(2, 2, 1000, 3, {from: delegate1}); + await liquidPledging.transfer(2, 2, 1000, 3, { from: delegate1 }); // delegate 1 transfer pledge back to self, thus undelegating delegate2 - await liquidPledging.transfer(2, 3, 1000, 2, {from: delegate1}); + await liquidPledging.transfer(2, 3, 1000, 2, { from: delegate1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges[2].amount, 1000); @@ -97,11 +97,11 @@ describe('DelegationChain test', function () { it('Should allow any delegate in chain to transfer pledge and undelegate all delegates occurring later in chain', async () => { // add delegate2 to chain - await liquidPledging.transfer(2, 2, 1000, 3, {from: delegate1}); + await liquidPledging.transfer(2, 2, 1000, 3, { from: delegate1, $extraGas: 200000 }); // add delegate3 to chain - await liquidPledging.transfer(3, 3, 1000, 4, {from: delegate2}); + await liquidPledging.transfer(3, 3, 1000, 4, { from: delegate2, $extraGas: 200000 }); // delegate 1 transfer pledge to project1. should also undelegate all delegates occurring later in chain - await liquidPledging.transfer(2, 4, 1000, 5, {from: delegate1}); + await liquidPledging.transfer(2, 4, 1000, 5, { from: delegate1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges[5].amount, 1000); @@ -113,15 +113,15 @@ describe('DelegationChain test', function () { }); it('Should throw if delegate2 is not in delegationChain', async () => { - await assertFail(liquidPledging.transfer(3, 5, 1000, 1, {from: delegate2, gas: 4000000})); + await assertFail(liquidPledging.transfer(3, 5, 1000, 1, { from: delegate2, gas: 4000000 })); }); it('Delegate1 should not be able to transfer to another giver', async () => { - await assertFail(liquidPledging.transfer(2, 5, 1000, 6, {from: delegate1, gas: 4000000})); + await assertFail(liquidPledging.transfer(2, 5, 1000, 6, { from: delegate1, gas: 4000000 })); }); it('Delegate1 should be able to transfer pledge back to owner', async () => { - await liquidPledging.transfer(2, 5, 1000, 1, {from: delegate1}); + await liquidPledging.transfer(2, 5, 1000, 1, { from: delegate1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges[1].amount, 1000); assert.equal(st.pledges[1].delegates.length, 0); @@ -130,11 +130,11 @@ describe('DelegationChain test', function () { it('Delegate1 should be able to change delegation', async () => { // add delegate1 to chain - await liquidPledging.transfer(1, 1, 1000, 2, {from: giver1}); + await liquidPledging.transfer(1, 1, 1000, 2, { from: giver1, $extraGas: 200000 }); // delegate1 add delegate2 to chain - await liquidPledging.transfer(2, 2, 1000, 3, {from: delegate1}); + await liquidPledging.transfer(2, 2, 1000, 3, { from: delegate1, $extraGas: 200000 }); // delegate1 remove delegate2 and add delegate3 to chain - await liquidPledging.transfer(2, 3, 1000, 4, {from: delegate1}); + await liquidPledging.transfer(2, 3, 1000, 4, { from: delegate1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges[1].amount, 0); @@ -146,9 +146,9 @@ describe('DelegationChain test', function () { it('delegate in chain should be able to delegate to previous delegate, thus undelegating themselves and any delegate after the previous delegate', async () => { // add delegate2 to chain - await liquidPledging.transfer(4, 6, 1000, 3, {from: delegate3}); + await liquidPledging.transfer(4, 6, 1000, 3, { from: delegate3 }); // delegate2 transfer back to delegate1, thus undelegating delegate2 & delegate3 - await liquidPledging.transfer(3, 7, 1000, 2, {from: delegate2}); + await liquidPledging.transfer(3, 7, 1000, 2, { from: delegate2, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges[7].amount, 0); @@ -159,13 +159,13 @@ describe('DelegationChain test', function () { it('Should not append delegate on veto delegation', async () => { // propose the delegation - await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1 }); + await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1, $extraGas: 200000 }); const origPledge = await liquidPledging.getPledge(2); assert.equal(origPledge.amount, '0'); // veto the delegation - await liquidPledging.transfer(1, 5, 1000, 2, { from: giver1 }); + await liquidPledging.transfer(1, 5, 1000, 2, { from: giver1, $extraGas: 200000 }); const currentPledge = await liquidPledging.getPledge(2); @@ -175,11 +175,11 @@ describe('DelegationChain test', function () { it('Pledge should have longest commitTime in delegation chain', async () => { // delegate1 add delegate2 to chain - await liquidPledging.transfer(2, 2, 1000, 3, {from: delegate1}); + await liquidPledging.transfer(2, 2, 1000, 3, { from: delegate1, $extraGas: 200000 }); // set the time const now = Math.floor(new Date().getTime() / 1000); - await liquidPledging.setMockedTime(now); + await liquidPledging.setMockedTime(now, { $extraGas: 200000 }); // propose project delegation await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2 }); @@ -190,21 +190,21 @@ describe('DelegationChain test', function () { it('delegation chain should remain the same when owner veto\'s delegation', async () => { // owner veto delegation to project1 - await liquidPledging.transfer(1, 8, 1000, 3, { from: giver1 }); + await liquidPledging.transfer(1, 8, 1000, 3, { from: giver1, $extraGas: 200000 }); const st = await liquidPledgingState.getState(); - assert.equal(st.pledges[ 8 ].amount, 0); - assert.equal(st.pledges[ 3 ].amount, 1000); - assert.equal(st.pledges[ 3 ].delegates.length, 2); - assert.equal(st.pledges[ 3 ].delegates[ 0 ].id, 2); - assert.equal(st.pledges[ 3 ].delegates[ 1 ].id, 3); + assert.equal(st.pledges[8].amount, 0); + assert.equal(st.pledges[3].amount, 1000); + assert.equal(st.pledges[3].delegates.length, 2); + assert.equal(st.pledges[3].delegates[0].id, 2); + assert.equal(st.pledges[3].delegates[1].id, 3); }); it('delegation chain should remain the same upto delegate of reciever when owner veto\'s delegation', async () => { // propose project1 delegation - await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2 }); + await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2, $extraGas: 200000 }); // owner veto delegation to project1 and remove delegate2 - await liquidPledging.transfer(1, 8, 1000, 2, { from: giver1 }); + await liquidPledging.transfer(1, 8, 1000, 2, { from: giver1, $extraGas: 200000 }); const pledge = await liquidPledging.getPledge(2); assert.equal(pledge.amount, 1000); @@ -214,7 +214,7 @@ describe('DelegationChain test', function () { // propose project1 delegation await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1 }); // owner veto delegation to project1 and assign new delgate - await liquidPledging.transfer(1, 9, 1000, 3, { from: giver1 }); + await liquidPledging.transfer(1, 9, 1000, 3, { from: giver1, $extraGas: 200000 }); const pledge = await liquidPledging.getPledge(10); assert.equal(pledge.amount, 1000); diff --git a/test/NormalOperation.js b/test/NormalOperation.js index af1f484..c7e12b8 100644 --- a/test/NormalOperation.js +++ b/test/NormalOperation.js @@ -34,11 +34,14 @@ describe('LiquidPledging test', function () { let adminProject3; let delegate2; let escapeHatchDestination; + let escapeHatchCaller; + let acl; + before(async () => { testrpc = TestRPC.server({ ws: true, gasLimit: 6700000, - total_accounts: 10, + total_accounts: 11, }); testrpc.listen(8545, '127.0.0.1'); @@ -54,6 +57,7 @@ describe('LiquidPledging test', function () { giver2 = accounts[7]; adminProject3 = accounts[8]; escapeHatchDestination = accounts[9]; + escapeHatchCaller = accounts[10]; }); after((done) => { @@ -72,16 +76,20 @@ describe('LiquidPledging test', function () { vault = new contracts.LPVault(web3, vaultAddress); const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; - lp = new contracts.LiquidPledgingMock(web3, lpAddress); - - // setup permissions - // const kernel = new contracts.Kernel(web3, await vault.kernel()); - // const acl = new contracts.ACL(web3, await kernel.acl()); + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); + + // set permissions + const kernel = new contracts.Kernel(web3, await liquidPledging.kernel()); + acl = new contracts.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}); }); it('Should create a giver', async () => { - await liquidPledging.addGiver('Giver1', 'URLGiver1', 86400, 0, { from: giver1 }); + await liquidPledging.addGiver('Giver1', 'URLGiver1', 86400, 0, { from: giver1, gas: 1000000 }); const nAdmins = await liquidPledging.numberOfPledgeAdmins(); assert.equal(nAdmins, 1); const res = await liquidPledging.getPledgeAdmin(1); @@ -92,10 +100,12 @@ describe('LiquidPledging test', function () { assert.equal(res[4], 86400); }); it('Should make a donation', async () => { - await liquidPledging.donate(1, 1, { from: giver1, value: utils.toWei('1') }); + const r = await liquidPledging.donate(1, 1, { from: giver1, value: utils.toWei('1'), gas: 1000000 }); const nPledges = await liquidPledging.numberOfPledges(); assert.equal(nPledges, 1); - await liquidPledging.getPledge(1); + const p = await liquidPledging.getPledge(1); + assert.equal(p.amount, utils.toWei('1')); + assert.equal(p.owner, 1); }); it('Should create a delegate', async () => { await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 }); @@ -109,7 +119,7 @@ describe('LiquidPledging test', function () { assert.equal(res[4], 0); }); 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, $extraGas: 100000 }); const nPledges = await liquidPledging.numberOfPledges(); assert.equal(nPledges, 2); const res1 = await liquidPledging.getPledge(1); @@ -118,7 +128,7 @@ describe('LiquidPledging test', function () { assert.equal(res2[0], utils.toWei('0.5')); assert.equal(res2[1], 1); // One delegate - const d = await liquidPledging.getDelegate(2, 0); + const d = await liquidPledging.getPledgeDelegate(2, 1); assert.equal(d[0], 2); assert.equal(d[1], delegate1); assert.equal(d[2], 'Delegate1'); @@ -180,7 +190,7 @@ describe('LiquidPledging test', function () { }); it('After the time, the project1 should be able to spend part of it', async () => { const n = Math.floor(new Date().getTime() / 1000); - await liquidPledging.setMockedTime(n + 86401); + await liquidPledging.setMockedTime(n + 86401, {$extraGas: 100000}); await liquidPledging.withdraw(3, utils.toWei('0.05'), { from: adminProject1 }); const nPledges = await liquidPledging.numberOfPledges(); assert.equal(nPledges, 6); @@ -204,7 +214,7 @@ describe('LiquidPledging test', function () { it('Should collect the Ether', async () => { const initialBalance = await web3.eth.getBalance(adminProject1); - await vault.confirmPayment(0); + await vault.confirmPayment(0, {$extraGas: 200000}); const finalBalance = await web3.eth.getBalance(adminProject1); const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance))); @@ -223,7 +233,7 @@ describe('LiquidPledging test', function () { assert.equal(res7[6], 2); // Peinding paid Paid }); it('Admin of the project1 should be able to cancel project1', async () => { - await liquidPledging.cancelProject(3, { from: adminProject1 }); + await liquidPledging.cancelProject(3, { from: adminProject1, $extraGas: 100000 }); const st = await liquidPledgingState.getState(liquidPledging); assert.equal(st.admins[3].canceled, true); }); @@ -236,7 +246,7 @@ describe('LiquidPledging test', function () { ); }); it('Delegate should send part of this ETH to project2', async () => { - await liquidPledging.transfer(2, 5, utils.toWei('0.03'), 4, {from: delegate1}); + await liquidPledging.transfer(2, 5, utils.toWei('0.03'), 4, {from: delegate1, $extraGas: 100000}); const st = await liquidPledgingState.getState(liquidPledging); assert.equal(st.pledges.length, 9); assert.equal(utils.fromWei(st.pledges[8].amount), 0.03); @@ -246,7 +256,7 @@ describe('LiquidPledging test', function () { assert.equal(st.pledges[8].intendedProject, 4); }); it('Giver should be able to send the remaining to project2', async () => { - await liquidPledging.transfer(1, 5, utils.toWei('0.02'), 4, { from: giver1 }); + await liquidPledging.transfer(1, 5, utils.toWei('0.02'), 4, { from: giver1, $extraGas: 100000 }); const st = await liquidPledgingState.getState(liquidPledging); assert.equal(st.pledges.length, 9); assert.equal(utils.fromWei(st.pledges[5].amount), 0); @@ -259,14 +269,14 @@ describe('LiquidPledging test', function () { assert.equal(nAdmins, 6); }); it('Project 2 delegate in delegate2', async () => { - await liquidPledging.transfer(4, 4, utils.toWei('0.02'), 6, { from: adminProject2 }); - const st = await liquidPledgingState.getState(liquidPledging); + await liquidPledging.transfer(4, 4, utils.toWei('0.02'), 6, { from: adminProject2, $extraGas: 200000 }); + const st = await liquidPledgingState.getState(); assert.equal(st.pledges.length, 10); assert.equal(utils.fromWei(st.pledges[9].amount), 0.02); assert.equal(utils.fromWei(st.pledges[4].amount), 0.1); }); 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, $extraGas: 100000 }); const st = await liquidPledgingState.getState(liquidPledging); assert.equal(st.pledges.length, 11); assert.equal(utils.fromWei(st.pledges[9].amount), 0.01); @@ -274,8 +284,8 @@ describe('LiquidPledging test', function () { }); it('project2a authorize to spend a litle', async () => { const n = Math.floor(new Date().getTime() / 1000); - await liquidPledging.setMockedTime(n + (86401 * 3)); - await liquidPledging.withdraw(10, utils.toWei('0.005'), { from: adminProject2a }); + await liquidPledging.setMockedTime(n + (86401 * 3), {$extraGas: 200000}); + await liquidPledging.withdraw(10, utils.toWei('0.005'), { from: adminProject2a, $extraGas: 200000 }); const st = await liquidPledgingState.getState(liquidPledging); assert.equal(st.pledges.length, 13); assert.equal(utils.fromWei(st.pledges[10].amount), 0); @@ -283,7 +293,7 @@ describe('LiquidPledging test', function () { assert.equal(utils.fromWei(st.pledges[12].amount), 0.005); }); it('project2 is canceled', async () => { - await liquidPledging.cancelProject(4, { from: adminProject2 }); + await liquidPledging.cancelProject(4, { from: adminProject2, $extraGas: 100000 }); }); it('Should not be able to withdraw it', async () => { await assertFail( @@ -313,10 +323,10 @@ describe('LiquidPledging test', function () { return '0x' + utils.padLeft(utils.toHex(p.amount).substring(2), 48) + utils.padLeft(utils.toHex(p.id).substring(2), 16); }); - await liquidPledging.mWithdraw(encodedPledges, { from: giver1 }); + await liquidPledging.mWithdraw(encodedPledges, { from: giver1, $extraGas: 200000 }); const initialBalance = await web3.eth.getBalance(giver1); - await vault.multiConfirm([2, 3, 4, 5, 6]); + await vault.multiConfirm([2, 3, 4, 5, 6], {$extraGas: 200000}); const finalBalance = await web3.eth.getBalance(giver1); const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance))); @@ -326,7 +336,7 @@ describe('LiquidPledging test', function () { it('Should make a donation and create giver', async () => { const oldNPledges = await liquidPledging.numberOfPledges(); 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'), $extraGas: 200000 }); const nPledges = await liquidPledging.numberOfPledges(); assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 1); const nAdmins = await liquidPledging.numberOfPledgeAdmins(); @@ -348,10 +358,10 @@ describe('LiquidPledging test', function () { it('should throw if projectLevel > 20', async () => { let nAdmins = await liquidPledging.numberOfPledgeAdmins(); - await liquidPledging.addProject('ProjectLevel0', '', adminProject1, 0, 86400, 0, { from: adminProject1 }); + await liquidPledging.addProject('ProjectLevel0', '', adminProject1, 0, 86400, 0, { from: adminProject1, $extraGas: 100000 }); for (let i = 2; i <= 20; i++) { - await liquidPledging.addProject(`ProjectLevel${i}`, '', adminProject1, ++nAdmins, 86400, 0, { from: adminProject1 }); + await liquidPledging.addProject(`ProjectLevel${i}`, '', adminProject1, ++nAdmins, 86400, 0, { from: adminProject1, $extraGas: 100000 }); } assertFail( diff --git a/test/NormalizePledge.js b/test/NormalizePledge.js index afe59c2..6147cfb 100644 --- a/test/NormalizePledge.js +++ b/test/NormalizePledge.js @@ -3,13 +3,9 @@ const TestRPC = require("ganache-cli"); const Web3 = require('web3'); const chai = require('chai'); -const liquidpledging = require('../index.js'); -const EternalStorage = require('../js/eternalStorage'); -const PledgeAdmins = require('../js/pledgeAdmins'); +const contracts = require("../build/contracts.js"); +const LiquidPledgingState = require('../index').LiquidPledgingState; -const LiquidPledging = liquidpledging.LiquidPledgingMock; -const LiquidPledgingState = liquidpledging.LiquidPledgingState; -const LPVault = liquidpledging.LPVault; const assert = chai.assert; const printState = async (liquidPledgingState) => { @@ -19,7 +15,7 @@ const printState = async (liquidPledgingState) => { describe('NormalizePledge test', function () { this.timeout(0); - + let testrpc; let web3; let accounts; @@ -58,13 +54,17 @@ describe('NormalizePledge test', function () { }); it('Should deploy LiquidPledging contract', async () => { - vault = await LPVault.new(web3, accounts[0], accounts[1]); - const storage = await EternalStorage.new(web3, accounts[0], accounts[1]); + const baseVault = await contracts.LPVault.new(web3); + const baseLP = await contracts.LiquidPledgingMock.new(web3); + lpFactory = await contracts.LPFactory.new(web3, baseVault.$address, baseLP.$address); - liquidPledging = await LiquidPledging.new(web3, storage.$address, vault.$address, accounts[0], accounts[0], {gas: 6700000}) + const r = await lpFactory.newLP(accounts[0], accounts[0]); - await storage.changeOwnership(liquidPledging.$address); - await vault.setLiquidPledging(liquidPledging.$address); + const vaultAddress = r.events.DeployVault.returnValues.vault; + vault = new contracts.LPVault(web3, vaultAddress); + + const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); }); @@ -83,25 +83,25 @@ describe('NormalizePledge test', function () { it('Should commit pledges if commitTime has passed', async () => { // commitTime 259200 - await liquidPledging.donate(1, 2, {from: giver1, value: 1000}); + await liquidPledging.donate(1, 2, { from: giver1, value: 1000 }); // commitTime 86400 - await liquidPledging.donate(1, 3, {from: giver1, value: 1000}); + await liquidPledging.donate(1, 3, { from: giver1, value: 1000 }); // commitTime 0 - await liquidPledging.donate(6, 3, {from: giver2, value: 1000}); + await liquidPledging.donate(6, 3, { from: giver2, value: 1000 }); // set the time const now = Math.floor(new Date().getTime() / 1000); - await liquidPledging.setMockedTime(now); + await liquidPledging.setMockedTime(now, { $extraGas: 200000 }); // delegate to project - await liquidPledging.transfer(2, 2, 1000, 4, {from: delegate1}); - await liquidPledging.transfer(3, 3, 1000, 4, {from: delegate2}); - await liquidPledging.transfer(3, 5, 1000, 4, {from: delegate2}); + await liquidPledging.transfer(2, 2, 1000, 4, { from: delegate1 }); + await liquidPledging.transfer(3, 3, 1000, 4, { from: delegate2 }); + await liquidPledging.transfer(3, 5, 1000, 4, { from: delegate2 }); // advance the time - await liquidPledging.setMockedTime( now + 100000 ); + await liquidPledging.setMockedTime(now + 100000, { $extraGas: 200000 }); - await liquidPledging.mNormalizePledge([6, 7, 8]); + await liquidPledging.mNormalizePledge([6, 7, 8], { $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges.length, 11); @@ -115,13 +115,13 @@ describe('NormalizePledge test', function () { }); it('Should transfer pledge to oldestPledgeNotCanceled', async () => { - await liquidPledging.transfer(4, 10, 1000, 5, {from: adminProject1}); + await liquidPledging.transfer(4, 10, 1000, 5, { from: adminProject1, $extraGas: 200000 }); // cancel projects - await liquidPledging.cancelProject(4, {from: adminProject1}); - await liquidPledging.cancelProject(5, {from: adminProject2}); + await liquidPledging.cancelProject(4, { from: adminProject1, $extraGas: 200000 }); + await liquidPledging.cancelProject(5, { from: adminProject2, $extraGas: 200000 }); - await liquidPledging.mNormalizePledge([9, 11]); + await liquidPledging.mNormalizePledge([9, 11], { $extraGas: 200000 }); const st = await liquidPledgingState.getState(); assert.equal(st.pledges.length, 12); diff --git a/test/Vault.js b/test/Vault.js index dd7e210..ddaad54 100644 --- a/test/Vault.js +++ b/test/Vault.js @@ -3,14 +3,10 @@ const TestRPC = require("ganache-cli"); const Web3 = require('web3'); const chai = require('chai'); -const liquidpledging = require('../index.js'); -const EternalStorage = require('../js/eternalStorage'); -const PledgeAdmins = require('../js/pledgeAdmins'); const assertFail = require('./helpers/assertFail'); +const contracts = require("../build/contracts.js"); -const LiquidPledging = liquidpledging.LiquidPledgingMock; -const LiquidPledgingState = liquidpledging.LiquidPledgingState; -const LPVault = liquidpledging.LPVault; +const LiquidPledgingState = require('../index').LiquidPledgingState; const assert = chai.assert; describe('Vault test', function () { @@ -27,6 +23,7 @@ describe('Vault test', function () { let escapeHatchDestination; let giver1; let adminProject1; + let restrictedPaymentsConfirmer; before(async () => { testrpc = TestRPC.server({ @@ -44,6 +41,7 @@ describe('Vault test', function () { vaultOwner = accounts[ 3 ]; escapeHatchDestination = accounts[ 4 ]; escapeHatchCaller = accounts[ 5 ]; + restrictedPaymentsConfirmer = accounts[ 6 ]; }); after((done) => { @@ -52,25 +50,37 @@ describe('Vault test', function () { }); it('Should deploy Vault contract', async function () { - vault = await LPVault.new(web3, escapeHatchCaller, escapeHatchDestination, {from: vaultOwner}); - const storage = await EternalStorage.new(web3, accounts[0], accounts[1]); + const baseVault = await contracts.LPVault.new(web3); + const baseLP = await contracts.LiquidPledgingMock.new(web3); + lpFactory = await contracts.LPFactory.new(web3, baseVault.$address, baseLP.$address); - liquidPledging = await LiquidPledging.new(web3, storage.$address, vault.$address, accounts[0], accounts[0], {gas: 6700000}) + const r = await lpFactory.newLP(accounts[0], escapeHatchDestination); - await storage.changeOwnership(liquidPledging.$address); - await vault.setLiquidPledging(liquidPledging.$address, {from: vaultOwner}); + const vaultAddress = r.events.DeployVault.returnValues.vault; + vault = new contracts.LPVault(web3, vaultAddress); + + const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging; + liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress); liquidPledgingState = new LiquidPledgingState(liquidPledging); - await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: giver1 }); - await liquidPledging.addProject('Project1', '', adminProject1, 0, 0, '0x0', { from: adminProject1 }); + // set permissions + const kernel = new contracts.Kernel(web3, await liquidPledging.kernel()); + acl = new contracts.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}); + + await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: giver1, $extraGas: 100000 }); + await liquidPledging.addProject('Project1', '', adminProject1, 0, 0, '0x0', { from: adminProject1, $extraGas: 100000 }); const nAdmins = await liquidPledging.numberOfPledgeAdmins(); assert.equal(nAdmins, 2); }); it('Should hold funds from liquidPledging', async function () { - await liquidPledging.donate(0, 2, { from: giver1, value: 10000 }); + await liquidPledging.donate(0, 2, { from: giver1, value: 10000, $extraGas: 100000 }); const balance = await web3.eth.getBalance(vault.$address); assert.equal(10000, balance); @@ -87,7 +97,7 @@ describe('Vault test', function () { it('escapeFunds should send funds to escapeHatchDestination', async function () { const preBalance = await web3.eth.getBalance(escapeHatchDestination); - await vault.escapeFunds(0x0, 1000, { from: vaultOwner }); + await vault.escapeFunds(0x0, 1000, { from: escapeHatchCaller, $extraGas: 200000 }); const vaultBalance = await web3.eth.getBalance(vault.$address); assert.equal(9000, vaultBalance); @@ -96,6 +106,19 @@ describe('Vault test', function () { const postBalance = await web3.eth.getBalance(escapeHatchDestination); assert.equal(expected, postBalance); + + await web3.eth.sendTransaction({from: escapeHatchCaller, to: vault.$address, value: '1000', gas: 21000}); + }); + + it('should restrict confirm payment to payments under specified amount', async function () { + await liquidPledging.withdraw(2, 300, {from: adminProject1, $extraGas: 200000}); + await liquidPledging.withdraw(2, 700, {from: adminProject1, $extraGas: 200000}); + + // set permission for 2nd param (p.amount) <= 300 + await acl.grantPermissionP(restrictedPaymentsConfirmer, vault.$address, await vault.CONFIRM_PAYMENT_ROLE(), ["0x010600000000000000000000000000000000000000000000000000000000012c"], {$extraGas: 200000}); + + assertFail(vault.confirmPayment(1, { from: restrictedPaymentsConfirmer, gas: 4000000 })); + await vault.confirmPayment(0, { from: restrictedPaymentsConfirmer, $extraGas: 200000 }); }); });