Skip to content

Commit

Permalink
Remove redundant deployments from network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Nov 10, 2021
1 parent 090ed5c commit d413609
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 52 deletions.
2 changes: 2 additions & 0 deletions test/contracts-network/colony-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ contract("Colony Expenditure", (accounts) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

({ colony, token } = await setupRandomColony(colonyNetwork));

await colony.setRewardInverse(100);
await colony.setAdministrationRole(1, UINT256_MAX, ADMIN, 1, true);
await colony.setArbitrationRole(1, UINT256_MAX, ARBITRATOR, 1, true);
Expand Down
52 changes: 13 additions & 39 deletions test/contracts-network/colony-network-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ import { BN } from "bn.js";
import { ethers } from "ethers";
import { soliditySha3 } from "web3-utils";

import { setupRandomColony, getMetaTransactionParameters } from "../../helpers/test-data-generator";
import { checkErrorRevert, web3GetBalance, encodeTxData } from "../../helpers/test-helper";
import { setupEtherRouter } from "../../helpers/upgradable-contracts";
import { UINT256_MAX } from "../../helpers/constants";

import {
setupColonyNetwork,
setupMetaColonyWithLockedCLNYToken,
setupRandomColony,
getMetaTransactionParameters,
} from "../../helpers/test-data-generator";

const { expect } = chai;
chai.use(bnChai(web3.utils.BN));

const ColonyExtension = artifacts.require("ColonyExtension");
const EtherRouter = artifacts.require("EtherRouter");
const IMetaColony = artifacts.require("IMetaColony");
const IColonyNetwork = artifacts.require("IColonyNetwork");
const ITokenLocking = artifacts.require("ITokenLocking");
const TestExtension0 = artifacts.require("TestExtension0");
const TestExtension1 = artifacts.require("TestExtension1");
Expand Down Expand Up @@ -52,6 +47,12 @@ contract("Colony Network Extensions", (accounts) => {
const TEST_VOTING_TOKEN = soliditySha3("VotingToken");

before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

testExtension0Resolver = await Resolver.new();
const testExtension0 = await TestExtension0.new();
await setupEtherRouter("TestExtension0", { TestExtension0: testExtension0.address }, testExtension0Resolver);
Expand All @@ -71,12 +72,14 @@ contract("Colony Network Extensions", (accounts) => {
testVotingTokenResolver = await Resolver.new();
const testVotingToken = await TestVotingToken.new();
await setupEtherRouter("TestVotingToken", { TestVotingToken: testVotingToken.address }, testVotingTokenResolver);

await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension2Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension3Resolver.address);
await metaColony.addExtensionToNetwork(TEST_VOTING_TOKEN, testVotingTokenResolver.address);
});

beforeEach(async () => {
colonyNetwork = await setupColonyNetwork();
({ metaColony } = await setupMetaColonyWithLockedCLNYToken(colonyNetwork));

({ colony, token } = await setupRandomColony(colonyNetwork));
await colony.addDomain(1, UINT256_MAX, 1); // Domain 2

Expand Down Expand Up @@ -111,9 +114,6 @@ contract("Colony Network Extensions", (accounts) => {

describe("adding extensions", () => {
it("allows the meta colony to add new extensions", async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension2Resolver.address);

const resolverAddress = await colonyNetwork.getExtensionResolver(TEST_EXTENSION, 1);
expect(resolverAddress).to.equal(testExtension1Resolver.address);
});
Expand All @@ -123,8 +123,6 @@ contract("Colony Network Extensions", (accounts) => {
});

it("does not allow the meta colony to overwrite existing extensions", async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);

await checkErrorRevert(
metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address),
"colony-network-extension-already-set"
Expand All @@ -146,11 +144,6 @@ contract("Colony Network Extensions", (accounts) => {
});

describe("installing extensions", () => {
beforeEach(async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension2Resolver.address);
});

it("allows a root user to install an extension with any version", async () => {
await colony.installExtension(TEST_EXTENSION, 2, { from: ROOT });

Expand Down Expand Up @@ -182,12 +175,6 @@ contract("Colony Network Extensions", (accounts) => {
});

describe("upgrading extensions", () => {
beforeEach(async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension2Resolver.address);
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension3Resolver.address);
});

it("allows root users to upgrade an extension", async () => {
await colony.installExtension(TEST_EXTENSION, 1, { from: ROOT });

Expand Down Expand Up @@ -231,10 +218,6 @@ contract("Colony Network Extensions", (accounts) => {
});

describe("deprecating extensions", () => {
beforeEach(async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
});

it("allows root users to deprecate and undeprecate an extension", async () => {
await colony.installExtension(TEST_EXTENSION, 1, { from: ROOT });

Expand All @@ -260,10 +243,6 @@ contract("Colony Network Extensions", (accounts) => {
});

describe("uninstalling extensions", () => {
beforeEach(async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
});

it("allows root users to uninstall an extension and send ether to the beneficiary", async () => {
await colony.installExtension(TEST_EXTENSION, 1, { from: ROOT });

Expand Down Expand Up @@ -292,10 +271,6 @@ contract("Colony Network Extensions", (accounts) => {
});

describe("using extensions", () => {
beforeEach(async () => {
await metaColony.addExtensionToNetwork(TEST_VOTING_TOKEN, testVotingTokenResolver.address);
});

it("allows network-managed extensions to lock and unlock tokens", async () => {
const tokenLockingAddress = await colonyNetwork.getTokenLocking();
const tokenLocking = await ITokenLocking.at(tokenLockingAddress);
Expand Down Expand Up @@ -363,7 +338,6 @@ contract("Colony Network Extensions", (accounts) => {
});

it("allows extensions to use metatransactions", async () => {
await metaColony.addExtensionToNetwork(TEST_EXTENSION, testExtension1Resolver.address);
await colony.installExtension(TEST_EXTENSION, 1, { from: ROOT });

const extensionAddress = await colonyNetwork.getExtensionInstallation(TEST_EXTENSION, colony.address);
Expand Down
8 changes: 5 additions & 3 deletions test/contracts-network/colony-network-recovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ chai.use(bnChai(web3.utils.BN));
const EtherRouter = artifacts.require("EtherRouter");
const IColonyNetwork = artifacts.require("IColonyNetwork");
const IReputationMiningCycle = artifacts.require("IReputationMiningCycle");
const IColony = artifacts.require("IColony");
const IMetaColony = artifacts.require("IMetaColony");
const Token = artifacts.require("Token");
const ReputationMiningCycle = artifacts.require("ReputationMiningCycle");
const ReputationMiningCycleRespond = artifacts.require("ReputationMiningCycleRespond");
Expand All @@ -60,8 +60,10 @@ contract("Colony Network Recovery", (accounts) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IColony.at(metaColonyAddress);
metaColony = await IMetaColony.at(metaColonyAddress);

const clnyAddress = await metaColony.getToken();
clny = await Token.at(clnyAddress);

Expand Down Expand Up @@ -447,7 +449,7 @@ contract("Colony Network Recovery", (accounts) => {
const colonyNetworkAddress = colonyNetwork.address;
const tokenLockingAddress = await colonyNetwork.getTokenLocking();
const metaColonyAddress = await colonyNetwork.getMetaColony();
const myMetaColony = await IColony.at(metaColonyAddress);
const myMetaColony = await IMetaColony.at(metaColonyAddress);
const myClnyAddress = await myMetaColony.getToken();

// slot 3: colonyNetworkAddress
Expand Down
1 change: 1 addition & 0 deletions test/contracts-network/colony-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract("Colony Payment", (accounts) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

Expand Down
1 change: 1 addition & 0 deletions test/contracts-network/colony-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ contract("ColonyTask", (accounts) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

Expand Down
7 changes: 5 additions & 2 deletions test/contracts-network/reputation-basic-functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ contract("Reputation mining - basic functionality", (accounts) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);
const tokenLockingAddress = await colonyNetwork.getTokenLocking();
tokenLocking = await ITokenLocking.at(tokenLockingAddress);

const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

const clnyAddress = await metaColony.getToken();
clnyToken = await Token.at(clnyAddress);

const tokenLockingAddress = await colonyNetwork.getTokenLocking();
tokenLocking = await ITokenLocking.at(tokenLockingAddress);
});

afterEach(async () => {
Expand Down
18 changes: 10 additions & 8 deletions test/contracts-network/reputation-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
setupRatedTask,
setupFundedTask,
setupFinalizedTask,
setupColonyNetwork,
setupMetaColonyWithLockedCLNYToken,
giveUserCLNYTokensAndStake,
} from "../../helpers/test-data-generator";

Expand Down Expand Up @@ -52,6 +50,9 @@ const ADDRESS_ZERO = ethers.constants.AddressZero;
const { expect } = chai;
chai.use(bnChai(web3.utils.BN));

const EtherRouter = artifacts.require("EtherRouter");
const IColonyNetwork = artifacts.require("IColonyNetwork");
const IMetaColony = artifacts.require("IMetaColony");
const IReputationMiningCycle = artifacts.require("IReputationMiningCycle");
const Token = artifacts.require("Token");
const TaskSkillEditing = artifacts.require("TaskSkillEditing");
Expand All @@ -69,13 +70,14 @@ contract("Reputation Updates", (accounts) => {
let inactiveReputationMiningCycle;

before(async () => {
// Setup a new network instance as we'll be modifying the global skills tree
colonyNetwork = await setupColonyNetwork();
({ metaColony, clnyToken } = await setupMetaColonyWithLockedCLNYToken(colonyNetwork));
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

await giveUserCLNYTokensAndStake(colonyNetwork, MINER1, DEFAULT_STAKE);
await colonyNetwork.initialiseReputationMining();
await colonyNetwork.startNextCycle();
const metaColonyAddress = await colonyNetwork.getMetaColony();
metaColony = await IMetaColony.at(metaColonyAddress);

const clnyTokenAddress = await metaColony.getToken();
clnyToken = await Token.at(clnyTokenAddress);
});

beforeEach(async function () {
Expand Down
1 change: 1 addition & 0 deletions test/contracts-network/token-locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract("Token Locking", (addresses) => {
before(async () => {
const etherRouter = await EtherRouter.deployed();
colonyNetwork = await IColonyNetwork.at(etherRouter.address);

const tokenLockingAddress = await colonyNetwork.getTokenLocking();
tokenLocking = await ITokenLocking.at(tokenLockingAddress);
});
Expand Down

0 comments on commit d413609

Please sign in to comment.