Merge pull request #1 from perissology/add_donor_on_donate

call addDonor in donate method if donorId is 0
This commit is contained in:
Jordi Baylina 2017-10-03 11:51:17 +02:00 committed by GitHub
commit c190d5fb0f
3 changed files with 24 additions and 5 deletions

View File

@ -21,7 +21,12 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idDonor Identifier of the donor thats donating.
/// @param idReceiver To whom it's transfered. Can be the same donor, another
/// donor, a delegate or a project
function donate(uint64 idDonor, uint64 idReceiver) payable {
function donate(uint64 idDonor, uint64 idReceiver) payable {
if (idDonor == 0) {
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
}
NoteManager storage sender = findManager(idDonor);
checkManagerOwner(sender);

View File

@ -77,7 +77,7 @@ contract LiquidPledgingBase {
/// @notice Creates a donor.
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
) returns (uint64 idDonor) {//Todo return idManager
) returns (uint64 idDonor) {
idDonor = uint64(managers.length);
@ -127,10 +127,10 @@ contract LiquidPledgingBase {
false,
plugin));
DeegateAdded(idDelegate);
DelegateAdded(idDelegate);
}
event DeegateAdded(uint64 indexed idDelegate);
event DelegateAdded(uint64 indexed idDelegate);
///@notice Changes the address, name or commitTime associated with a specific delegate
function updateDelegate(

View File

@ -42,6 +42,7 @@ describe('LiquidPledging test', () => {
let liquidPledging;
let vault;
let donor1;
let donor2;
let delegate1;
let adminProject1;
let adminProject2;
@ -57,10 +58,11 @@ describe('LiquidPledging test', () => {
adminProject2 = accounts[4];
adminProject2a = accounts[5];
delegate2 = accounts[6];
donor2 = accounts[7];
done();
});
});
it('Should deploy LiquidPledgin contract', async () => {
it('Should deploy LiquidPledging contract', async () => {
vault = await Vault.new(web3);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5200000 });
await vault.setLiquidPledging(liquidPledging.$address);
@ -300,4 +302,16 @@ describe('LiquidPledging test', () => {
assert.equal(collected, 0.95);
}).timeout(8000);
it('Should make a donation and create donor', async () => {
await liquidPledging.donate(0, 1, { from: donor2, value: web3.toWei(1) });
const nNotes = await liquidPledging.numberOfNotes();
assert.equal(nNotes.toNumber(), 14);
const nManagers = await liquidPledging.numberOfNoteManagers();
assert.equal(nManagers.toNumber(), 7);
const res = await liquidPledging.getNoteManager(7);
assert.equal(res[0], 0); // Donor
assert.equal(res[1], donor2);
assert.equal(res[2], '');
assert.equal(res[3], 259200); // default to 3 day commitTime
}).timeout(6000);
});