create donor on donate if donorId == 0

This commit is contained in:
perissology 2017-09-28 08:49:10 -07:00
parent 0a2251aae2
commit f01d174a56
3 changed files with 25 additions and 5 deletions

View File

@ -23,6 +23,10 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idReceiver To whom it's transfered. Can be the same donor, another /// @param idReceiver To whom it's transfered. Can be the same donor, another
/// donor, a delegate or a project /// donor, a delegate or a project
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()` function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
if (idDonor == 0) {
idDonor = addDonor('', 259200); // default to 3 day commitTime
}
NoteManager storage sender = findManager(idDonor); NoteManager storage sender = findManager(idDonor);
require(sender.managerType == NoteManagerType.Donor); require(sender.managerType == NoteManagerType.Donor);

View File

@ -67,7 +67,7 @@ contract LiquidPledgingBase {
// Managers functions // Managers functions
////// //////
function addDonor(string name, uint64 commitTime) {//Todo return idManager function addDonor(string name, uint64 commitTime) returns (uint64 idManager) {
managers.push(NoteManager( managers.push(NoteManager(
NoteManagerType.Donor, NoteManagerType.Donor,
msg.sender, msg.sender,
@ -76,7 +76,9 @@ contract LiquidPledgingBase {
0, 0,
false)); false));
DonorAdded(uint64(managers.length-1)); idManager = uint64(managers.length-1);
DonorAdded(idManager);
} }
event DonorAdded(uint64 indexed idDonor); event DonorAdded(uint64 indexed idDonor);
@ -107,10 +109,10 @@ contract LiquidPledgingBase {
0, 0,
false)); false));
DeegateAdded(uint64(managers.length-1)); DelegateAdded(uint64(managers.length-1));
} }
event DeegateAdded(uint64 indexed idDelegate); event DelegateAdded(uint64 indexed idDelegate);
function updateDelegate(uint64 idDelegate, address newAddr, string newName) { function updateDelegate(uint64 idDelegate, address newAddr, string newName) {
NoteManager storage delegate = findManager(idDelegate); NoteManager storage delegate = findManager(idDelegate);

View File

@ -42,6 +42,7 @@ describe('LiquidPledging test', () => {
let liquidPledging; let liquidPledging;
let vault; let vault;
let donor1; let donor1;
let donor2;
let delegate1; let delegate1;
let adminProject1; let adminProject1;
let adminProject2; let adminProject2;
@ -57,10 +58,11 @@ describe('LiquidPledging test', () => {
adminProject2 = accounts[4]; adminProject2 = accounts[4];
adminProject2a = accounts[5]; adminProject2a = accounts[5];
delegate2 = accounts[6]; delegate2 = accounts[6];
donor2 = accounts[7];
done(); done();
}); });
}); });
it('Should deploy LiquidPledgin 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); liquidPledging = await LiquidPledging.new(web3, vault.$address);
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
@ -300,4 +302,16 @@ describe('LiquidPledging test', () => {
assert.equal(collected, 0.95); assert.equal(collected, 0.95);
}).timeout(8000); }).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);
}); });