Change comments based on requests

This commit is contained in:
Arthur L Lunn 2017-12-03 01:59:30 +01:00
parent 458c6236bd
commit 9f105876a8
3 changed files with 32 additions and 129 deletions

View File

@ -91,7 +91,8 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param amount Quantity of value that's being moved
/// @param idReceiver Destination of the value, can be a giver sending to
/// a giver or a delegate, a delegate to another delegate or a project
/// to pre-commit it to that project
/// to pre-commit it to that project if called from a delegate,
/// or to commit it to the project if called from the owner.
function transfer(
uint64 idSender,
uint64 idPledge,
@ -197,10 +198,8 @@ contract LiquidPledging is LiquidPledgingBase {
assert(false); // It is not the owner nor any delegate.
}
/// @notice This method is used to withdraw value from the system.
/// This can be used by the givers to avoid committing the donation
/// or by project admin to use the Ether.
/// This can be used by the givers withdraw any un-commited donations.
/// @param idPledge Id of the pledge that wants to be withdrawn.
/// @param amount Quantity of Ether that wants to be withdrawn.
function withdraw(uint64 idPledge, uint amount) {
@ -374,8 +373,7 @@ contract LiquidPledging is LiquidPledgingBase {
/// @notice `mNormalizePledge` allows for multiple pledges to be
/// normalized efficiently
/// @param pledges An array of pledge IDs which are extrapolated using
/// the D64 bitmask
/// @param pledges An array of pledge IDs
function mNormalizePledge(uint64[] pledges) {
for (uint i = 0; i < pledges.length; i++ ) {
normalizePledge( pledges[i] );
@ -387,8 +385,8 @@ contract LiquidPledging is LiquidPledgingBase {
///////
/// @notice `transferOwnershipToProject` allows for the transfer of
/// ownership to the project, but it can also be called to un-delegate
/// everyone by setting one's own id for the idReceiver
/// ownership to the project, but it can also be called by a project
/// to un-delegate everyone by setting one's own id for the idReceiver
/// @param idPledge Id of the pledge to be transfered.
/// @param amount Quantity of value that's being transfered
/// @param idReceiver The new owner of the project (or self to un-delegate)
@ -545,10 +543,12 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param _amount The amount of value that will be transfered.
function doTransfer(uint64 from, uint64 to, uint _amount) internal {
uint amount = callPlugins(true, from, to, _amount);
if (from == to)
if (from == to) {
return;
if (amount == 0)
}
if (amount == 0) {
return;
}
Pledge storage nFrom = findPledge(from);
Pledge storage nTo = findPledge(to);
require(nFrom.amount >= amount);
@ -581,8 +581,9 @@ contract LiquidPledging is LiquidPledgingBase {
// Check to make sure this pledge hasn't already been used
// or is in the process of being used
if (n.paymentState != PaymentState.Pledged)
if (n.paymentState != PaymentState.Pledged) {
return idPledge;
}
// First send to a project if it's proposed and committed
if ((n.intendedProject > 0) && ( getTime() > n.commitTime)) {
@ -592,14 +593,16 @@ contract LiquidPledging is LiquidPledgingBase {
0,
0,
n.oldPledge,
PaymentState.Pledged);
PaymentState.Pledged
);
uint64 toPledge = findOrCreatePledge(
n.intendedProject,
new uint64[](0),
0,
0,
oldPledge,
PaymentState.Pledged);
PaymentState.Pledged
);
doTransfer(idPledge, toPledge, n.amount);
idPledge = toPledge;
n = findPledge(idPledge);

View File

@ -40,8 +40,9 @@ contract LiquidPledgingBase is Owned {
enum PledgeAdminType { Giver, Delegate, Project }
enum PaymentState { Pledged, Paying, Paid }
/// @dev This struct defines the details of the `PledgeAdmin` which are
/// Referenced by their id and can own pledges and act as delegates
/// @dev This struct defines the details of a `PledgeAdmin` which are
/// commonly referenced by their index in the `admins` array.
/// and can own pledges and act as delegates
struct PledgeAdmin {
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // Account or contract address for admin
@ -172,9 +173,9 @@ contract LiquidPledgingBase is Owned {
/// @notice Creates a Delegate Admin with the `msg.sender` as the Admin addr
/// @param name The name used to identify the Delegate
/// @param url The link to the Delegate's profile often an IPFS hash
/// @param commitTime Sets the length of time in seconds the Delegate has to
/// veto when the Delegate delegates to another Delegate and they pledge
/// those funds to a project
/// @param commitTime Sets the length of time in seconds that this delegate
/// can be vetoed. Whenever this delegate is in a delegate chain the time
/// allowed to veto any event must be greater than or equal to this time.
/// @param plugin This is Delegate's liquid pledge plugin allowing for
/// extended functionality
/// @return idxDelegate The id number used to reference this Delegate within
@ -212,9 +213,10 @@ contract LiquidPledgingBase is Owned {
/// @param newAddr The new address that represents this Delegate
/// @param newName The new name used to identify the Delegate
/// @param newUrl The new link to the Delegate's profile often an IPFS hash
/// @param newCommitTime Sets the length of time in seconds the Delegate has
/// to veto when the Delegate delegates to a Delegate and they pledge those
/// funds to a project
/// @param newCommitTime Sets the length of time in seconds that this
/// delegate can be vetoed. Whenever this delegate is in a delegate chain
/// the time allowed to veto any event must be greater than or equal to
/// this time.
function updateDelegate(
uint64 idxDelegate,
address newAddr,
@ -237,7 +239,7 @@ contract LiquidPledgingBase is Owned {
/// @param name The name used to identify the Project
/// @param url The link to the Project's profile often an IPFS hash
/// @param projectAdmin The address for the trusted project manager
/// @param parentProject The Admin id number for the parent Campaign or 0 if
/// @param parentProject The Admin id number for the parent project or 0 if
/// there is no parentProject
/// @param commitTime Sets the length of time in seconds the Project has to
/// veto when the Project delegates to another Delegate and they pledge
@ -372,7 +374,7 @@ contract LiquidPledgingBase is Owned {
/// @return commitTime The length of time in seconds the Admin has to veto
/// when the Admin delegates to a Delegate and that Delegate pledges those
/// funds to a project
/// @return parentProject The Admin id number for the parent Campaign or 0
/// @return parentProject The Admin id number for the parent project or 0
/// if there is no parentProject
/// @return canceled 0 for Delegates & Givers, true if a Project has been
/// canceled
@ -462,9 +464,10 @@ contract LiquidPledgingBase is Owned {
/// authority a specific delegate has within a Pledge
/// @param n The Pledge that will be searched
/// @param idxDelegate The specified delegate that's searched for
/// @return How many Delegates have more authority than the specified
/// delegate; if the delegate is not in the delegationChain it will return
/// `0xFFFFFFFFFFFFFFFF`
/// @return If the delegate chain contains the delegate with the
/// `admins` array index `idxDelegae` this returns that delegates
/// corresponding index in the delegationChain. Otherwise it returns
/// the maximum address.
function getDelegateIdx(Pledge n, uint64 idxDelegate) internal returns(uint64) {
for (uint i=0; i<n.delegationChain.length; i++) {
if (n.delegationChain[i] == idxDelegate) return uint64(i);

View File

@ -1,103 +0,0 @@
/* eslint-env mocha */
/* eslint-disable no-await-in-loop */
const TestRPC = require('ethereumjs-testrpc');
const Web3 = require('web3');
const chai = require('chai');
const liquidpledging = require('../index.js');
const LiquidPledging = liquidpledging.LiquidPledgingMock;
const LiquidPledgingState = liquidpledging.LiquidPledgingState;
const LPVault = liquidpledging.LPVault;
const assert = chai.assert;
const printState = async (liquidPledgingState) => {
const st = await liquidPledgingState.getState();
console.log(JSON.stringify(st, null, 2));
};
describe('Liquid Pledging Veto Delegation', () => {
let testrpc;
let web3;
let accounts;
let liquidPledging;
let liquidPledgingState;
let vault;
let giver1;
let delegate1;
let adminProject1;
before(async () => {
testrpc = TestRPC.server({
ws: true,
gasLimit: 5800000,
total_accounts: 10,
});
testrpc.listen(8546, '127.0.0.1');
web3 = new Web3('ws://localhost:8546');
accounts = await web3.eth.getAccounts();
giver1 = accounts[1];
delegate1 = accounts[2];
adminProject1 = accounts[3];
});
after((done) => {
testrpc.close();
done();
});
it('Should deploy LiquidPledgin contract', async () => {
vault = await LPVault.new(web3);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 });
await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging);
});
it('Should create a delegate', async () => {
await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 1);
const res = await liquidPledging.getPledgeAdmin(1);
assert.equal(res[0], 1); // Giver
assert.equal(res[1], delegate1);
assert.equal(res[2], 'Delegate1');
assert.equal(res[3], 'URLDelegate1');
assert.equal(res[4], 0);
}).timeout(6000);
it('Should make a donation and create giver', async () => {
await liquidPledging.donate(0, 1, { from: giver1, value: '1000', gas: 2000000 });
const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 2);
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 2);
const res = await liquidPledging.getPledgeAdmin(nAdmins);
assert.equal(res[0], 0); // Giver
assert.equal(res[1], giver1);
assert.equal(res[2], '');
assert.equal(res[3], '');
assert.equal(res[4], 259200); // default to 3 day commitTime
});
it('Should not append delegate on veto delegation', async () => {
await liquidPledging.addProject('Project 1', 'url', adminProject1, 0, 0, 0);
// propose the delegation
await liquidPledging.transfer(1, 2, '1000', 3, { from: delegate1, gas: 400000 });
// await liquidPledging.transfer(1, 2, '1000', 5, { from: giver1, gas: 400000 });
const origPledge = await liquidPledging.getPledge(2);
assert.equal(origPledge.amount, '0');
// await printState(liquidPledgingState);
// veto the delegation
await liquidPledging.transfer(2, 3, '1000', 1, { from: giver1, gas: 400000 });
const currentPledge = await liquidPledging.getPledge(2);
// await printState(liquidPledgingState);
assert.equal(currentPledge.amount, '1000');
assert.equal(currentPledge.nDelegates, 1);
});
});