preserve delegationChain on delegation veto

This commit is contained in:
perissology 2017-11-10 08:39:58 -08:00
parent 1ed9c88a14
commit 5d15fc6f62
2 changed files with 53 additions and 8 deletions

View File

@ -81,8 +81,31 @@ contract LiquidPledging is LiquidPledgingBase {
} 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); uint recieverDIdx = getDelegateIdx(n, idReceiver);
if (n.intendedProject > 0 && recieverDIdx != NOTFOUND) {
// if there is an intendedProject and the receiver is in the delegationChain,
// then we want to preserve the delegationChain as this is a veto of the
// intendedProject by the owner
if (recieverDIdx == n.delegationChain.length - 1) {
uint64 toPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
0,
0,
n.oldPledge,
PaymentState.Pledged);
doTransfer(idPledge, toPledge, amount);
} else {
undelegate(idPledge, amount, n.delegationChain.length - receiverDIdx - 1);
}
} else {
// owner is transferring pledge to a new delegate, so we want to reset
// the delegationChain
idPledge = undelegate(idPledge, amount, n.delegationChain.length);
appendDelegate(idPledge, amount, idReceiver);
}
} else { } else {
assert(false); assert(false);
} }

View File

@ -181,19 +181,41 @@ 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 () => {
// delegate1 add delegate2 to chain
await liquidPledging.transfer(2, 2, 1000, 3, { from: delegate1, $extraGas: 100000 });
// delegate2 delegate to project1
await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2, $extraGas: 100000 });
// owner veto delegation to project1 // owner veto delegation to project1
await liquidPledging.transfer(1, 8, 1000, 3, { from: giver1, $extraGas: 100000 }); await liquidPledging.transfer(1, 8, 1000, 3, { from: giver1, $extraGas: 100000 });
printState(liquidPledgingState);
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[ 0 ].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 () => {
// propose project1 delegation
await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2, $extraGas: 100000 });
// owner veto delegation to project1 and remove delegate2
await liquidPledging.transfer(1, 8, 1000, 2, { from: giver1, $extraGas: 100000 });
const pledge = await liquidPledging.getPledge(2);
assert.equal(pledge.amount, 1000);
});
it('owner should be able to transfer pledge to a new delegate at any time', async () => {
// propose project1 delegation
await liquidPledging.transfer(2, 2, 1000, 5, { from: delegate1, $extraGas: 100000 });
// owner veto delegation to project1 and assign new delgate
await liquidPledging.transfer(1, 9, 1000, 3, { from: giver1, $extraGas: 100000 });
const pledge = await liquidPledging.getPledge(10);
assert.equal(pledge.amount, 1000);
assert.equal(pledge.nDelegates, 1);
// owner assign new delegate w/o vetoing intendedProject
await liquidPledging.transfer(1, 10, 1000, 2, { from: giver1, $extraGas: 100000 });
const pledge2 = await liquidPledging.getPledge(2);
assert.equal(pledge2.amount, 1000);
await printState(liquidPledgingState);
}); });
}); });