Skip to content
Permalink
Browse files

Transfer founds to receiver.

  • Loading branch information...
ilanolkies committed Mar 19, 2019
1 parent d4ba882 commit 0aa77a6e8fb7b396bacbcc81d3686de20ec8ef38
Showing with 28 additions and 5 deletions.
  1. +7 −1 contracts/DirectDonate.sol
  2. +21 −4 test/direct_donate.js
@@ -34,7 +34,13 @@ contract DirectDonate {
projects.push(project);
}

function projectName (uint index) public view returns(string) {
function projectName (uint index) public view returns (string) {
return projects[index].name;
}

function donate (uint index) public payable {
address receiver = projects[index].receiver;

receiver.transfer(msg.value);
}
}
@@ -44,17 +44,34 @@ contract('DirectDonate', async (accounts) => {
assert.equal(project, projectName);
});

it('should store the project\'s address and url', async () => {
const projectName = 'NewProject';
const projectReceiver = accounts[1];
const projectUrl = 'https://www.kklweb.org/';
const projectName = 'NewProject';
const projectReceiver = accounts[1];
const projectUrl = 'https://www.kklweb.org/';

const addProject = async () => {
await directDonate.addProject(projectName, projectReceiver, projectUrl);
}

it('should store the project\'s address and url', async () => {
await addProject();

const project = await directDonate.projects(0);

assert.equal(project[0], projectName);
assert.equal(project[1], projectReceiver);
assert.equal(project[2], projectUrl);
});

it('should send founds to receiver', async () => {
await addProject();

const previousBalance = await web3.eth.getBalance(accounts[1]);
const value = 10e18;

await directDonate.donate(0, { value });

const balance = await web3.eth.getBalance(accounts[1]);

assert.equal(balance, previousBalance.toNumber() + value);
});
});

0 comments on commit 0aa77a6

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