Veto by the owner fixed
This commit is contained in:
parent
6194f3957b
commit
5230c14ab2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -495,6 +495,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
} else if (receiver.adminType == PledgeAdminType.Project) {
|
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
transferOwnershipToProject(idPledge, amount, idReceiver);
|
transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -520,14 +521,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
|
|
||||||
// If the receiver is not in the delegate list
|
// If the receiver is not in the delegate list
|
||||||
if (receiverDIdx == NOTFOUND) {
|
if (receiverDIdx == NOTFOUND) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
// after the sender, then all of the other delegates after the sender are
|
// after the sender, then all of the other delegates after the sender are
|
||||||
// removed and the receiver is appended at the end of the delegation chain
|
// removed and the receiver is appended at the end of the delegation chain
|
||||||
} else if (receiverDIdx > senderDIdx) {
|
} else if (receiverDIdx > senderDIdx) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
|
@ -544,7 +545,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
// If the delegate wants to support a project, they undelegate all
|
// If the delegate wants to support a project, they undelegate all
|
||||||
// the delegates after them in the chain and choose a project
|
// the delegates after them in the chain and choose a project
|
||||||
if (receiver.adminType == PledgeAdminType.Project) {
|
if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
proposeAssignProject(idPledge, amount, idReceiver);
|
proposeAssignProject(idPledge, amount, idReceiver);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -767,7 +768,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param q Number of undelegations
|
/// @param q Number of undelegations
|
||||||
function undelegate(uint64 idPledge, uint amount, uint q) internal {
|
function undelegate(uint64 idPledge, uint amount, uint q) internal returns (uint64){
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage n = findPledge(idPledge);
|
||||||
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
||||||
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
||||||
|
@ -781,6 +782,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
n.oldPledge,
|
n.oldPledge,
|
||||||
PaymentState.Pledged);
|
PaymentState.Pledged);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
|
|
||||||
|
return toPledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -495,6 +495,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
} else if (receiver.adminType == PledgeAdminType.Project) {
|
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
transferOwnershipToProject(idPledge, amount, idReceiver);
|
transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -520,14 +521,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
|
|
||||||
// If the receiver is not in the delegate list
|
// If the receiver is not in the delegate list
|
||||||
if (receiverDIdx == NOTFOUND) {
|
if (receiverDIdx == NOTFOUND) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
// after the sender, then all of the other delegates after the sender are
|
// after the sender, then all of the other delegates after the sender are
|
||||||
// removed and the receiver is appended at the end of the delegation chain
|
// removed and the receiver is appended at the end of the delegation chain
|
||||||
} else if (receiverDIdx > senderDIdx) {
|
} else if (receiverDIdx > senderDIdx) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
|
@ -544,7 +545,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
// If the delegate wants to support a project, they undelegate all
|
// If the delegate wants to support a project, they undelegate all
|
||||||
// the delegates after them in the chain and choose a project
|
// the delegates after them in the chain and choose a project
|
||||||
if (receiver.adminType == PledgeAdminType.Project) {
|
if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
proposeAssignProject(idPledge, amount, idReceiver);
|
proposeAssignProject(idPledge, amount, idReceiver);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -767,7 +768,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param q Number of undelegations
|
/// @param q Number of undelegations
|
||||||
function undelegate(uint64 idPledge, uint amount, uint q) internal {
|
function undelegate(uint64 idPledge, uint amount, uint q) internal returns (uint64){
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage n = findPledge(idPledge);
|
||||||
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
||||||
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
||||||
|
@ -781,6 +782,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
n.oldPledge,
|
n.oldPledge,
|
||||||
PaymentState.Pledged);
|
PaymentState.Pledged);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
|
|
||||||
|
return toPledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
} else if (receiver.adminType == PledgeAdminType.Project) {
|
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
transferOwnershipToProject(idPledge, amount, idReceiver);
|
transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -106,14 +107,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
|
|
||||||
// If the receiver is not in the delegate list
|
// If the receiver is not in the delegate list
|
||||||
if (receiverDIdx == NOTFOUND) {
|
if (receiverDIdx == NOTFOUND) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
// after the sender, then all of the other delegates after the sender are
|
// after the sender, then all of the other delegates after the sender are
|
||||||
// removed and the receiver is appended at the end of the delegation chain
|
// removed and the receiver is appended at the end of the delegation chain
|
||||||
} else if (receiverDIdx > senderDIdx) {
|
} else if (receiverDIdx > senderDIdx) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
// If the receiver is already part of the delegate chain and is
|
// If the receiver is already part of the delegate chain and is
|
||||||
|
@ -130,7 +131,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
// If the delegate wants to support a project, they undelegate all
|
// If the delegate wants to support a project, they undelegate all
|
||||||
// the delegates after them in the chain and choose a project
|
// the delegates after them in the chain and choose a project
|
||||||
if (receiver.adminType == PledgeAdminType.Project) {
|
if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
idPledge = undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||||
proposeAssignProject(idPledge, amount, idReceiver);
|
proposeAssignProject(idPledge, amount, idReceiver);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -353,7 +354,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param q Number of undelegations
|
/// @param q Number of undelegations
|
||||||
function undelegate(uint64 idPledge, uint amount, uint q) internal {
|
function undelegate(uint64 idPledge, uint amount, uint q) internal returns (uint64){
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage n = findPledge(idPledge);
|
||||||
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
||||||
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
||||||
|
@ -367,6 +368,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||||
n.oldPledge,
|
n.oldPledge,
|
||||||
PaymentState.Pledged);
|
PaymentState.Pledged);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
|
|
||||||
|
return toPledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ const readTest = async (liquidPledging) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('LiquidPledging test', () => {
|
describe('LiquidPledging test', () => {
|
||||||
|
let testrpc;
|
||||||
let web3;
|
let web3;
|
||||||
let accounts;
|
let accounts;
|
||||||
let liquidPledging;
|
let liquidPledging;
|
||||||
|
@ -52,7 +53,7 @@ describe('LiquidPledging test', () => {
|
||||||
let adminProject3;
|
let adminProject3;
|
||||||
let delegate2;
|
let delegate2;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const testrpc = TestRPC.server({
|
testrpc = TestRPC.server({
|
||||||
ws: true,
|
ws: true,
|
||||||
gasLimit: 5800000,
|
gasLimit: 5800000,
|
||||||
total_accounts: 10,
|
total_accounts: 10,
|
||||||
|
@ -71,6 +72,11 @@ describe('LiquidPledging test', () => {
|
||||||
giver2 = accounts[7];
|
giver2 = accounts[7];
|
||||||
adminProject3 = accounts[8];
|
adminProject3 = accounts[8];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
after((done) => {
|
||||||
|
testrpc.close();
|
||||||
|
done();
|
||||||
|
});
|
||||||
it('Should deploy LiquidPledging contract', async () => {
|
it('Should deploy LiquidPledging contract', async () => {
|
||||||
vault = await Vault.new(web3);
|
vault = await Vault.new(web3);
|
||||||
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 });
|
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 });
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
/* eslint-env mocha */
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
const TestRPC = require('ethereumjs-testrpc');
|
||||||
|
const Web3 = require('web3');
|
||||||
|
const chai = require('chai');
|
||||||
|
const liquidpledging = require('../index.js');
|
||||||
|
const assertFail = require('./helpers/assertFail');
|
||||||
|
|
||||||
|
const { utils } = Web3;
|
||||||
|
|
||||||
|
const LiquidPledging = liquidpledging.LiquidPledging(true);
|
||||||
|
const Vault = liquidpledging.Vault;
|
||||||
|
const assert = chai.assert;
|
||||||
|
|
||||||
|
const printState = async (liquidPledging) => {
|
||||||
|
const st = await liquidPledging.getState();
|
||||||
|
console.log(JSON.stringify(st, null, 2));
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('LiquidPledging test', function() {
|
||||||
|
this.timeout(0);
|
||||||
|
let testrpc;
|
||||||
|
let web3;
|
||||||
|
let accounts;
|
||||||
|
let liquidPledging;
|
||||||
|
let vault;
|
||||||
|
let giver1;
|
||||||
|
let giver2;
|
||||||
|
let delegate1;
|
||||||
|
let adminProject1;
|
||||||
|
let adminProject2;
|
||||||
|
let adminProject2a;
|
||||||
|
let delegate2;
|
||||||
|
|
||||||
|
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 ];
|
||||||
|
adminProject2 = accounts[ 4 ];
|
||||||
|
adminProject2a = accounts[ 5 ];
|
||||||
|
delegate2 = accounts[ 6 ];
|
||||||
|
giver2 = accounts[ 7 ];
|
||||||
|
});
|
||||||
|
|
||||||
|
after((done) => {
|
||||||
|
testrpc.close();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should deploy LiquidPledgin contract', async () => {
|
||||||
|
vault = await Vault.new(web3);
|
||||||
|
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 });
|
||||||
|
await vault.setLiquidPledging(liquidPledging.$address);
|
||||||
|
});
|
||||||
|
|
||||||
|
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 function() {
|
||||||
|
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(liquidPledging);
|
||||||
|
// veto the delegation
|
||||||
|
await liquidPledging.transfer(2, 3, '1000', 1, { from: giver1, gas: 400000 });
|
||||||
|
|
||||||
|
const currentPledge = await liquidPledging.getPledge(2);
|
||||||
|
|
||||||
|
// await printState(liquidPledging);
|
||||||
|
|
||||||
|
assert.equal(currentPledge.amount, '1000');
|
||||||
|
assert.equal(currentPledge.nDelegates, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue