From ea62796b9238e2a0486b015128b8bd2e8f82fdbd Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Jun 2019 10:59:31 +0100 Subject: [PATCH 1/4] Bump Colony version to v2 Also allow us to initialise with any version. This is required because we wish to align versions between Goerli and Mainnet --- contracts/Colony.sol | 2 +- contracts/ColonyNetwork.sol | 6 +++--- contracts/IColonyNetwork.sol | 5 +++-- helpers/test-data-generator.js | 3 ++- test/contracts-network/colony-network.js | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/contracts/Colony.sol b/contracts/Colony.sol index 00b294aca4..27a969a244 100755 --- a/contracts/Colony.sol +++ b/contracts/Colony.sol @@ -26,7 +26,7 @@ contract Colony is ColonyStorage, PatriciaTreeProofs { // This function, exactly as defined, is used in build scripts. Take care when updating. // Version number should be upped with every change in Colony or its dependency contracts or libraries. - function version() public pure returns (uint256 colonyVersion) { return 1; } + function version() public pure returns (uint256 colonyVersion) { return 2; } function setRootRole(address _user, bool _setTo) public stoppable auth { ColonyAuthority(address(authority)).setUserRole(_user, uint8(ColonyRole.Root), _setTo); diff --git a/contracts/ColonyNetwork.sol b/contracts/ColonyNetwork.sol index 4aa53ddf0a..b3a9b0dd0d 100644 --- a/contracts/ColonyNetwork.sol +++ b/contracts/ColonyNetwork.sol @@ -182,13 +182,13 @@ contract ColonyNetwork is ColonyNetworkStorage { emit ColonyVersionAdded(_version, _resolver); } - function initialise(address _resolver) public + function initialise(address _resolver, uint256 _version) public stoppable auth { require(currentColonyVersion == 0, "colony-network-already-initialised"); - colonyVersionResolver[1] = _resolver; - currentColonyVersion = 1; + colonyVersionResolver[_version] = _resolver; + currentColonyVersion = _version; emit ColonyNetworkInitialised(_resolver); } diff --git a/contracts/IColonyNetwork.sol b/contracts/IColonyNetwork.sol index 8a1ac1f19f..0ecedee85c 100644 --- a/contracts/IColonyNetwork.sol +++ b/contracts/IColonyNetwork.sol @@ -142,8 +142,9 @@ contract IColonyNetwork is ColonyNetworkDataTypes, IRecovery { /// @notice Initialises the colony network by setting the first Colony version resolver to `_resolver` address. /// @dev Only allowed to be run once, by the Network owner before any Colony versions are added. - /// @param _resolver Address of the resolver for Colony contract version 1 - function initialise(address _resolver) public; + /// @param _resolver Address of the resolver for Colony contract + /// @param _resolver Version of the Colony contract the resolver represents + function initialise(address _resolver, uint256 _version) public; /// @notice Get a colony address by its Id in the network. /// @param _id Id of the colony to get diff --git a/helpers/test-data-generator.js b/helpers/test-data-generator.js index 80c6fbfda5..495614686f 100644 --- a/helpers/test-data-generator.js +++ b/helpers/test-data-generator.js @@ -344,7 +344,8 @@ export async function setupColonyNetwork() { const colonyNetwork = await IColonyNetwork.at(etherRouter.address); await setupColonyVersionResolver(colonyTemplate, colonyTask, colonyPayment, colonyFunding, contractRecovery, resolver); - await colonyNetwork.initialise(resolver.address); + const version = await colonyTemplate.version(); + await colonyNetwork.initialise(resolver.address, version); // Jumping through these hoops to avoid the need to rewire ReputationMiningCycleResolver. const deployedColonyNetwork = await IColonyNetwork.at(EtherRouter.address); const reputationMiningCycleResolverAddress = await deployedColonyNetwork.getMiningResolver(); diff --git a/test/contracts-network/colony-network.js b/test/contracts-network/colony-network.js index 6814a21923..cfb35d691f 100755 --- a/test/contracts-network/colony-network.js +++ b/test/contracts-network/colony-network.js @@ -80,7 +80,7 @@ contract("Colony Network", accounts => { }); it("should not be able to initialise network twice", async () => { - await checkErrorRevert(colonyNetwork.initialise("0xDde1400C69752A6596a7B2C1f2420Fb9A71c1FDA"), "colony-network-already-initialised"); + await checkErrorRevert(colonyNetwork.initialise("0xDde1400C69752A6596a7B2C1f2420Fb9A71c1FDA", 3), "colony-network-already-initialised"); }); it("should not be able to create a colony if the network is not initialised", async () => { From 492b1d822073285c53632ea81856cbb352cc63c9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Jun 2019 11:31:36 +0100 Subject: [PATCH 2/4] Changes based on Elena's review --- contracts/ColonyNetwork.sol | 1 + contracts/IColonyNetwork.sol | 2 +- docs/_Interface_IColonyNetwork.md | 3 ++- migrations/4_setup_colony_version_resolver.js | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/ColonyNetwork.sol b/contracts/ColonyNetwork.sol index b3a9b0dd0d..3dff90eaa4 100644 --- a/contracts/ColonyNetwork.sol +++ b/contracts/ColonyNetwork.sol @@ -187,6 +187,7 @@ contract ColonyNetwork is ColonyNetworkStorage { auth { require(currentColonyVersion == 0, "colony-network-already-initialised"); + require(_version > 0, "colony-network-invalid-version"); colonyVersionResolver[_version] = _resolver; currentColonyVersion = _version; diff --git a/contracts/IColonyNetwork.sol b/contracts/IColonyNetwork.sol index 0ecedee85c..ae0b6c7d81 100644 --- a/contracts/IColonyNetwork.sol +++ b/contracts/IColonyNetwork.sol @@ -143,7 +143,7 @@ contract IColonyNetwork is ColonyNetworkDataTypes, IRecovery { /// @notice Initialises the colony network by setting the first Colony version resolver to `_resolver` address. /// @dev Only allowed to be run once, by the Network owner before any Colony versions are added. /// @param _resolver Address of the resolver for Colony contract - /// @param _resolver Version of the Colony contract the resolver represents + /// @param _version Version of the Colony contract the resolver represents function initialise(address _resolver, uint256 _version) public; /// @notice Get a colony address by its Id in the network. diff --git a/docs/_Interface_IColonyNetwork.md b/docs/_Interface_IColonyNetwork.md index c2d6d9f0f8..dd2e73ca0d 100644 --- a/docs/_Interface_IColonyNetwork.md +++ b/docs/_Interface_IColonyNetwork.md @@ -428,7 +428,8 @@ Initialises the colony network by setting the first Colony version resolver to ` |Name|Type|Description| |---|---|---| -|_resolver|address|Address of the resolver for Colony contract version 1 +|_resolver|address|Address of the resolver for Colony contract +|_version|uint256|Version of the Colony contract the resolver represents ### `initialiseReputationMining` diff --git a/migrations/4_setup_colony_version_resolver.js b/migrations/4_setup_colony_version_resolver.js index 7b3c47e762..daee2852f2 100644 --- a/migrations/4_setup_colony_version_resolver.js +++ b/migrations/4_setup_colony_version_resolver.js @@ -28,7 +28,7 @@ module.exports = async function(deployer) { // Register the new Colony contract version with the newly setup Resolver await setupColonyVersionResolver(colony, colonyTask, colonyPayment, colonyFunding, contractRecovery, resolver); - await colonyNetwork.initialise(resolver.address); + await colonyNetwork.initialise(resolver.address, version); console.log("### Colony version", version.toString(), "set to Resolver", resolver.address); }; From ff7857ebaebc7dcd4aa83c2013a310e8d729281d Mon Sep 17 00:00:00 2001 From: elenadimitrova Date: Wed, 5 Jun 2019 13:42:38 +0300 Subject: [PATCH 3/4] Add tests for network initialise function behaviour --- test/contracts-network/colony-network.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/contracts-network/colony-network.js b/test/contracts-network/colony-network.js index cfb35d691f..9875a86939 100755 --- a/test/contracts-network/colony-network.js +++ b/test/contracts-network/colony-network.js @@ -94,6 +94,26 @@ contract("Colony Network", accounts => { "colony-network-not-initialised-cannot-create-colony" ); }); + + it("should not be able to initialise the network with colony version number 0", async () => { + const resolverColonyNetworkDeployed = await Resolver.deployed(); + const etherRouter = await EtherRouter.new(); + await etherRouter.setResolver(resolverColonyNetworkDeployed.address); + const colonyNetworkNew = await IColonyNetwork.at(etherRouter.address); + + await checkErrorRevert(colonyNetworkNew.initialise("0xDde1400C69752A6596a7B2C1f2420Fb9A71c1FDA", 0), "colony-network-invalid-version"); + }); + + it("should be able to initialise the network with any colony version number greater than 0", async () => { + const resolverColonyNetworkDeployed = await Resolver.deployed(); + const etherRouter = await EtherRouter.new(); + await etherRouter.setResolver(resolverColonyNetworkDeployed.address); + const colonyNetworkNew = await IColonyNetwork.at(etherRouter.address); + + await colonyNetworkNew.initialise("0xDde1400C69752A6596a7B2C1f2420Fb9A71c1FDA", 79); + const currentColonyVersion = await colonyNetworkNew.getCurrentColonyVersion(); + expect(currentColonyVersion).to.eq.BN(79); + }); }); describe("when managing the mining process", () => { From 5954725fbd11d7d22f89f1b8178069ca5a788cdf Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 5 Jun 2019 11:59:26 +0100 Subject: [PATCH 4/4] Update version test --- test/contracts-network/colony-network.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/contracts-network/colony-network.js b/test/contracts-network/colony-network.js index 9875a86939..87d7bfc124 100755 --- a/test/contracts-network/colony-network.js +++ b/test/contracts-network/colony-network.js @@ -48,7 +48,7 @@ contract("Colony Network", accounts => { it("should have the correct current Colony version set", async () => { const currentColonyVersion = await colonyNetwork.getCurrentColonyVersion(); - expect(currentColonyVersion).to.eq.BN(1); + expect(currentColonyVersion).to.eq.BN(2); }); it("should have the Resolver for current Colony version set", async () => {