Skip to content
Permalink
Browse files

List donors for porjects

  • Loading branch information...
ilanolkies committed Mar 19, 2019
1 parent 0c10ccd commit 3acdceabb77b3dbfcfd4c29776c1aca4d302cc6c
Showing with 30 additions and 1 deletion.
  1. +11 −1 contracts/DirectDonate.sol
  2. +19 −0 test/direct_donate.js
@@ -10,6 +10,7 @@ contract DirectDonate {
string name;
address receiver;
string url;
address[] donors;
}

modifier onlyOwner () {
@@ -30,6 +31,8 @@ contract DirectDonate {
project.name = name;
project.receiver = receiver;
project.url = url;
address[] memory donors;
project.donors = donors;

projects.push(project);
}
@@ -39,8 +42,15 @@ contract DirectDonate {
}

function donate (uint index) public payable {
address receiver = projects[index].receiver;
Project storage project = projects[index];
address receiver = project.receiver;
project.donors.push(msg.sender);

receiver.transfer(msg.value);
}

function donors (uint index) public view returns (address[] memory) {
Project storage project = projects[index];
return project.donors;
}
}
@@ -118,4 +118,23 @@ contract('DirectDonate', async (accounts) => {
assert.equal(balance, previousBalance.toNumber() + value);
}
});

it('should return project\'s donors', async () => {
await addProject();

await directDonate.donate(0, { from: accounts[2], value: 1e18 });

var donors = await directDonate.donors(0);

assert.equal(donors.length, 1);
assert.equal(donors[0], accounts[2]);

await directDonate.donate(0, { from: accounts[3], value: 1e18 });

donors = await directDonate.donors(0);

assert.equal(donors.length, 2);
assert.equal(donors[0], accounts[2]);
assert.equal(donors[1], accounts[3]);
});
});

0 comments on commit 3acdcea

Please sign in to comment.
You can’t perform that action at this time.