Skip to content
Permalink
Browse files

List donations for projects

  • Loading branch information...
ilanolkies committed Mar 19, 2019
1 parent 3acdcea commit 93d2707b93dbe0250089ffe732644c2a60711aca
Showing with 21 additions and 0 deletions.
  1. +9 −0 contracts/DirectDonate.sol
  2. +12 −0 test/direct_donate.js
@@ -11,6 +11,7 @@ contract DirectDonate {
address receiver;
string url;
address[] donors;
uint[] donations;
}

modifier onlyOwner () {
@@ -33,6 +34,8 @@ contract DirectDonate {
project.url = url;
address[] memory donors;
project.donors = donors;
uint[] memory donations;
project.donations = donations;

projects.push(project);
}
@@ -45,6 +48,7 @@ contract DirectDonate {
Project storage project = projects[index];
address receiver = project.receiver;
project.donors.push(msg.sender);
project.donations.push(msg.value);

receiver.transfer(msg.value);
}
@@ -53,4 +57,9 @@ contract DirectDonate {
Project storage project = projects[index];
return project.donors;
}

function donations (uint index) public view returns (uint[] memory) {
Project storage project = projects[index];
return project.donations;
}
}
@@ -137,4 +137,16 @@ contract('DirectDonate', async (accounts) => {
assert.equal(donors[0], accounts[2]);
assert.equal(donors[1], accounts[3]);
});

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

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

var donations = await directDonate.donations(0);

assert.equal(donations.length, 1);
assert.equal(donations[0], value);
});
});

0 comments on commit 93d2707

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