Skip to content

Commit fa1bb3d

Browse files
committed
Extra tests, mostly around permissions
1 parent d687576 commit fa1bb3d

7 files changed

Lines changed: 68 additions & 1 deletion

File tree

contracts/common/DomainReceiverManagement.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ abstract contract DomainReceiverManagement is MetaTransactionMsgSender, IsContra
3737
function checkDomainTokenReceiverDeployed(
3838
uint256 _domainId
3939
) public returns (address domainTokenReceiverAddress) {
40-
require(msgSenderIsColony(), "colony-domain-receiver-management-not-colony");
4140
require(!isStopped(), "colony-domain-receiver-management-stopped");
41+
require(msgSenderIsColony(), "colony-domain-receiver-management-not-colony");
4242

4343
// Calculate the address the domain should be receiving funds at
4444
domainTokenReceiverAddress = getDomainTokenReceiverAddress(msgSender(), _domainId);

test/contracts-network/colony-arbitrary-transactions.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ contract("Colony Arbitrary Transactions", (accounts) => {
4848
expect(balancePost.sub(balancePre)).to.eq.BN(WAD);
4949
});
5050

51+
it("makeSingleArbitraryTransaction can only be called by the colony on itself", async () => {
52+
const action = await encodeTxData(token, "mint", [WAD]);
53+
await checkErrorRevert(colony.makeSingleArbitraryTransaction(token.address, action, { from: USER0 }), "colony-not-self");
54+
});
55+
56+
it("makeArbitraryTransactions must be called with the same number of addresses and actions", async () => {
57+
const action = await encodeTxData(token, "mint", [WAD]);
58+
await checkErrorRevert(
59+
colony.makeArbitraryTransactions([token.address, token.address], [action], true),
60+
"colony-targets-and-actions-length-mismatch",
61+
);
62+
});
63+
5164
it("should be able to make multiple arbitrary transactions", async () => {
5265
const action = await encodeTxData(token, "mint", [WAD]);
5366
const action2 = await encodeTxData(token, "mint", [WAD.muln(2)]);

test/contracts-network/colony-expenditure.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ contract("Colony Expenditure", (accounts) => {
234234

235235
it("should allow arbitrators to update the metadata", async () => {
236236
const setExpenditureMetadata = colony.methods["setExpenditureMetadata(uint256,uint256,uint256,string)"];
237+
238+
// Try with a bad proof
239+
await checkErrorRevert(setExpenditureMetadata(1, 0, expenditureId, IPFS_HASH, { from: ARBITRATOR }), "ds-auth-invalid-domain-inheritance");
240+
237241
const tx = await setExpenditureMetadata(1, UINT256_MAX, expenditureId, IPFS_HASH, { from: ARBITRATOR });
238242

239243
await expectEvent(tx, "ExpenditureMetadataSet", [ARBITRATOR, expenditureId, IPFS_HASH]);
@@ -588,6 +592,15 @@ contract("Colony Expenditure", (accounts) => {
588592
await checkErrorRevert(colony.finalizeExpenditure(expenditureId, { from: ADMIN }), "colony-expenditure-not-draft-or-locked");
589593
});
590594

595+
it("should not allow expenditures to be finalized if they are not fully funded", async () => {
596+
await colony.setExpenditurePayout(expenditureId, SLOT0, token.address, WAD, { from: ADMIN });
597+
await checkErrorRevert(colony.finalizeExpenditure(expenditureId, { from: ADMIN }), "colony-expenditure-not-funded");
598+
await checkErrorRevert(
599+
colony.finalizeExpenditureViaArbitration(1, UINT256_MAX, expenditureId, { from: ARBITRATOR }),
600+
"colony-expenditure-not-funded",
601+
);
602+
});
603+
591604
it("should allow owners to finalize expenditures from locked state", async () => {
592605
await colony.lockExpenditure(expenditureId, { from: ADMIN });
593606

test/contracts-network/colony-network-recovery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ contract("Colony Network Recovery", (accounts) => {
197197
await checkErrorRevert(colonyNetwork.bridgeMessage(1, "0x00000000"), "colony-in-recovery-mode");
198198
await checkErrorRevert(colonyNetwork.bridgeMessageToNetwork(1, "0x00000000"), "colony-in-recovery-mode");
199199
await checkErrorRevert(colonyNetwork.createProxyColony(1, HASHZERO), "colony-in-recovery-mode");
200+
await checkErrorRevert(colonyNetwork.checkDomainTokenReceiverDeployed(1), "colony-domain-receiver-management-stopped");
200201

201202
await colonyNetwork.approveExitRecovery();
202203
await colonyNetwork.exitRecoveryMode();

test/contracts-network/colony-recovery.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,24 @@ contract("Colony Recovery", (accounts) => {
197197
await checkErrorRevert(metaColony.claimExpenditurePayout(0, 0, ADDRESS_ZERO), "colony-in-recovery-mode");
198198
await checkErrorRevert(metaColony.moveFundsBetweenPots(0, 0, 0, 0, 0, 0, 0, 0, ADDRESS_ZERO), "colony-in-recovery-mode");
199199
await checkErrorRevert(metaColony.moveFundsBetweenPots(0, 0, 0, 0, 0, 0, ADDRESS_ZERO), "colony-in-recovery-mode");
200+
await checkErrorRevert(metaColony.moveFundsBetweenPots(0, 0, 0, 0, 0, 0, 0, 0, 0, ADDRESS_ZERO), "colony-in-recovery-mode");
200201
await checkErrorRevert(metaColony.claimColonyFunds(ADDRESS_ZERO), "colony-in-recovery-mode");
201202
await checkErrorRevert(metaColony.startNextRewardPayout(ADDRESS_ZERO, HASHZERO, HASHZERO, 0, []), "colony-in-recovery-mode");
202203
await checkErrorRevert(metaColony.claimRewardPayout(0, [0, 0, 0, 0, 0, 0, 0], HASHZERO, HASHZERO, 0, []), "colony-in-recovery-mode");
203204
await checkErrorRevert(metaColony.setRewardInverse(0), "colony-in-recovery-mode");
204205
await checkErrorRevert(metaColony.setExpenditurePayouts(0, [], ADDRESS_ZERO, []), "colony-in-recovery-mode");
205206
await checkErrorRevert(metaColony.setExpenditurePayout(0, 0, ADDRESS_ZERO, 0), "colony-in-recovery-mode");
206207
await checkErrorRevert(metaColony.setExpenditurePayout(1, UINT256_MAX, 0, 0, ADDRESS_ZERO, 0), "colony-in-recovery-mode");
208+
await checkErrorRevert(metaColony.setExpenditureSkill(1, 1, 1), "colony-in-recovery-mode");
207209
await checkErrorRevert(metaColony.enterRecoveryMode(), "colony-in-recovery-mode");
208210
await checkErrorRevert(metaColony.burnTokens(ADDRESS_ZERO, 0), "colony-in-recovery-mode");
209211
await checkErrorRevert(metaColony.registerColonyLabel("", ""), "colony-in-recovery-mode");
210212
await checkErrorRevert(metaColony.updateColonyOrbitDB(""), "colony-in-recovery-mode");
211213
await checkErrorRevert(metaColony.makeArbitraryTransaction(ADDRESS_ZERO, HASHZERO), "colony-in-recovery-mode");
212214
await checkErrorRevert(metaColony.makeArbitraryTransactions([], [], true), "colony-in-recovery-mode");
213215
await checkErrorRevert(metaColony.makeSingleArbitraryTransaction(ADDRESS_ZERO, HASHZERO), "colony-in-recovery-mode");
216+
await checkErrorRevert(metaColony.makeProxyArbitraryTransactions(1, [], []), "colony-in-recovery-mode");
217+
await checkErrorRevert(metaColony.callProxyNetwork(1, []), "colony-in-recovery-mode");
214218
await checkErrorRevert(metaColony.updateApprovalAmount(ADDRESS_ZERO, ADDRESS_ZERO), "colony-in-recovery-mode");
215219
await checkErrorRevert(metaColony.finalizeRewardPayout(1), "colony-in-recovery-mode");
216220
});

test/contracts-network/colony.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
expectAllEvents,
1414
expectEvent,
1515
upgradeColonyOnceThenToLatest,
16+
bn2bytes32,
1617
} = require("../../helpers/test-helper");
1718
const {
1819
setupRandomColony,
@@ -216,6 +217,14 @@ contract("Colony", (accounts) => {
216217
await expectEvent(tx, "FundingPotAdded", [fundingPotCount]);
217218
await expectEvent(tx, "DomainMetadata", [accounts[0], domainCount, IPFS_HASH]);
218219
});
220+
221+
it("should require a valid permission proof", async () => {
222+
await colony.addDomain(1, UINT256_MAX, 1);
223+
224+
// Remove permission
225+
await colony.setUserRoles(1, UINT256_MAX, USER0, 1, bn2bytes32(0));
226+
await checkErrorRevert(colony.addDomain(1, UINT256_MAX, 1), "ds-auth-unauthorized");
227+
});
219228
});
220229

221230
describe("when editing domains", () => {
@@ -229,6 +238,15 @@ contract("Colony", (accounts) => {
229238
await colony.addDomain(1, UINT256_MAX, 1);
230239
await expectNoEvent(colony.editDomain(1, 0, 2, ""), "DomainMetadata");
231240
});
241+
242+
it("should require a valid permission proof", async () => {
243+
await colony.addDomain(1, UINT256_MAX, 1);
244+
await colony.editDomain(1, 0, 2, IPFS_HASH);
245+
246+
// Remove permission
247+
await colony.setUserRoles(1, UINT256_MAX, USER0, 1, bn2bytes32(0));
248+
await checkErrorRevert(colony.editDomain(1, 0, 2, IPFS_HASH), "ds-auth-unauthorized");
249+
});
232250
});
233251

234252
describe.skip("when deprecating domains", () => {

test/cross-chain/cross-chain.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,17 @@ contract("Cross-chain", (accounts) => {
927927
expect(balanceAfter.sub(balanceBefore).toHexString()).to.equal(ethers.utils.parseEther("100").toHexString());
928928
});
929929

930+
it("root permissions are required for makeProxyArbitraryTransactions", async () => {
931+
const p = guardianSpy.getPromiseForNextBridgedTransaction();
932+
let tx = await colony.makeProxyArbitraryTransactions(foreignChainId, [foreignToken.address], ["0x00000000"]);
933+
await tx.wait();
934+
await p;
935+
936+
await colony.setUserRoles(1, UINT256_MAX_ETHERS, accounts[0], 1, ethers.utils.hexZeroPad("0x00", 32));
937+
tx = await colony.makeProxyArbitraryTransactions(foreignChainId, [foreignToken.address], ["0x00000000"], { gasLimit: 1000000 });
938+
await checkErrorRevertEthers(tx.wait(), "ds-auth-unauthorized");
939+
});
940+
930941
it("arbitrary transactions on the foreign chain must go to contracts", async () => {
931942
const p = guardianSpy.getPromiseForNextBridgedTransaction();
932943

@@ -1079,6 +1090,13 @@ contract("Cross-chain", (accounts) => {
10791090
});
10801091
});
10811092

1093+
describe("ColonyNetwork functions are secure", async () => {
1094+
it("a non-colony address cannot call bridgeMessage", async () => {
1095+
const tx = await homeColonyNetwork.bridgeMessage(1, HASHZERO, { gasLimit: 1000000 });
1096+
await checkErrorRevertEthers(tx.wait(), "colony-caller-must-be-colony");
1097+
});
1098+
});
1099+
10821100
describe("Invalid interactions with bridging system are handled appropriately", async () => {
10831101
it("Can't bridge to a chain that's not supported", async () => {
10841102
const tx = await homeColony.makeProxyArbitraryTransactions(111, [ADDRESS_ZERO], ["0x00000000"], { gasLimit: 1000000 });

0 commit comments

Comments
 (0)