Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
createProject tested
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Apr 9, 2017
1 parent e196cfe commit 18b9abc
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 81 deletions.
7 changes: 5 additions & 2 deletions contracts/ProjectController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract ProjectController is Owned {
startHour = 0;
endHour = 86400;
topThreshold = maxTopThreshold;
bottomThreshold = 0;
bottomThreshold = maxTopThreshold/10;
whiteListTimelock = minWhiteListTimelock;
}

Expand Down Expand Up @@ -188,13 +188,13 @@ contract ProjectController is Owned {
_minWhiteListTimelock
));

pc.initialize();

childProjects[childProjects.length ++] = pc;
addr2project[address(pc)] = childProjects.length;

NewProject(childProjects.length -1);

pc.initialize();
pc.changeOwner(_admin);

return childProjects.length;
Expand Down Expand Up @@ -283,6 +283,8 @@ contract ProjectController is Owned {
/// @notice `onlyOwnerOrProjectAdmin` Requests to Fill up the specified project's vault
/// to the topThreshold from th `mainVault`

uint public test1;

function refillMe() {
if (canceled) throw;
uint idProject = addr2project[msg.sender];
Expand Down Expand Up @@ -476,6 +478,7 @@ contract ProjectController is Owned {
86400 + endHour - startHour;

if (canceled) return false;

// Resets the daily transfer counters
if (dayOfLastTx < actualDay) {
accTxsInDay = 0;
Expand Down
14 changes: 7 additions & 7 deletions contracts/ProjectController.sol.js

Large diffs are not rendered by default.

77 changes: 59 additions & 18 deletions dist/projectcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var _lodash = require("lodash");

var _lodash2 = _interopRequireDefault(_lodash);

var _vaultcontract = require("vaultcontract");

var _vaultcontract2 = _interopRequireDefault(_vaultcontract);

var _runethtx = require("runethtx");

var _ProjectControllerSol = require("../contracts/ProjectController.sol.js");
Expand All @@ -36,47 +40,82 @@ var ProjectController = function () {
var _this = this;

return (0, _runethtx.asyncfunc)(function (cb) {
var st = {};
var st = {
address: _this.contract.address
};
var nProjects = void 0;
_async2.default.series([function (cb1) {
_this.contract.name(function (err, _name) {
if (err) {
cb1(err);return;
}
st.name = _name;
cb1();
});
}, function (cb1) {
_this.contract.owner(function (err, _owner) {
if (err) {
cb(err);return;
cb1(err);return;
}
st.owner = _owner;
cb1();
});
}, function (cb1) {
_this.contract.mainVault(function (err, _mainVault) {
if (err) {
cb(err);return;
cb1(err);return;
}
st.mainVault = _mainVault;
cb1();
});
}, function (cb1) {
var vault = new _vaultcontract2.default(_this.web3, st.mainVault);
vault.getState(function (err, _st) {
if (err) {
cb1(err);return;
}
st.mainVault = _st;
cb1();
});
}, function (cb1) {
_this.contract.topThreshold(function (err, _topThreshold) {
if (err) {
cb1(err);return;
}
st.topThreshold = _topThreshold;
cb1();
});
}, function (cb1) {
_this.contract.bottomThreshold(function (err, _bottomThreshold) {
if (err) {
cb1(err);return;
}
st.bottomThreshold = _bottomThreshold;
cb1();
});
}, function (cb1) {
_this.contract.numberOfProjects(function (err, res) {
if (err) {
cb(err);return;
cb1(err);return;
}
nProjects = res.toNumber();
st.projects = [];
cb1();
});
}, function (cb1) {
_async2.default.eachSeries(_lodash2.default.range(0, nProjects), function (idProject, cb2) {
_this.contract.getProject(idProject, function (err, res) {
_this.contract.childProjects(idProject, function (err, addrChildProject) {
if (err) {
cb(err);return;
cb1(err);return;
}
st.projects.push({
idProject: idProject,
name: res[0],
admin: res[1],
vault: res[2],
balance: res[3]
var childProject = new ProjectController(_this.web3, addrChildProject);
childProject.getState(function (err2, _st) {
if (err2) {
cb2(err2);return;
}
st.projects.push(_st);
cb2();
});
cb2();
});
}, cb1);
}], function (err) {
Expand All @@ -87,18 +126,20 @@ var ProjectController = function () {
});
}, _cb);
}
}, {
key: "createProject",
value: function createProject(opts, cb) {
return (0, _runethtx.sendContractTx)(this.web3, this.contract, "createProject", opts, cb);
}
}, {
key: "initialize",
value: function initialize(opts, cb) {
return (0, _runethtx.sendContractTx)(this.web3, this.contract, "initialize", Object.assign({}, opts, {
extraGas: 250000
}), cb);
}
}, {
key: "createProject",
value: function createProject(opts, cb) {
return (0, _runethtx.sendContractTx)(this.web3, this.contract, "createProject", Object.assign({}, opts, {
gas: 4400000
}), cb);
}
}], [{
key: "deploy",
value: function deploy(web3, opts, _cb) {
Expand Down
70 changes: 51 additions & 19 deletions js/projectcontroller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import async from "async";
import _ from "lodash";
import Vault from "vaultcontract";
import { deploy, sendContractTx, asyncfunc } from "runethtx";
import { ProjectControllerAbi, ProjectControllerByteCode, ProjectControllerFactoryAbi, ProjectControllerFactoryByteCode, VaultFactoryAbi, VaultFactoryByteCode } from "../contracts/ProjectController.sol.js";

Expand All @@ -12,43 +13,72 @@ export default class ProjectController {

getState(_cb) {
return asyncfunc((cb) => {
const st = {};
const st = {
address: this.contract.address,
};
let nProjects;
async.series([
(cb1) => {
this.contract.name((err, _name) => {
if (err) { cb1(err); return; }
st.name = _name;
cb1();
});
},
(cb1) => {
this.contract.owner((err, _owner) => {
if (err) { cb(err); return; }
if (err) { cb1(err); return; }
st.owner = _owner;
cb1();
});
},
(cb1) => {
this.contract.mainVault((err, _mainVault) => {
if (err) { cb(err); return; }
if (err) { cb1(err); return; }
st.mainVault = _mainVault;
cb1();
});
},
(cb1) => {
const vault = new Vault(this.web3, st.mainVault);
vault.getState((err, _st) => {
if (err) { cb1(err); return; }
st.mainVault = _st;
cb1();
});
},
(cb1) => {
this.contract.topThreshold((err, _topThreshold) => {
if (err) { cb1(err); return; }
st.topThreshold = _topThreshold;
cb1();
});
},
(cb1) => {
this.contract.bottomThreshold((err, _bottomThreshold) => {
if (err) { cb1(err); return; }
st.bottomThreshold = _bottomThreshold;
cb1();
});
},
(cb1) => {
this.contract.numberOfProjects((err, res) => {
if (err) { cb(err); return; }
if (err) { cb1(err); return; }
nProjects = res.toNumber();
st.projects = [];
cb1();
});
},
(cb1) => {
async.eachSeries(_.range(0, nProjects), (idProject, cb2) => {
this.contract.getProject(idProject, (err, res) => {
if (err) { cb(err); return; }
st.projects.push({
idProject,
name: res[ 0 ],
admin: res[ 1 ],
vault: res[ 2 ],
balance: res[ 3 ],
this.contract.childProjects(idProject, (err, addrChildProject) => {
if (err) { cb1(err); return; }
const childProject = new ProjectController(this.web3, addrChildProject);
childProject.getState((err2, _st) => {
if (err2) { cb2(err2); return; }
st.projects.push(_st);
cb2();
});
cb2();
});
}, cb1);
},
Expand All @@ -59,22 +89,24 @@ export default class ProjectController {
}, _cb);
}

createProject(opts, cb) {
initialize(opts, cb) {
return sendContractTx(
this.web3,
this.contract,
"createProject",
opts,
"initialize",
Object.assign({}, opts, {
extraGas: 250000,
}),
cb);
}

initialize(opts, cb) {
createProject(opts, cb) {
return sendContractTx(
this.web3,
this.contract,
"initialize",
"createProject",
Object.assign({}, opts, {
extraGas: 250000,
gas: 4700000,
}),
cb);
}
Expand Down
75 changes: 53 additions & 22 deletions js/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import ethConnector from "ethconnector";
import { deploy } from "../js/projectcontroller";
import async from "async";
import ProjectController from "../js/projectcontroller";

let owner;
let escapeHatchCaller;
let escapeHatchDestination;
let parentVault;
let admin;
let projectController;

ethConnector.init("testrpc", (err) => {
if (err) {
Expand All @@ -15,25 +18,53 @@ ethConnector.init("testrpc", (err) => {
escapeHatchCaller = ethConnector.accounts[ 1 ];
escapeHatchDestination = ethConnector.accounts[ 2 ];
parentVault = ethConnector.accounts[ 3 ];
deploy(ethConnector.web3, {
from: owner,
name: "Main Vault",
baseToken: 0,
escapeHatchCaller,
escapeHatchDestination,
parentProjectController: 0,
parentVault,
maxDailyLimit: ethConnector.web3.toWei(100),
maxDailyTransactions: 5,
maxTransactionLimit: ethConnector.web3.toWei(10),
maxTopThreshold: ethConnector.web3.toWei(500),
mintWhitelistTimelock: 86400,
verbose: true,
}, (err2, _projectBalancer) => {
if (err2) {
console.log(err2);
return;
}
console.log(_projectBalancer.contract.address);
});
admin = ethConnector.accounts[ 4 ];
async.series([
(cb) => {
ProjectController.deploy(ethConnector.web3, {
from: owner,
name: "Main Vault",
baseToken: 0,
escapeHatchCaller,
escapeHatchDestination,
parentProjectController: 0,
parentVault,
maxDailyLimit: ethConnector.web3.toWei(100),
maxDailyTransactions: 5,
maxTransactionLimit: ethConnector.web3.toWei(50),
maxTopThreshold: ethConnector.web3.toWei(500),
minWhiteListTimelock: 86400,
verbose: true,
}, (err2, _ProjectController) => {
if (err2) {
console.log(err2);
cb(err2);
return;
}
projectController = _ProjectController;
console.log(_ProjectController.contract.address);
cb();
});
},
(cb) => {
projectController.createProject({
name: "Project 1",
admin,
maxDailyLimit: ethConnector.web3.toWei(100),
maxDailyTransactions: 5,
maxTransactionLimit: ethConnector.web3.toWei(10),
maxTopThreshold: ethConnector.web3.toWei(500),
minWhiteListTimelock: 86400,
verbose: true,
}, (err2) => {
if (err2) {
console.log(err2);
cb(err2);
return;
}
console.log("Project Created!");
cb();
});
},
]);
});
Loading

0 comments on commit 18b9abc

Please sign in to comment.