create donor on donate if donorId == 0
This commit is contained in:
parent
0a2251aae2
commit
f01d174a56
|
@ -23,6 +23,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// @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 {// TODO change to `pledge()`
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
|
||||
require(sender.managerType == NoteManagerType.Donor);
|
||||
|
|
|
@ -67,7 +67,7 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
function addDonor(string name, uint64 commitTime) {//Todo return idManager
|
||||
function addDonor(string name, uint64 commitTime) returns (uint64 idManager) {
|
||||
managers.push(NoteManager(
|
||||
NoteManagerType.Donor,
|
||||
msg.sender,
|
||||
|
@ -76,7 +76,9 @@ contract LiquidPledgingBase {
|
|||
0,
|
||||
false));
|
||||
|
||||
DonorAdded(uint64(managers.length-1));
|
||||
idManager = uint64(managers.length-1);
|
||||
|
||||
DonorAdded(idManager);
|
||||
}
|
||||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
|
@ -107,10 +109,10 @@ contract LiquidPledgingBase {
|
|||
0,
|
||||
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) {
|
||||
NoteManager storage delegate = findManager(idDelegate);
|
||||
|
|
|
@ -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);
|
||||
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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue