Skip to content

Commit 6343cc5

Browse files
authored
[WIP] More tests (#744)
* DAOfactory test coverage * lint * Update reputationfromtoken.js * vote in organization test * App tests * Fix voteinorganization * More controller tests
1 parent bd9aea7 commit 6343cc5

File tree

8 files changed

+304
-28
lines changed

8 files changed

+304
-28
lines changed

contracts/controller/Controller.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ contract Controller is Initializable {
329329
onlyUpgradingScheme
330330
returns(bool)
331331
{
332-
require(newController == address(0)); // so the upgrade could be done once for a contract.
333-
require(_newController != address(0));
332+
require(newController == address(0), "this controller was already upgraded"); // so the upgrade could be done once for a contract.
333+
require(_newController != address(0), "new controller cannot be 0");
334334
newController = _newController;
335335
avatar.transferOwnership(_newController);
336-
require(avatar.owner() == _newController);
336+
require(avatar.owner() == _newController, "failed to transfer avatar ownership to the new controller");
337337
if (nativeToken.owner() == address(this)) {
338338
nativeToken.transferOwnership(_newController);
339-
require(nativeToken.owner() == _newController);
339+
require(nativeToken.owner() == _newController, "failed to transfer token ownership to the new controller");
340340
}
341341
if (nativeReputation.owner() == address(this)) {
342342
nativeReputation.transferOwnership(_newController);
343-
require(nativeReputation.owner() == _newController);
343+
require(nativeReputation.owner() == _newController, "failed to transfer reputation ownership to the new controller");
344344
}
345345
emit UpgradeController(address(this), newController);
346346
return true;

contracts/utils/DAOFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ contract DAOFactory is Initializable {
9999
require(locks[address(_avatar)].sender == msg.sender, "sender is not holding the lock");
100100
// Mint token and reputation for founders:
101101
for (uint256 i = 0; i < _founders.length; i++) {
102-
require(_founders[i] != address(0));
102+
require(_founders[i] != address(0), "founder address cannot be 0");
103103
if (_foundersTokenAmount[i] > 0) {
104104
Controller(
105105
_avatar.owner()).mintTokens(_foundersTokenAmount[i], _founders[i]);

test/app.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,37 @@ contract('App', accounts => {
9090

9191
it("addVersion", async function() {
9292
await setup();
93-
var tx = await registration.packageInstance.addVersion([1,0,0],registration.implementationDirectory.address,helpers.NULL_HASH);
93+
var tx = await registration.packageInstance.addVersion([1,1,0],registration.implementationDirectory.address,helpers.NULL_HASH);
9494
assert.equal(tx.logs[0].event, "VersionAdded");
9595
assert.equal(tx.logs[0].args.semanticVersion[0], 1);
96+
97+
try {
98+
await registration.packageInstance.addVersion([1,2,0],helpers.NULL_ADDRESS,helpers.NULL_HASH);
99+
assert(false, "contract address cannot be 0");
100+
} catch(error) {
101+
helpers.assertVMException(error);
102+
}
103+
try {
104+
await registration.packageInstance.addVersion([1,1,0],registration.implementationDirectory.address,helpers.NULL_HASH);
105+
assert(false, "cannot register same version twice");
106+
} catch(error) {
107+
helpers.assertVMException(error);
108+
}
109+
try {
110+
await registration.packageInstance.addVersion([0,0,0],registration.implementationDirectory.address,helpers.NULL_HASH);
111+
assert(false, "version cannot be 0");
112+
} catch(error) {
113+
helpers.assertVMException(error);
114+
}
115+
116+
tx = await registration.packageInstance.addVersion([1,0,0],registration.implementationDirectory.address,helpers.NULL_HASH);
117+
assert.equal(tx.logs[0].event, "VersionAdded");
118+
assert.equal(tx.logs[0].args.semanticVersion[0], 1);
119+
assert.equal(tx.logs[0].args.semanticVersion[1], 0);
120+
121+
let latest = await registration.packageInstance.getLatest();
122+
assert.equal(latest.semanticVersion[0], 1);
123+
assert.equal(latest.semanticVersion[1], 1);
124+
assert.equal(latest.semanticVersion[2], 0);
96125
});
97126
});

test/controller.js

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ contract('Controller', accounts => {
6262
assert.equal(rep,amountToMint);
6363
});
6464

65+
it("mint reputation - only registered scheme", async () => {
66+
controller = await setup(accounts);
67+
await reputation.transferOwnership(controller.address);
68+
try {
69+
await controller.mintReputation(amountToMint,accounts[0],{from:accounts[1]});
70+
assert(false, 'only registered scheme can mint reputation');
71+
} catch (ex) {
72+
helpers.assertVMException(ex);
73+
}
74+
});
75+
6576
it("burn reputation via controller", async () => {
6677
controller = await setup(accounts);
6778
await reputation.transferOwnership(controller.address);
@@ -214,6 +225,17 @@ contract('Controller', accounts => {
214225
assert.equal(count[0], 1); //pre
215226
assert.equal(count[1], 1); //post
216227
});
228+
229+
it("globalConstraint - cannot register without sufficient permissions", async () => {
230+
controller = await setup(accounts, "0x00000001");
231+
try {
232+
await controller.addGlobalConstraint(helpers.NULL_ADDRESS);
233+
assert(false, 'only scheme with sufficient permission can add global constraint');
234+
} catch (ex) {
235+
helpers.assertVMException(ex);
236+
}
237+
});
238+
217239
it("removeGlobalConstraint ", async () => {
218240
const zeroBytes32 = "0x0000000000000000000000000000000000000000";
219241
controller = await setup(accounts);
@@ -255,11 +277,43 @@ contract('Controller', accounts => {
255277
assert.equal(gcCount[1],3);
256278
});
257279

258-
it("upgrade controller ", async () => {
280+
it("upgrade controller", async () => {
259281
controller = await setup(accounts);
260282
await reputation.transferOwnership(controller.address);
261283
await token.transferOwnership(controller.address);
284+
285+
try {
286+
await controller.upgradeController(accounts[1]);
287+
assert(false, 'cannot upgrade controller if it does not ow the avatar');
288+
} catch (ex) {
289+
helpers.assertVMException(ex);
290+
}
291+
262292
await avatar.transferOwnership(controller.address);
293+
294+
try {
295+
await controller.upgradeController(helpers.NULL_ADDRESS);
296+
assert(false, 'new controller cannot be 0');
297+
} catch (ex) {
298+
helpers.assertVMException(ex);
299+
}
300+
301+
var tx = await controller.upgradeController(accounts[1]);
302+
assert.equal(tx.logs.length, 1);
303+
assert.equal(tx.logs[0].event, "UpgradeController");
304+
305+
try {
306+
await controller.upgradeController(accounts[2]);
307+
assert(false, 'cannot upgrade twice the same controller contract');
308+
} catch (ex) {
309+
helpers.assertVMException(ex);
310+
}
311+
});
312+
313+
it("upgrade controller - no native token and reputation", async () => {
314+
controller = await setup(accounts);
315+
await avatar.transferOwnership(controller.address);
316+
263317
var tx = await controller.upgradeController(accounts[1]);
264318
assert.equal(tx.logs.length, 1);
265319
assert.equal(tx.logs[0].event, "UpgradeController");
@@ -310,6 +364,22 @@ contract('Controller', accounts => {
310364
assert.equal(result[1], 14);
311365
});
312366

367+
it("generic call - only generic call scheme", async () => {
368+
controller = await setup(accounts,'0x00000001');
369+
await avatar.transferOwnership(controller.address);
370+
let actionMock = await ActionMock.new();
371+
let a = 7;
372+
let b = actionMock.address;
373+
let c = "0x1234";
374+
const encodeABI = await new web3.eth.Contract(actionMock.abi).methods.test(a,b,c).encodeABI();
375+
try {
376+
await controller.genericCall.call(actionMock.address,encodeABI,0);
377+
assert(false, 'only registered scheme can mint reputation');
378+
} catch (ex) {
379+
helpers.assertVMException(ex);
380+
}
381+
});
382+
313383
it("generic call withoutReturnValue", async () => {
314384
controller = await setup(accounts,'0x00000010');
315385
await avatar.transferOwnership(controller.address);
@@ -623,5 +693,14 @@ contract('Controller', accounts => {
623693

624694
});
625695

626-
696+
it("metaData - cannot set metaData without sufficient permissions", async () => {
697+
controller = await setup(accounts, "0x00000001");
698+
await avatar.transferOwnership(controller.address);
699+
try {
700+
await controller.metaData('newMetadata');
701+
assert(false, 'only scheme with sufficient permission can set metadata');
702+
} catch (ex) {
703+
helpers.assertVMException(ex);
704+
}
705+
});
627706
});

test/daofactory.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ contract('DaoFactory', function(accounts) {
228228
helpers.assertVMException(ex);
229229
}
230230

231+
try {
232+
await registration.daoFactory.forgeOrg("testOrg",nativeTokenData,[accounts[0]],[],[11],[0,0,0],{gas:constants.ARC_GAS_LIMIT});
233+
assert(false,"should revert because token array size is 0");
234+
}
235+
catch(ex){
236+
helpers.assertVMException(ex);
237+
}
238+
231239
try {
232240
await registration.daoFactory.forgeOrg("testOrg",
233241
nativeTokenData,[accounts[0],
@@ -236,7 +244,7 @@ contract('DaoFactory', function(accounts) {
236244
[amountToMint,amountToMint],
237245
[0,0,0],
238246
{gas:constants.ARC_GAS_LIMIT});
239-
assert(false,"should revert because account is 0");
247+
assert(false,"should revert because account is 0");
240248
}
241249
catch(ex){
242250
helpers.assertVMException(ex);
@@ -287,6 +295,63 @@ contract('DaoFactory', function(accounts) {
287295
assert.equal(tx.logs[2].args._avatar, avatar.address);
288296
});
289297

298+
299+
it("setSchemes to SchemeMock and addFounders wrong lengths", async function() {
300+
var amountToMint = 10;
301+
await setup(accounts,amountToMint,amountToMint);
302+
var foundersArray = [];
303+
var founderReputation = [];
304+
var founderToken = [];
305+
306+
try {
307+
await registration.daoFactory.addFounders(avatar.address,foundersArray,founderReputation,founderToken,{gas:constants.ARC_GAS_LIMIT});
308+
assert(false, "should revert because founders list is empty");
309+
}
310+
catch(ex){
311+
helpers.assertVMException(ex);
312+
}
313+
314+
var i;
315+
var numberOfFounders = 60;
316+
for (i=0;i<numberOfFounders;i++) {
317+
foundersArray[i] = accounts[1];
318+
founderReputation[i] = 1;
319+
founderToken[i] = 1;
320+
321+
}
322+
founderToken[i] = 1;
323+
try {
324+
await registration.daoFactory.addFounders(avatar.address,foundersArray,founderReputation,founderToken,{gas:constants.ARC_GAS_LIMIT});
325+
assert(false, "should revert because founders list is shorter than tokens");
326+
} catch(ex) {
327+
helpers.assertVMException(ex);
328+
}
329+
founderToken.pop();
330+
founderReputation[i] = 1;
331+
try {
332+
await registration.daoFactory.addFounders(avatar.address,foundersArray,founderReputation,founderToken,{gas:constants.ARC_GAS_LIMIT});
333+
assert(false, "should revert because founders list is shorter than reputations");
334+
} catch(ex) {
335+
helpers.assertVMException(ex);
336+
}
337+
founderReputation.pop();
338+
foundersArray[i-1] = helpers.NULL_ADDRESS;
339+
try {
340+
await registration.daoFactory.addFounders(avatar.address,foundersArray,founderReputation,founderToken,{gas:constants.ARC_GAS_LIMIT});
341+
assert(false, "should revert because founder address cannot be 0");
342+
} catch(ex) {
343+
helpers.assertVMException(ex);
344+
}
345+
foundersArray[i-1] = accounts[1];
346+
founderReputation[i-1] = 0;
347+
founderToken[i-1] = 0;
348+
await registration.daoFactory.addFounders(avatar.address,foundersArray,founderReputation,founderToken,{gas:constants.ARC_GAS_LIMIT});
349+
var rep = await reputation.balanceOf(accounts[1],{from:accounts[1]});
350+
assert.equal(rep.toNumber(),numberOfFounders - 1);
351+
var founderBalance = await daoToken.balanceOf(accounts[1],{from:accounts[1]});
352+
assert.equal(founderBalance.toNumber(),numberOfFounders - 1);
353+
});
354+
290355
it("forgeOrg different version", async function() {
291356
var amountToMint = 10;
292357
await setup(accounts,amountToMint,amountToMint);

test/reputationfromtoken.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ contract('ReputationFromToken and RepAllocation', accounts => {
192192
assert.equal(tx.logs[0].args._sender,accounts[0]);
193193
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
194194
assert.equal(await testSetup.org.reputation.balanceOf(accounts[1]),expected);
195+
196+
try {
197+
await testSetup.reputationFromToken.redeem(accounts[1]);
198+
assert(false, "cannot redeem twice");
199+
} catch(error) {
200+
helpers.assertVMException(error);
201+
}
195202
});
196203

197204
it("redeemWithSignature", async () => {
@@ -225,6 +232,16 @@ contract('ReputationFromToken and RepAllocation', accounts => {
225232
assert.equal(await testSetup.org.reputation.balanceOf(accounts[1]),0);
226233
});
227234

235+
it("cannot redeem before initialize", async () => {
236+
try {
237+
let reputationFromToken = await ReputationFromToken.new();
238+
await reputationFromToken.redeem(accounts[1]);
239+
assert(false, "cannot redeem before initialize");
240+
} catch(error) {
241+
helpers.assertVMException(error);
242+
}
243+
});
244+
228245
it("cannot initialize twice", async () => {
229246
let testSetup = await setup(accounts);
230247
try {

test/schemeregistrar.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ contract('SchemeRegistrar', accounts => {
109109
assert.equal(tx.logs[0].event, "RemoveSchemeProposal");
110110
});
111111

112+
it("proposeScheme cannot be 0", async function() {
113+
var testSetup = await setup(accounts);
114+
try {
115+
await testSetup.schemeRegistrar.proposeScheme(
116+
helpers.NULL_ADDRESS,
117+
"0x00000000",
118+
helpers.NULL_HASH);
119+
} catch(ex) {
120+
helpers.assertVMException(ex);
121+
}
122+
});
123+
124+
it("proposeToRemoveScheme cannot be 0", async function() {
125+
var testSetup = await setup(accounts);
126+
try {
127+
await testSetup.schemeRegistrar.proposeToRemoveScheme(helpers.NULL_ADDRESS, helpers.NULL_HASH);
128+
} catch(ex) {
129+
helpers.assertVMException(ex);
130+
}
131+
});
112132

113133
it("execute proposeScheme and execute -yes - fee > 0 ", async function() {
114134
var testSetup = await setup(accounts);

0 commit comments

Comments
 (0)