all tests passing
This commit is contained in:
parent
369e6ae6cd
commit
ece3355c67
|
@ -29,7 +29,7 @@ import "@aragon/os/contracts/apps/AragonApp.sol";
|
||||||
/// not blacklisted
|
/// not blacklisted
|
||||||
contract EscapableApp is AragonApp {
|
contract EscapableApp is AragonApp {
|
||||||
// warning whoever has this role can move all funds to the `escapeHatchDestination`
|
// 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;
|
address public escapeHatchDestination;
|
||||||
mapping (address=>bool) private escapeBlacklist; // Token contract addresses
|
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
|
/// Multisig) to send the ether held in this contract; if a neutral address
|
||||||
/// is required, the WHG Multisig is an option:
|
/// is required, the WHG Multisig is an option:
|
||||||
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
||||||
function initialize(address _escapeHatchDestination) onlyInit external {
|
function initialize(address _escapeHatchDestination) onlyInit public {
|
||||||
initialized();
|
initialized();
|
||||||
require(_escapeHatchDestination != 0x0);
|
require(_escapeHatchDestination != 0x0);
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,10 @@ contract ILiquidPledging {
|
||||||
/// contract that holds funds for the liquid pledging system.
|
/// contract that holds funds for the liquid pledging system.
|
||||||
contract LPVault is EscapableApp {
|
contract LPVault is EscapableApp {
|
||||||
|
|
||||||
bytes32 constant public CONFIRM_PAYMENT_ROLE = bytes32(1);
|
bytes32 constant public CONFIRM_PAYMENT_ROLE = keccak256("CONFIRM_PAYMENT_ROLE");
|
||||||
bytes32 constant public CANCEL_PAYMENT_ROLE = bytes32(2);
|
bytes32 constant public CANCEL_PAYMENT_ROLE = keccak256("CANCEL_PAYMENT_ROLE");
|
||||||
bytes32 constant public AUTHORIZE_PAYMENT_ROLE = bytes32(3);
|
bytes32 constant public AUTHORIZE_PAYMENT_ROLE = keccak256("AUTHORIZE_PAYMENT_ROLE");
|
||||||
bytes32 constant public SET_AUTOPAY_ROLE = bytes32(4);
|
bytes32 constant public SET_AUTOPAY_ROLE = keccak256("SET_AUTOPAY_ROLE");
|
||||||
|
|
||||||
event AutoPaySet(bool autoPay);
|
event AutoPaySet(bool autoPay);
|
||||||
event EscapeFundsCalled(address token, uint amount);
|
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
|
require(false); // overload the EscapableApp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +95,9 @@ contract LPVault is EscapableApp {
|
||||||
/// is required, the WHG Multisig is an option:
|
/// is required, the WHG Multisig is an option:
|
||||||
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
||||||
function initialize(address _liquidPledging, address _escapeHatchDestination) onlyInit external {
|
function initialize(address _liquidPledging, address _escapeHatchDestination) onlyInit external {
|
||||||
initialized();
|
super.initialize(_escapeHatchDestination);
|
||||||
require(_escapeHatchDestination != 0x0);
|
|
||||||
require(_liquidPledging != 0x0);
|
|
||||||
|
|
||||||
escapeHatchDestination = _escapeHatchDestination;
|
require(_liquidPledging != 0x0);
|
||||||
liquidPledging = ILiquidPledging(_liquidPledging);
|
liquidPledging = ILiquidPledging(_liquidPledging);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,19 +28,6 @@ import "./LiquidPledgingBase.sol";
|
||||||
contract LiquidPledging is LiquidPledgingBase {
|
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;
|
/// @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
|
/// 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
|
/// 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 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:
|
/// @param idReceiver The Admin receiving the donation; can be any Admin:
|
||||||
/// the Giver themselves, another Giver, a Delegate or a Project
|
/// 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
|
public payable
|
||||||
{
|
{
|
||||||
// TODO: maybe need a separate role here to allow giver creation
|
// 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);
|
PledgeAdmins.PledgeAdmin storage sender = _findAdmin(idGiver);
|
||||||
// _checkAdminOwner(sender);
|
|
||||||
require(sender.adminType == PledgeAdminType.Giver);
|
require(sender.adminType == PledgeAdminType.Giver);
|
||||||
|
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(idGiver))));
|
||||||
|
|
||||||
uint amount = msg.value;
|
uint amount = msg.value;
|
||||||
require(amount > 0);
|
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(
|
uint64 idPledge = _findOrCreatePledge(
|
||||||
idGiver,
|
idGiver,
|
||||||
|
@ -223,14 +213,14 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// intendedProject
|
/// intendedProject
|
||||||
/// @param idPledge Id of the pledge that is to be redeemed into ether
|
/// @param idPledge Id of the pledge that is to be redeemed into ether
|
||||||
/// @param amount Quantity of ether (in wei) to be authorized
|
/// @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
|
idPledge = normalizePledge(idPledge); // Updates pledge info
|
||||||
|
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||||
require(p.pledgeState == PledgeState.Pledged);
|
require(p.pledgeState == PledgeState.Pledged);
|
||||||
|
|
||||||
PledgeAdmins.PledgeAdmin storage owner = _findAdmin(p.owner);
|
PledgeAdmins.PledgeAdmin storage owner = _findAdmin(p.owner);
|
||||||
// _checkAdminOwner(owner);
|
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
||||||
|
|
||||||
uint64 idNewPledge = _findOrCreatePledge(
|
uint64 idNewPledge = _findOrCreatePledge(
|
||||||
p.owner,
|
p.owner,
|
||||||
|
@ -307,12 +297,13 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// @param idPledge Id of the pledge that is to be canceled
|
/// @param idPledge Id of the pledge that is to be canceled
|
||||||
/// @param amount Quantity of ether (in wei) to be transfered to the
|
/// @param amount Quantity of ether (in wei) to be transfered to the
|
||||||
/// `oldPledge`
|
/// `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);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledges.Pledge storage p = _findPledge(idPledge);
|
Pledges.Pledge storage p = _findPledge(idPledge);
|
||||||
require(p.oldPledge != 0);
|
require(p.oldPledge != 0);
|
||||||
|
|
||||||
|
require(canPerform(msg.sender, PLEDGE_ADMIN_ROLE, arr(uint(p.owner))));
|
||||||
// PledgeAdmins.PledgeAdmin storage a = _findAdmin(p.owner);
|
// PledgeAdmins.PledgeAdmin storage a = _findAdmin(p.owner);
|
||||||
// _checkAdminOwner(a);
|
// _checkAdminOwner(a);
|
||||||
|
|
||||||
|
@ -811,6 +802,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTime() public view returns(uint) {
|
||||||
|
return _getTime();
|
||||||
|
}
|
||||||
|
|
||||||
// Event Declarations
|
// Event Declarations
|
||||||
event Transfer(uint indexed from, uint indexed to, uint amount);
|
event Transfer(uint indexed from, uint indexed to, uint amount);
|
||||||
event CancelProject(uint indexed idProject);
|
event CancelProject(uint indexed idProject);
|
||||||
|
|
|
@ -56,13 +56,7 @@ contract LiquidPledgingBase is PledgeAdmins, Pledges, EscapableApp {
|
||||||
// Constructor
|
// Constructor
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
function LiquidPledgingBase()
|
function initialize(address _escapeHatchDestination) onlyInit public {
|
||||||
PledgeAdmins()
|
|
||||||
Pledges() public
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
function initialize(address _escapeHatchDestination) onlyInit external {
|
|
||||||
require(false); // overload the EscapableApp
|
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
|
/// Multisig) to send the ether held in this contract; if a neutral address
|
||||||
/// is required, the WHG Multisig is an option:
|
/// is required, the WHG Multisig is an option:
|
||||||
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
/// 0x8Ff920020c8AD673661c8117f2855C384758C572
|
||||||
function initialize(address _vault, address _escapeHatchDestination) onlyInit external {
|
function initialize(address _vault, address _escapeHatchDestination) onlyInit public {
|
||||||
initialized();
|
super.initialize(_escapeHatchDestination);
|
||||||
require(_escapeHatchDestination != 0x0);
|
|
||||||
require(_vault != 0x0);
|
require(_vault != 0x0);
|
||||||
|
|
||||||
escapeHatchDestination = _escapeHatchDestination;
|
|
||||||
vault = ILPVault(_vault);
|
vault = ILPVault(_vault);
|
||||||
|
|
||||||
|
admins.length = 1; // we reserve the 0 admin
|
||||||
|
pledges.length = 1; // we reserve the 0 pledge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,14 @@ contract LiquidPledgingMock is LiquidPledging {
|
||||||
|
|
||||||
/// @dev `LiquidPledgingMock` creates a standard `LiquidPledging`
|
/// @dev `LiquidPledgingMock` creates a standard `LiquidPledging`
|
||||||
/// instance and sets the mocked time to the current blocktime.
|
/// 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;
|
mock_time = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev `getTime` is a basic getter function for
|
/// @dev `getTime` is a basic getter function for
|
||||||
/// the mock_time parameter
|
/// the mock_time parameter
|
||||||
function getTime() internal view returns (uint) {
|
function _getTime() internal view returns (uint) {
|
||||||
return mock_time;
|
return mock_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,16 +61,6 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
|
|
||||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
|
||||||
// Constructor
|
|
||||||
///////////////
|
|
||||||
|
|
||||||
function PledgeAdmins()
|
|
||||||
LiquidPledgingPlugins() public
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// Public functions
|
// Public functions
|
||||||
////////////////////
|
////////////////////
|
||||||
|
@ -258,7 +248,7 @@ contract PledgeAdmins is AragonApp, LiquidPledgingPlugins {
|
||||||
plugin)
|
plugin)
|
||||||
);
|
);
|
||||||
|
|
||||||
_grantPledgeAdminPermission(msg.sender, idProject);
|
_grantPledgeAdminPermission(projectAdmin, idProject);
|
||||||
if (address(plugin) != 0) {
|
if (address(plugin) != 0) {
|
||||||
_grantPledgeAdminPermission(address(plugin), idProject);
|
_grantPledgeAdminPermission(address(plugin), idProject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,6 @@ contract Pledges is AragonApp {
|
||||||
/// index number by the hash of that pledge
|
/// index number by the hash of that pledge
|
||||||
mapping (bytes32 => uint64) hPledge2idx;
|
mapping (bytes32 => uint64) hPledge2idx;
|
||||||
|
|
||||||
///////////////
|
|
||||||
// Constructor
|
|
||||||
///////////////
|
|
||||||
|
|
||||||
function Pledges() public {
|
|
||||||
pledges.length = 1; // we reserve the 0 pledge
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Public constant functions
|
// Public constant functions
|
||||||
|
|
|
@ -31,9 +31,9 @@ class LiquidPledgingState {
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (let i = 0; i < res.nDelegates; i += 1) {
|
for (let i = 1; i <= res.nDelegates; i += 1) {
|
||||||
promises.push(
|
promises.push(
|
||||||
this.$lp.getDelegate(idPledge, i)
|
this.$lp.getPledgeDelegate(idPledge, i)
|
||||||
.then(r => ({
|
.then(r => ({
|
||||||
id: r.idDelegate,
|
id: r.idDelegate,
|
||||||
addr: r.addr,
|
addr: r.addr,
|
||||||
|
|
|
@ -3,17 +3,13 @@
|
||||||
const TestRPC = require("ganache-cli");
|
const TestRPC = require("ganache-cli");
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const chai = require('chai');
|
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 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 simpleProjectPluginFactoryAbi = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginFactoryAbi;
|
||||||
const simpleProjectPluginFactoryByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginFactoryByteCode;
|
const simpleProjectPluginFactoryByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginFactoryByteCode;
|
||||||
const simpleProjectPluginRuntimeByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginRuntimeByteCode;
|
const simpleProjectPluginRuntimeByteCode = require('../build/TestSimpleProjectPluginFactory.sol').TestSimpleProjectPluginRuntimeByteCode;
|
||||||
const LPVault = liquidpledging.LPVault;
|
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
|
|
||||||
const printState = async (liquidPledgingState) => {
|
const printState = async (liquidPledgingState) => {
|
||||||
|
@ -45,9 +41,9 @@ describe('LiquidPledging plugins test', function () {
|
||||||
|
|
||||||
web3 = new Web3('ws://localhost:8546');
|
web3 = new Web3('ws://localhost:8546');
|
||||||
accounts = await web3.eth.getAccounts();
|
accounts = await web3.eth.getAccounts();
|
||||||
giver1 = accounts[ 1 ];
|
giver1 = accounts[1];
|
||||||
adminProject1 = accounts[ 2 ];
|
adminProject1 = accounts[2];
|
||||||
adminDelegate1 = accounts[ 3 ];
|
adminDelegate1 = accounts[3];
|
||||||
});
|
});
|
||||||
|
|
||||||
after((done) => {
|
after((done) => {
|
||||||
|
@ -55,47 +51,51 @@ describe('LiquidPledging plugins test', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should deploy LiquidPledging contract', async function() {
|
it('Should deploy LiquidPledging contract', async function () {
|
||||||
vault = await LPVault.new(web3, accounts[0], accounts[1]);
|
const baseVault = await contracts.LPVault.new(web3);
|
||||||
const storage = await EternalStorage.new(web3, accounts[0], accounts[1]);
|
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);
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
||||||
await vault.setLiquidPledging(liquidPledging.$address);
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
|
liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress);
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
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 });
|
await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: adminProject1 });
|
||||||
|
|
||||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||||
assert.equal(nAdmins, 1);
|
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(
|
await assertFail(
|
||||||
liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1, gas: 4000000 })
|
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(
|
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(
|
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
|
// add plugin as valid plugin
|
||||||
const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode);
|
const codeHash = web3.utils.soliditySha3(simpleProjectPluginRuntimeByteCode);
|
||||||
await liquidPledging.addValidPlugin(codeHash);
|
await liquidPledging.addValidPlugin(codeHash, { $extraGas: 200000 });
|
||||||
|
|
||||||
// deploy new plugin
|
// deploy new plugin
|
||||||
const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi)
|
const factoryContract = await new web3.eth.Contract(simpleProjectPluginFactoryAbi)
|
||||||
|
@ -113,8 +113,8 @@ describe('LiquidPledging plugins test', function () {
|
||||||
assert.equal(nAdmins, 2);
|
assert.equal(nAdmins, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should allow all plugins', async function() {
|
it('Should allow all plugins', async function () {
|
||||||
await liquidPledging.useWhitelist(false);
|
await liquidPledging.useWhitelist(false, { $extraGas: 200000 });
|
||||||
|
|
||||||
await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1 });
|
await liquidPledging.addGiver('Giver2', '', 0, vault.$address, { from: giver1 });
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,10 @@
|
||||||
const TestRPC = require("ganache-cli");
|
const TestRPC = require("ganache-cli");
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const chai = require('chai');
|
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 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 assert = chai.assert;
|
||||||
|
|
||||||
const printState = async (liquidPledgingState) => {
|
const printState = async (liquidPledgingState) => {
|
||||||
|
@ -53,13 +49,17 @@ describe('LiquidPledging cancelPledge normal scenario', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should deploy LiquidPledging contract', async () => {
|
it('Should deploy LiquidPledging contract', async () => {
|
||||||
vault = await LPVault.new(web3, accounts[0], accounts[1]);
|
const baseVault = await contracts.LPVault.new(web3);
|
||||||
const storage = await EternalStorage.new(web3, accounts[0], accounts[1]);
|
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);
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
||||||
await vault.setLiquidPledging(liquidPledging.$address);
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
|
liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress);
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ describe('LiquidPledging cancelPledge normal scenario', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should cancel pledge and return to oldPledge', async () => {
|
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();
|
const st = await liquidPledgingState.getState();
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,9 @@
|
||||||
const TestRPC = require("ganache-cli");
|
const TestRPC = require("ganache-cli");
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const liquidpledging = require('../index.js');
|
const contracts = require("../build/contracts.js");
|
||||||
const EternalStorage = require('../js/eternalStorage');
|
const LiquidPledgingState = require('../index').LiquidPledgingState;
|
||||||
const PledgeAdmins = require('../js/pledgeAdmins');
|
|
||||||
|
|
||||||
const LiquidPledging = liquidpledging.LiquidPledgingMock;
|
|
||||||
const LiquidPledgingState = liquidpledging.LiquidPledgingState;
|
|
||||||
const LPVault = liquidpledging.LPVault;
|
|
||||||
const assertFail = require('./helpers/assertFail');
|
const assertFail = require('./helpers/assertFail');
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
|
|
||||||
|
@ -38,7 +34,8 @@ describe('DelegationChain test', function () {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
testrpc = TestRPC.server({
|
testrpc = TestRPC.server({
|
||||||
ws: true,
|
ws: true,
|
||||||
gasLimit: 6700000, total_accounts: 10,
|
gasLimit: 6700000,
|
||||||
|
total_accounts: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
testrpc.listen(8545, '127.0.0.1');
|
testrpc.listen(8545, '127.0.0.1');
|
||||||
|
@ -55,18 +52,21 @@ describe('DelegationChain test', function () {
|
||||||
|
|
||||||
after((done) => {
|
after((done) => {
|
||||||
testrpc.close();
|
testrpc.close();
|
||||||
// console.log(gasUsage);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should deploy LiquidPledging contract', async () => {
|
it('Should deploy LiquidPledging contract', async () => {
|
||||||
vault = await LPVault.new(web3, accounts[0], accounts[1]);
|
const baseVault = await contracts.LPVault.new(web3);
|
||||||
const storage = await EternalStorage.new(web3, accounts[0], accounts[1]);
|
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);
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
||||||
await vault.setLiquidPledging(liquidPledging.$address);
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
|
liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress);
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
||||||
});
|
});
|
||||||
|
@ -84,11 +84,11 @@ describe('DelegationChain test', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should allow previous delegate to transfer pledge', async () => {
|
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
|
// 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
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[2].amount, 1000);
|
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 () => {
|
it('Should allow any delegate in chain to transfer pledge and undelegate all delegates occurring later in chain', async () => {
|
||||||
// add delegate2 to chain
|
// 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
|
// 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
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[5].amount, 1000);
|
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 () => {
|
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 () => {
|
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 () => {
|
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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[1].amount, 1000);
|
assert.equal(st.pledges[1].amount, 1000);
|
||||||
assert.equal(st.pledges[1].delegates.length, 0);
|
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 () => {
|
it('Delegate1 should be able to change delegation', async () => {
|
||||||
// add delegate1 to chain
|
// 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
|
// 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
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[1].amount, 0);
|
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 () => {
|
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
|
// 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
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[7].amount, 0);
|
assert.equal(st.pledges[7].amount, 0);
|
||||||
|
@ -159,13 +159,13 @@ describe('DelegationChain test', function () {
|
||||||
|
|
||||||
it('Should not append delegate on veto delegation', async () => {
|
it('Should not append delegate on veto delegation', async () => {
|
||||||
// propose the delegation
|
// 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);
|
const origPledge = await liquidPledging.getPledge(2);
|
||||||
assert.equal(origPledge.amount, '0');
|
assert.equal(origPledge.amount, '0');
|
||||||
|
|
||||||
// veto the delegation
|
// 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);
|
const currentPledge = await liquidPledging.getPledge(2);
|
||||||
|
|
||||||
|
@ -175,11 +175,11 @@ describe('DelegationChain test', function () {
|
||||||
|
|
||||||
it('Pledge should have longest commitTime in delegation chain', async () => {
|
it('Pledge should have longest commitTime in delegation chain', async () => {
|
||||||
// delegate1 add delegate2 to chain
|
// 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
|
// set the time
|
||||||
const now = Math.floor(new Date().getTime() / 1000);
|
const now = Math.floor(new Date().getTime() / 1000);
|
||||||
await liquidPledging.setMockedTime(now);
|
await liquidPledging.setMockedTime(now, { $extraGas: 200000 });
|
||||||
|
|
||||||
// propose project delegation
|
// propose project delegation
|
||||||
await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2 });
|
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 () => {
|
it('delegation chain should remain the same when owner veto\'s delegation', async () => {
|
||||||
// owner veto delegation to project1
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges[ 8 ].amount, 0);
|
assert.equal(st.pledges[8].amount, 0);
|
||||||
assert.equal(st.pledges[ 3 ].amount, 1000);
|
assert.equal(st.pledges[3].amount, 1000);
|
||||||
assert.equal(st.pledges[ 3 ].delegates.length, 2);
|
assert.equal(st.pledges[3].delegates.length, 2);
|
||||||
assert.equal(st.pledges[ 3 ].delegates[ 0 ].id, 2);
|
assert.equal(st.pledges[3].delegates[0].id, 2);
|
||||||
assert.equal(st.pledges[ 3 ].delegates[ 1 ].id, 3);
|
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 () => {
|
it('delegation chain should remain the same upto delegate of reciever when owner veto\'s delegation', async () => {
|
||||||
// propose project1 delegation
|
// 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
|
// 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);
|
const pledge = await liquidPledging.getPledge(2);
|
||||||
assert.equal(pledge.amount, 1000);
|
assert.equal(pledge.amount, 1000);
|
||||||
|
@ -214,7 +214,7 @@ describe('DelegationChain test', function () {
|
||||||
// propose project1 delegation
|
// propose project1 delegation
|
||||||
await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1 });
|
await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1 });
|
||||||
// owner veto delegation to project1 and assign new delgate
|
// 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);
|
const pledge = await liquidPledging.getPledge(10);
|
||||||
assert.equal(pledge.amount, 1000);
|
assert.equal(pledge.amount, 1000);
|
||||||
|
|
|
@ -34,11 +34,14 @@ describe('LiquidPledging test', function () {
|
||||||
let adminProject3;
|
let adminProject3;
|
||||||
let delegate2;
|
let delegate2;
|
||||||
let escapeHatchDestination;
|
let escapeHatchDestination;
|
||||||
|
let escapeHatchCaller;
|
||||||
|
let acl;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
testrpc = TestRPC.server({
|
testrpc = TestRPC.server({
|
||||||
ws: true,
|
ws: true,
|
||||||
gasLimit: 6700000,
|
gasLimit: 6700000,
|
||||||
total_accounts: 10,
|
total_accounts: 11,
|
||||||
});
|
});
|
||||||
|
|
||||||
testrpc.listen(8545, '127.0.0.1');
|
testrpc.listen(8545, '127.0.0.1');
|
||||||
|
@ -54,6 +57,7 @@ describe('LiquidPledging test', function () {
|
||||||
giver2 = accounts[7];
|
giver2 = accounts[7];
|
||||||
adminProject3 = accounts[8];
|
adminProject3 = accounts[8];
|
||||||
escapeHatchDestination = accounts[9];
|
escapeHatchDestination = accounts[9];
|
||||||
|
escapeHatchCaller = accounts[10];
|
||||||
});
|
});
|
||||||
|
|
||||||
after((done) => {
|
after((done) => {
|
||||||
|
@ -72,16 +76,20 @@ describe('LiquidPledging test', function () {
|
||||||
vault = new contracts.LPVault(web3, vaultAddress);
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
lp = new contracts.LiquidPledgingMock(web3, lpAddress);
|
liquidPledging = 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());
|
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
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 () => {
|
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();
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||||
assert.equal(nAdmins, 1);
|
assert.equal(nAdmins, 1);
|
||||||
const res = await liquidPledging.getPledgeAdmin(1);
|
const res = await liquidPledging.getPledgeAdmin(1);
|
||||||
|
@ -92,10 +100,12 @@ 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') });
|
const r = await liquidPledging.donate(1, 1, { from: giver1, value: utils.toWei('1'), gas: 1000000 });
|
||||||
const nPledges = await liquidPledging.numberOfPledges();
|
const nPledges = await liquidPledging.numberOfPledges();
|
||||||
assert.equal(nPledges, 1);
|
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 () => {
|
it('Should create a delegate', async () => {
|
||||||
await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 });
|
await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 });
|
||||||
|
@ -109,7 +119,7 @@ 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, $extraGas: 100000 });
|
||||||
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);
|
||||||
|
@ -118,7 +128,7 @@ describe('LiquidPledging test', function () {
|
||||||
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.getDelegate(2, 0);
|
const d = await liquidPledging.getPledgeDelegate(2, 1);
|
||||||
assert.equal(d[0], 2);
|
assert.equal(d[0], 2);
|
||||||
assert.equal(d[1], delegate1);
|
assert.equal(d[1], delegate1);
|
||||||
assert.equal(d[2], '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 () => {
|
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, {$extraGas: 100000});
|
||||||
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);
|
||||||
|
@ -204,7 +214,7 @@ describe('LiquidPledging test', function () {
|
||||||
it('Should collect the Ether', async () => {
|
it('Should collect the Ether', async () => {
|
||||||
const initialBalance = await web3.eth.getBalance(adminProject1);
|
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 finalBalance = await web3.eth.getBalance(adminProject1);
|
||||||
|
|
||||||
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
|
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
|
assert.equal(res7[6], 2); // Peinding paid Paid
|
||||||
});
|
});
|
||||||
it('Admin of the project1 should be able to cancel project1', async () => {
|
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);
|
const st = await liquidPledgingState.getState(liquidPledging);
|
||||||
assert.equal(st.admins[3].canceled, true);
|
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 () => {
|
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);
|
const st = await liquidPledgingState.getState(liquidPledging);
|
||||||
assert.equal(st.pledges.length, 9);
|
assert.equal(st.pledges.length, 9);
|
||||||
assert.equal(utils.fromWei(st.pledges[8].amount), 0.03);
|
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);
|
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 });
|
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);
|
||||||
|
@ -259,14 +269,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, $extraGas: 200000 });
|
||||||
const st = await liquidPledgingState.getState(liquidPledging);
|
const st = await liquidPledgingState.getState();
|
||||||
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, $extraGas: 100000 });
|
||||||
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);
|
||||||
|
@ -274,8 +284,8 @@ 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), {$extraGas: 200000});
|
||||||
await liquidPledging.withdraw(10, utils.toWei('0.005'), { from: adminProject2a });
|
await liquidPledging.withdraw(10, utils.toWei('0.005'), { from: adminProject2a, $extraGas: 200000 });
|
||||||
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);
|
||||||
|
@ -283,7 +293,7 @@ describe('LiquidPledging test', function () {
|
||||||
assert.equal(utils.fromWei(st.pledges[12].amount), 0.005);
|
assert.equal(utils.fromWei(st.pledges[12].amount), 0.005);
|
||||||
});
|
});
|
||||||
it('project2 is canceled', async () => {
|
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 () => {
|
it('Should not be able to withdraw it', async () => {
|
||||||
await assertFail(
|
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);
|
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);
|
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 finalBalance = await web3.eth.getBalance(giver1);
|
||||||
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
|
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 () => {
|
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'), $extraGas: 200000 });
|
||||||
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();
|
||||||
|
@ -348,10 +358,10 @@ describe('LiquidPledging test', function () {
|
||||||
it('should throw if projectLevel > 20', async () => {
|
it('should throw if projectLevel > 20', async () => {
|
||||||
let nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
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++) {
|
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(
|
assertFail(
|
||||||
|
|
|
@ -3,13 +3,9 @@
|
||||||
const TestRPC = require("ganache-cli");
|
const TestRPC = require("ganache-cli");
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const liquidpledging = require('../index.js');
|
const contracts = require("../build/contracts.js");
|
||||||
const EternalStorage = require('../js/eternalStorage');
|
const LiquidPledgingState = require('../index').LiquidPledgingState;
|
||||||
const PledgeAdmins = require('../js/pledgeAdmins');
|
|
||||||
|
|
||||||
const LiquidPledging = liquidpledging.LiquidPledgingMock;
|
|
||||||
const LiquidPledgingState = liquidpledging.LiquidPledgingState;
|
|
||||||
const LPVault = liquidpledging.LPVault;
|
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
|
|
||||||
const printState = async (liquidPledgingState) => {
|
const printState = async (liquidPledgingState) => {
|
||||||
|
@ -58,13 +54,17 @@ describe('NormalizePledge test', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should deploy LiquidPledging contract', async () => {
|
it('Should deploy LiquidPledging contract', async () => {
|
||||||
vault = await LPVault.new(web3, accounts[0], accounts[1]);
|
const baseVault = await contracts.LPVault.new(web3);
|
||||||
const storage = await EternalStorage.new(web3, accounts[0], accounts[1]);
|
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);
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
||||||
await vault.setLiquidPledging(liquidPledging.$address);
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
|
liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress);
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
||||||
});
|
});
|
||||||
|
@ -83,25 +83,25 @@ describe('NormalizePledge test', function () {
|
||||||
|
|
||||||
it('Should commit pledges if commitTime has passed', async () => {
|
it('Should commit pledges if commitTime has passed', async () => {
|
||||||
// commitTime 259200
|
// commitTime 259200
|
||||||
await liquidPledging.donate(1, 2, {from: giver1, value: 1000});
|
await liquidPledging.donate(1, 2, { from: giver1, value: 1000 });
|
||||||
// commitTime 86400
|
// commitTime 86400
|
||||||
await liquidPledging.donate(1, 3, {from: giver1, value: 1000});
|
await liquidPledging.donate(1, 3, { from: giver1, value: 1000 });
|
||||||
// commitTime 0
|
// commitTime 0
|
||||||
await liquidPledging.donate(6, 3, {from: giver2, value: 1000});
|
await liquidPledging.donate(6, 3, { from: giver2, value: 1000 });
|
||||||
|
|
||||||
// set the time
|
// set the time
|
||||||
const now = Math.floor(new Date().getTime() / 1000);
|
const now = Math.floor(new Date().getTime() / 1000);
|
||||||
await liquidPledging.setMockedTime(now);
|
await liquidPledging.setMockedTime(now, { $extraGas: 200000 });
|
||||||
|
|
||||||
// delegate to project
|
// delegate to project
|
||||||
await liquidPledging.transfer(2, 2, 1000, 4, {from: delegate1});
|
await liquidPledging.transfer(2, 2, 1000, 4, { from: delegate1 });
|
||||||
await liquidPledging.transfer(3, 3, 1000, 4, {from: delegate2});
|
await liquidPledging.transfer(3, 3, 1000, 4, { from: delegate2 });
|
||||||
await liquidPledging.transfer(3, 5, 1000, 4, {from: delegate2});
|
await liquidPledging.transfer(3, 5, 1000, 4, { from: delegate2 });
|
||||||
|
|
||||||
// advance the time
|
// 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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges.length, 11);
|
assert.equal(st.pledges.length, 11);
|
||||||
|
@ -115,13 +115,13 @@ describe('NormalizePledge test', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should transfer pledge to oldestPledgeNotCanceled', async () => {
|
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
|
// cancel projects
|
||||||
await liquidPledging.cancelProject(4, {from: adminProject1});
|
await liquidPledging.cancelProject(4, { from: adminProject1, $extraGas: 200000 });
|
||||||
await liquidPledging.cancelProject(5, {from: adminProject2});
|
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();
|
const st = await liquidPledgingState.getState();
|
||||||
assert.equal(st.pledges.length, 12);
|
assert.equal(st.pledges.length, 12);
|
||||||
|
|
|
@ -3,14 +3,10 @@
|
||||||
const TestRPC = require("ganache-cli");
|
const TestRPC = require("ganache-cli");
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const chai = require('chai');
|
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 assertFail = require('./helpers/assertFail');
|
||||||
|
const contracts = require("../build/contracts.js");
|
||||||
|
|
||||||
const LiquidPledging = liquidpledging.LiquidPledgingMock;
|
const LiquidPledgingState = require('../index').LiquidPledgingState;
|
||||||
const LiquidPledgingState = liquidpledging.LiquidPledgingState;
|
|
||||||
const LPVault = liquidpledging.LPVault;
|
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
|
|
||||||
describe('Vault test', function () {
|
describe('Vault test', function () {
|
||||||
|
@ -27,6 +23,7 @@ describe('Vault test', function () {
|
||||||
let escapeHatchDestination;
|
let escapeHatchDestination;
|
||||||
let giver1;
|
let giver1;
|
||||||
let adminProject1;
|
let adminProject1;
|
||||||
|
let restrictedPaymentsConfirmer;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
testrpc = TestRPC.server({
|
testrpc = TestRPC.server({
|
||||||
|
@ -44,6 +41,7 @@ describe('Vault test', function () {
|
||||||
vaultOwner = accounts[ 3 ];
|
vaultOwner = accounts[ 3 ];
|
||||||
escapeHatchDestination = accounts[ 4 ];
|
escapeHatchDestination = accounts[ 4 ];
|
||||||
escapeHatchCaller = accounts[ 5 ];
|
escapeHatchCaller = accounts[ 5 ];
|
||||||
|
restrictedPaymentsConfirmer = accounts[ 6 ];
|
||||||
});
|
});
|
||||||
|
|
||||||
after((done) => {
|
after((done) => {
|
||||||
|
@ -52,25 +50,37 @@ describe('Vault test', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should deploy Vault contract', async function () {
|
it('Should deploy Vault contract', async function () {
|
||||||
vault = await LPVault.new(web3, escapeHatchCaller, escapeHatchDestination, {from: vaultOwner});
|
const baseVault = await contracts.LPVault.new(web3);
|
||||||
const storage = await EternalStorage.new(web3, accounts[0], accounts[1]);
|
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);
|
const vaultAddress = r.events.DeployVault.returnValues.vault;
|
||||||
await vault.setLiquidPledging(liquidPledging.$address, {from: vaultOwner});
|
vault = new contracts.LPVault(web3, vaultAddress);
|
||||||
|
|
||||||
|
const lpAddress = r.events.DeployLiquidPledging.returnValues.liquidPledging;
|
||||||
|
liquidPledging = new contracts.LiquidPledgingMock(web3, lpAddress);
|
||||||
|
|
||||||
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
liquidPledgingState = new LiquidPledgingState(liquidPledging);
|
||||||
|
|
||||||
await liquidPledging.addGiver('Giver1', '', 0, '0x0', { from: giver1 });
|
// set permissions
|
||||||
await liquidPledging.addProject('Project1', '', adminProject1, 0, 0, '0x0', { from: adminProject1 });
|
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();
|
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||||
assert.equal(nAdmins, 2);
|
assert.equal(nAdmins, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should hold funds from liquidPledging', async function () {
|
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);
|
const balance = await web3.eth.getBalance(vault.$address);
|
||||||
assert.equal(10000, balance);
|
assert.equal(10000, balance);
|
||||||
|
@ -87,7 +97,7 @@ describe('Vault test', function () {
|
||||||
it('escapeFunds should send funds to escapeHatchDestination', async function () {
|
it('escapeFunds should send funds to escapeHatchDestination', async function () {
|
||||||
const preBalance = await web3.eth.getBalance(escapeHatchDestination);
|
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);
|
const vaultBalance = await web3.eth.getBalance(vault.$address);
|
||||||
assert.equal(9000, vaultBalance);
|
assert.equal(9000, vaultBalance);
|
||||||
|
@ -96,6 +106,19 @@ describe('Vault test', function () {
|
||||||
const postBalance = await web3.eth.getBalance(escapeHatchDestination);
|
const postBalance = await web3.eth.getBalance(escapeHatchDestination);
|
||||||
|
|
||||||
assert.equal(expected, postBalance);
|
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 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue