added test for maxCommit time in delegation chain

This commit is contained in:
perissology 2017-10-23 17:02:47 -07:00
parent fa996a43b9
commit 423f61ff51
2 changed files with 18 additions and 3 deletions

View File

@ -22,7 +22,7 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idReceiver To whom it's transfered. Can be the same giver, another /// @param idReceiver To whom it's transfered. Can be the same giver, another
/// giver, a delegate or a project /// giver, a delegate or a project
function donate(uint64 idGiver, uint64 idReceiver) payable { function donate(uint64 idGiver, uint64 idReceiver) payable {
if (idGiver == 0) { if (idGiver == 0) {
idGiver = addGiver('', '', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime idGiver = addGiver('', '', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
} }

View File

@ -64,8 +64,8 @@ describe('LiquidPledging test', function () {
}); });
it('Should add pledgeAdmins', async () => { it('Should add pledgeAdmins', async () => {
await liquidPledging.addGiver('Giver1', 'URLGiver1', 0, 0, { from: giver1 }); // pledgeAdmin 1 await liquidPledging.addGiver('Giver1', 'URLGiver1', 86400, 0, { from: giver1 }); // pledgeAdmin 1
await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 0, 0, { from: delegate1 }); // pledgeAdmin 2 await liquidPledging.addDelegate('Delegate1', 'URLDelegate1', 259200, 0, { from: delegate1 }); // pledgeAdmin 2
await liquidPledging.addDelegate('Delegate2', 'URLDelegate2', 0, 0, { from: delegate2 }); // pledgeAdmin 3 await liquidPledging.addDelegate('Delegate2', 'URLDelegate2', 0, 0, { from: delegate2 }); // pledgeAdmin 3
await liquidPledging.addDelegate('Delegate3', 'URLDelegate3', 0, 0, { from: delegate3 }); // pledgeAdmin 4 await liquidPledging.addDelegate('Delegate3', 'URLDelegate3', 0, 0, { from: delegate3 }); // pledgeAdmin 4
await liquidPledging.addProject('Project1', 'URLProject1', adminProject1, 0, 0, 0, { from: adminProject1 }); // pledgeAdmin 5 await liquidPledging.addProject('Project1', 'URLProject1', adminProject1, 0, 0, 0, { from: adminProject1 }); // pledgeAdmin 5
@ -164,4 +164,19 @@ describe('LiquidPledging test', function () {
assert.equal(currentPledge.amount, '1000'); assert.equal(currentPledge.amount, '1000');
assert.equal(currentPledge.nDelegates, 1); assert.equal(currentPledge.nDelegates, 1);
}); });
it('Pledge should have longest commitTime in delegation chain', async () => {
// delegate1 add delegate2 to chain
await liquidPledging.transfer(2, 2, 1000, 3, {from: delegate1, $extraGas: 100000});
// propose project delegation
const now = Math.floor(new Date().getTime() / 1000);
await liquidPledging.transfer(3, 3, 1000, 5, { from: delegate2, $extraGas: 100000 });
const pledge = await liquidPledging.getPledge(8);
// due to how block timestamp differences, we can't check an exact time
// the commitTimes for the pledgeAdmins are as follows giver - 86400, delegate1 - 259200, delegate2 - 0
// therefore checking within 1000 ms means that the longest commitTime was choosen
assert.approximately(web3.utils.toDecimal(pledge.commitTime), now + 259200, 1000); // 259200 is longest commitTime in delegationChain
})
}); });