Skip to content
Permalink
Browse files

Store receiver address and url for a project.

  • Loading branch information...
ilanolkies committed Mar 19, 2019
1 parent 7904b90 commit d4ba88277078f5e1d338b9620b294905ecadac5f
Showing with 35 additions and 6 deletions.
  1. +18 −3 contracts/DirectDonate.sol
  2. +17 −3 test/direct_donate.js
@@ -4,7 +4,13 @@ pragma solidity ^0.4.22;
contract DirectDonate {
address public owner;

string[] public projects;
Project[] public projects;

struct Project {
string name;
address receiver;
string url;
}

modifier onlyOwner () {
require(msg.sender == owner);
@@ -19,7 +25,16 @@ contract DirectDonate {
return projects.length;
}

function addProject (string projectName) public {
projects.push(projectName);
function addProject (string name, address receiver, string url) public {
Project memory project;
project.name = name;
project.receiver = receiver;
project.url = url;

projects.push(project);
}

function projectName (uint index) public view returns(string) {
return projects[index].name;
}
}
@@ -27,7 +27,7 @@ contract('DirectDonate', async (accounts) => {
it('should add a project', async () => {
const previousQuantity = await directDonate.projectIndex();

await directDonate.addProject('');
await directDonate.addProject('', '', '');

const projectQuantity = await directDonate.projectIndex();

@@ -37,10 +37,24 @@ contract('DirectDonate', async (accounts) => {
it('should add and return the project', async () => {
const projectName = 'NewProject';

await directDonate.addProject(projectName);
await directDonate.addProject(projectName, '', '');

const project = await directDonate.projects(0);
const project = await directDonate.projectName(0);

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/';

await directDonate.addProject(projectName, projectReceiver, projectUrl);

const project = await directDonate.projects(0);

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

0 comments on commit d4ba882

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