From 170620369d6f1fc46901ec28f89e27d08c39f105 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Mon, 17 Jun 2024 11:00:16 -0400 Subject: [PATCH 1/9] Delete migrations/ --- migrations/1_initial_migration.js | 6 - migrations/2_deploy_contracts.js | 51 ------- migrations/3_setup_colony_network.js | 80 ----------- migrations/4_setup_colony_version_resolver.js | 50 ------- migrations/5_setup_token_locking.js | 26 ---- migrations/6_setup_mining_cycle_resolver.js | 45 ------ migrations/7_setup_ens_registry.js | 18 --- migrations/8_setup_meta_colony.js | 133 ------------------ migrations/9_setup_extensions.js | 70 --------- 9 files changed, 479 deletions(-) delete mode 100644 migrations/1_initial_migration.js delete mode 100644 migrations/2_deploy_contracts.js delete mode 100644 migrations/3_setup_colony_network.js delete mode 100644 migrations/4_setup_colony_version_resolver.js delete mode 100644 migrations/5_setup_token_locking.js delete mode 100644 migrations/6_setup_mining_cycle_resolver.js delete mode 100644 migrations/7_setup_ens_registry.js delete mode 100644 migrations/8_setup_meta_colony.js delete mode 100644 migrations/9_setup_extensions.js diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index 808eb41d5b..0000000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,6 +0,0 @@ -/* globals artifacts */ -const Migrations = artifacts.require("./Migrations"); - -module.exports = async function (deployer) { - await deployer.deploy(Migrations); -}; diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js deleted file mode 100644 index c67fbf4e48..0000000000 --- a/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,51 +0,0 @@ -/* globals artifacts */ - -const fs = require("fs"); - -const ContractRecovery = artifacts.require("./ContractRecovery"); -const ColonyNetwork = artifacts.require("./ColonyNetwork"); -const ColonyNetworkDeployer = artifacts.require("./ColonyNetworkDeployer"); -const ColonyNetworkMining = artifacts.require("./ColonyNetworkMining"); -const ColonyNetworkAuction = artifacts.require("./ColonyNetworkAuction"); -const ColonyNetworkENS = artifacts.require("./ColonyNetworkENS"); -const ColonyNetworkExtensions = artifacts.require("./ColonyNetworkExtensions"); -const ColonyNetworkSkills = artifacts.require("./ColonyNetworkSkills"); -const ReputationMiningCycle = artifacts.require("./ReputationMiningCycle"); -const ReputationMiningCycleRespond = artifacts.require("./ReputationMiningCycleRespond"); -const ReputationMiningCycleBinarySearch = artifacts.require("./ReputationMiningCycleBinarySearch"); - -const EtherRouter = artifacts.require("./EtherRouter"); -const Resolver = artifacts.require("./Resolver"); - -// We `require` the ReputationMiningCycle object to make sure -// it is injected in the `artifacts` variables during test -// preparation. We need this for the eth-gas-reporter. -// See https://github.com/cgewecke/eth-gas-reporter/issues/64 -artifacts.require("./ReputationMiningCycle"); - -module.exports = async function (deployer, network, accounts) { - console.log(`## ${network} network ##`); - await deployer.deploy(ColonyNetwork); - await deployer.deploy(ColonyNetworkDeployer); - await deployer.deploy(ColonyNetworkMining); - await deployer.deploy(ColonyNetworkAuction); - await deployer.deploy(ColonyNetworkENS); - await deployer.deploy(ColonyNetworkExtensions); - await deployer.deploy(ColonyNetworkSkills); - await deployer.deploy(ReputationMiningCycle); - await deployer.deploy(ReputationMiningCycleRespond); - await deployer.deploy(ReputationMiningCycleBinarySearch); - await deployer.deploy(EtherRouter); - await deployer.deploy(Resolver); - await deployer.deploy(ContractRecovery); - - // Deploy CreateX - await web3.eth.sendTransaction({ from: accounts[0], to: "0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5", value: web3.utils.toWei("0.3", "ether") }); - const rawTx = fs - .readFileSync("lib/createx/scripts/presigned-createx-deployment-transactions/signed_serialised_transaction_gaslimit_3000000_.json", { - encoding: "utf8", - }) - .replace(/"/g, "") - .replace("\n", ""); - await web3.eth.sendSignedTransaction(rawTx); -}; diff --git a/migrations/3_setup_colony_network.js b/migrations/3_setup_colony_network.js deleted file mode 100644 index 436f126489..0000000000 --- a/migrations/3_setup_colony_network.js +++ /dev/null @@ -1,80 +0,0 @@ -/* globals artifacts */ -const contract = require("@truffle/contract"); -const { writeFileSync } = require("fs"); -const path = require("path"); -const { setupUpgradableColonyNetwork } = require("../helpers/upgradable-contracts"); - -const ColonyNetworkAuthority = artifacts.require("./ColonyNetworkAuthority"); -const ContractRecovery = artifacts.require("./ContractRecovery"); -const ColonyNetwork = artifacts.require("./ColonyNetwork"); -const ColonyNetworkDeployer = artifacts.require("./ColonyNetworkDeployer"); -const ColonyNetworkMining = artifacts.require("./ColonyNetworkMining"); -const ColonyNetworkAuction = artifacts.require("./ColonyNetworkAuction"); -const ColonyNetworkENS = artifacts.require("./ColonyNetworkENS"); -const ColonyNetworkExtensions = artifacts.require("./ColonyNetworkExtensions"); -const ColonyNetworkSkills = artifacts.require("./ColonyNetworkSkills"); -const EtherRouterCreate3 = artifacts.require("./EtherRouterCreate3"); -const Resolver = artifacts.require("./Resolver"); -const createXABI = require("../lib/createx/artifacts/src/ICreateX.sol/ICreateX.json"); - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer, network, accounts) { - const colonyNetwork = await ColonyNetwork.deployed(); - const colonyNetworkDeployer = await ColonyNetworkDeployer.deployed(); - const colonyNetworkMining = await ColonyNetworkMining.deployed(); - const colonyNetworkAuction = await ColonyNetworkAuction.deployed(); - const colonyNetworkENS = await ColonyNetworkENS.deployed(); - const colonyNetworkExtensions = await ColonyNetworkExtensions.deployed(); - const colonyNetworkSkills = await ColonyNetworkSkills.deployed(); - const resolver = await Resolver.deployed(); - const contractRecovery = await ContractRecovery.deployed(); - - // Deploy EtherRouter through CreateX - const CreateX = contract({ abi: createXABI.abi }); - CreateX.setProvider(web3.currentProvider); - const createX = await CreateX.at("0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed"); - - // This is a fake instance of an etherRouter, just so we can call encodeABI - const fakeEtherRouter = await EtherRouterCreate3.at(colonyNetwork.address); - const setOwnerData = fakeEtherRouter.contract.methods.setOwner(accounts[0]).encodeABI(); - const tx = await createX.methods["deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))"]( - // `${accounts[0]}001212121212121212121212`, - `0xb77d57f4959eafa0339424b83fcfaf9c15407461005e95d52076387600e2c1e9`, - EtherRouterCreate3.bytecode, - setOwnerData, - [0, 0], - { from: accounts[0] }, - ); - - const etherRouter = await EtherRouterCreate3.at(tx.logs.filter((log) => log.event === "ContractCreation")[0].args.newContract); - - await setupUpgradableColonyNetwork( - etherRouter, - resolver, - colonyNetwork, - colonyNetworkDeployer, - colonyNetworkMining, - colonyNetworkAuction, - colonyNetworkENS, - colonyNetworkExtensions, - colonyNetworkSkills, - contractRecovery, - ); - - const authorityNetwork = await ColonyNetworkAuthority.new(etherRouter.address); - await authorityNetwork.setOwner(etherRouter.address); - await etherRouter.setAuthority(authorityNetwork.address); - - writeFileSync(path.resolve(__dirname, "..", "etherrouter-address.json"), JSON.stringify({ etherRouterAddress: etherRouter.address }), { - encoding: "utf8", - }); - - console.log( - "### Colony Network setup with Resolver", - resolver.address, - ", EtherRouter", - etherRouter.address, - " and Authority ", - authorityNetwork.address, - ); -}; diff --git a/migrations/4_setup_colony_version_resolver.js b/migrations/4_setup_colony_version_resolver.js deleted file mode 100644 index e1d1000be3..0000000000 --- a/migrations/4_setup_colony_version_resolver.js +++ /dev/null @@ -1,50 +0,0 @@ -/* globals artifacts */ - -const { setupColonyVersionResolver } = require("../helpers/upgradable-contracts"); - -const Colony = artifacts.require("./Colony"); -const ColonyDomains = artifacts.require("./ColonyDomains"); -const ColonyExpenditure = artifacts.require("./ColonyExpenditure"); -const ColonyFunding = artifacts.require("./ColonyFunding"); -const ColonyRewards = artifacts.require("./ColonyRewards"); -const ColonyRoles = artifacts.require("./ColonyRoles"); -const ContractRecovery = artifacts.require("./ContractRecovery"); -const ColonyArbitraryTransaction = artifacts.require("./ColonyArbitraryTransaction"); -const EtherRouter = artifacts.require("./EtherRouter"); -const Resolver = artifacts.require("./Resolver"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer) { - // Create a new Colony (version) and setup a new Resolver for it - const colony = await Colony.new(); - const colonyDomains = await ColonyDomains.new(); - const colonyExpenditure = await ColonyExpenditure.new(); - const colonyFunding = await ColonyFunding.new(); - const colonyRewards = await ColonyRewards.new(); - const colonyRoles = await ColonyRoles.new(); - const colonyArbitraryTransaction = await ColonyArbitraryTransaction.new(); - const contractRecovery = await ContractRecovery.deployed(); - const version = await colony.version(); - const resolver = await Resolver.new(); - - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouter = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouter.address); - - // Register the new Colony contract version with the newly setup Resolver - await setupColonyVersionResolver( - colony, - colonyDomains, - colonyExpenditure, - colonyFunding, - colonyRewards, - colonyRoles, - contractRecovery, - colonyArbitraryTransaction, - resolver, - ); - await colonyNetwork.initialise(resolver.address, version); - - console.log("### Colony version", version.toString(), "set to Resolver", resolver.address); -}; diff --git a/migrations/5_setup_token_locking.js b/migrations/5_setup_token_locking.js deleted file mode 100644 index 73d33bf345..0000000000 --- a/migrations/5_setup_token_locking.js +++ /dev/null @@ -1,26 +0,0 @@ -/* globals artifacts */ - -const { setupUpgradableTokenLocking } = require("../helpers/upgradable-contracts"); - -const TokenLocking = artifacts.require("./TokenLocking"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const EtherRouter = artifacts.require("./EtherRouter"); -const Resolver = artifacts.require("./Resolver"); - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer) { - const resolver = await Resolver.new(); - const etherRouter = await EtherRouter.new(); - const tokenLockingContract = await TokenLocking.new(); - await setupUpgradableTokenLocking(etherRouter, resolver, tokenLockingContract); - - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouterDeployed = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouterDeployed.address); - await colonyNetwork.setTokenLocking(etherRouter.address); - - const tokenLocking = await TokenLocking.at(etherRouter.address); - await tokenLocking.setColonyNetwork(colonyNetwork.address); - - console.log("### TokenLocking setup at ", tokenLocking.address, "with Resolver", resolver.address); -}; diff --git a/migrations/6_setup_mining_cycle_resolver.js b/migrations/6_setup_mining_cycle_resolver.js deleted file mode 100644 index 1351465c6c..0000000000 --- a/migrations/6_setup_mining_cycle_resolver.js +++ /dev/null @@ -1,45 +0,0 @@ -/* globals artifacts */ - -const { setupReputationMiningCycleResolver } = require("../helpers/upgradable-contracts"); -const { getChainId } = require("../helpers/test-helper"); - -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const ReputationMiningCycle = artifacts.require("./ReputationMiningCycle"); -const ReputationMiningCycleRespond = artifacts.require("./ReputationMiningCycleRespond"); -const ReputationMiningCycleBinarySearch = artifacts.require("./ReputationMiningCycleBinarySearch"); -const EtherRouter = artifacts.require("./EtherRouter"); -const Resolver = artifacts.require("./Resolver"); - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer) { - // Check chain id - // If not a mining chain, then skip - const chainId = await getChainId(); - const miningChainId = parseInt(process.env.MINING_CHAIN_ID, 10) || chainId; - - if (chainId !== miningChainId) { - console.log("Not mining chain, skipping setting up mining cycle resolver"); - return; - } - - // Create a new Colony (version) and setup a new Resolver for it - const reputationMiningCycle = await ReputationMiningCycle.deployed(); - const reputationMiningCycleRespond = await ReputationMiningCycleRespond.deployed(); - const reputationMiningCycleBinarySearch = await ReputationMiningCycleBinarySearch.deployed(); - const resolver = await Resolver.new(); - - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouterDeployed = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouterDeployed.address); - - // Register a new Resolver for ReputationMining instance and set it on the Network - await setupReputationMiningCycleResolver( - reputationMiningCycle, - reputationMiningCycleRespond, - reputationMiningCycleBinarySearch, - resolver, - colonyNetwork, - ); - - console.log("### ReputationMiningCycle set to Resolver", resolver.address); -}; diff --git a/migrations/7_setup_ens_registry.js b/migrations/7_setup_ens_registry.js deleted file mode 100644 index b9f13f23b1..0000000000 --- a/migrations/7_setup_ens_registry.js +++ /dev/null @@ -1,18 +0,0 @@ -/* globals artifacts */ - -const { setupENSRegistrar } = require("../helpers/upgradable-contracts"); - -const EtherRouter = artifacts.require("./EtherRouter"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const ENSRegistry = artifacts.require("ENSRegistry"); - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer, network, accounts) { - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouterDeployed = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouterDeployed.address); - const ensRegistry = await ENSRegistry.new(); - await setupENSRegistrar(colonyNetwork, ensRegistry, accounts[0]); - - console.log("### ENSRegistry set up at", ensRegistry.address, "and linked to ColonyNetwork"); -}; diff --git a/migrations/8_setup_meta_colony.js b/migrations/8_setup_meta_colony.js deleted file mode 100644 index 047dd2feb0..0000000000 --- a/migrations/8_setup_meta_colony.js +++ /dev/null @@ -1,133 +0,0 @@ -/* globals artifacts */ - -const assert = require("assert"); -const ethers = require("ethers"); -const { UINT256_MAX, XDAI_CHAINID, FORKED_XDAI_CHAINID } = require("../helpers/constants"); - -const Token = artifacts.require("./Token"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const IMetaColony = artifacts.require("./IMetaColony"); -const ITokenLocking = artifacts.require("./ITokenLocking"); -const TokenAuthority = artifacts.require("./TokenAuthority"); - -const Resolver = artifacts.require("./Resolver"); -const EtherRouter = artifacts.require("./EtherRouter"); - -const Version3 = artifacts.require("./Version3"); -const Version4 = artifacts.require("./Version4"); -const { setupColonyVersionResolver } = require("../helpers/upgradable-contracts"); -const { getChainId } = require("../helpers/test-helper"); - -const DEFAULT_STAKE = "2000000000000000000000000"; // DEFAULT_STAKE - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer, network, accounts) { - const MAIN_ACCOUNT = accounts[5]; - const TOKEN_OWNER = accounts[11]; - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouterDeployed = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouterDeployed.address); - const clnyToken = await Token.new("Colony Network Token", "CLNY", 18); - await colonyNetwork.createMetaColony(clnyToken.address); - const metaColonyAddress = await colonyNetwork.getMetaColony(); - const metaColony = await IMetaColony.at(metaColonyAddress); - await metaColony.setNetworkFeeInverse(100); - - const tokenLockingAddress = await colonyNetwork.getTokenLocking(); - const reputationMinerTestAccounts = accounts.slice(3, 11); - - // Penultimate parameter is the vesting contract which is not the subject of this integration testing so passing in ZERO_ADDRESS - const tokenAuthority = await TokenAuthority.new(clnyToken.address, metaColonyAddress, [ - colonyNetwork.address, - tokenLockingAddress, - ...reputationMinerTestAccounts, - ]); - await clnyToken.setAuthority(tokenAuthority.address); - await clnyToken.setOwner(TOKEN_OWNER); - - // Check chain id - // If not a mining chain, then skip setting up mining - const chainId = await getChainId(); - const miningChainId = parseInt(process.env.MINING_CHAIN_ID, 10) || chainId; - - if (miningChainId === chainId) { - // These commands add MAIN_ACCOUNT as a reputation miner. - // This is necessary because the first miner must have staked before the mining cycle begins. - await clnyToken.mint(MAIN_ACCOUNT, DEFAULT_STAKE, { from: TOKEN_OWNER }); - await clnyToken.approve(tokenLockingAddress, DEFAULT_STAKE, { from: MAIN_ACCOUNT }); - const mainAccountBalance = await clnyToken.balanceOf(MAIN_ACCOUNT); - assert.equal(mainAccountBalance.toString(), DEFAULT_STAKE.toString()); - const tokenLocking = await ITokenLocking.at(tokenLockingAddress); - await tokenLocking.methods["deposit(address,uint256,bool)"](clnyToken.address, DEFAULT_STAKE, true, { from: MAIN_ACCOUNT }); - await colonyNetwork.stakeForMining(DEFAULT_STAKE, { from: MAIN_ACCOUNT }); - } - - // Set up functional resolvers that identify correctly as previous versions. - const Colony = artifacts.require("./Colony"); - const ColonyDomains = artifacts.require("./ColonyDomains"); - const ColonyExpenditure = artifacts.require("./ColonyExpenditure"); - const ColonyFunding = artifacts.require("./ColonyFunding"); - const ColonyRewards = artifacts.require("./ColonyRewards"); - const ColonyRoles = artifacts.require("./ColonyRoles"); - const ContractRecovery = artifacts.require("./ContractRecovery"); - const ColonyArbitraryTransaction = artifacts.require("./ColonyArbitraryTransaction"); - - const colony = await Colony.new(); - const colonyDomains = await ColonyDomains.new(); - const colonyExpenditure = await ColonyExpenditure.new(); - const colonyFunding = await ColonyFunding.new(); - const colonyRewards = await ColonyRewards.new(); - const colonyRoles = await ColonyRoles.new(); - const contractRecovery = await ContractRecovery.deployed(); - const colonyArbitraryTransaction = await ColonyArbitraryTransaction.new(); - - const resolver3 = await Resolver.new(); - await setupColonyVersionResolver( - colony, - colonyDomains, - colonyExpenditure, - colonyFunding, - colonyRewards, - colonyRoles, - contractRecovery, - colonyArbitraryTransaction, - resolver3, - ); - const v3responder = await Version3.new(); - await resolver3.register("version()", v3responder.address); - await metaColony.addNetworkColonyVersion(3, resolver3.address); - - const resolver4 = await Resolver.new(); - await setupColonyVersionResolver( - colony, - colonyDomains, - colonyExpenditure, - colonyFunding, - colonyRewards, - colonyRoles, - contractRecovery, - colonyArbitraryTransaction, - resolver4, - ); - const v4responder = await Version4.new(); - await resolver4.register("version()", v4responder.address); - await metaColony.addNetworkColonyVersion(4, resolver4.address); - - if (chainId === miningChainId) { - await metaColony.initialiseReputationMining(miningChainId, ethers.constants.HashZero, 0); - // await colonyNetwork.startNextCycle(); - const skillCount = await colonyNetwork.getSkillCount(); - console.log(skillCount.toString(16)); - if (chainId === XDAI_CHAINID || chainId === FORKED_XDAI_CHAINID) { - assert.equal(skillCount.toNumber(), 3); - } else { - assert.equal(skillCount.shln(128).mod(UINT256_MAX).shrn(128).toNumber(), 3); - } - } else { - await metaColony.initialiseReputationMining(miningChainId, ethers.constants.HashZero, 0); - const skillCount = await colonyNetwork.getSkillCount(); - assert.equal(skillCount.shln(128).mod(UINT256_MAX).shrn(128).toNumber(), 2); - } - - console.log("### Meta Colony created at", metaColony.address); -}; diff --git a/migrations/9_setup_extensions.js b/migrations/9_setup_extensions.js deleted file mode 100644 index 8f50660664..0000000000 --- a/migrations/9_setup_extensions.js +++ /dev/null @@ -1,70 +0,0 @@ -/* globals artifacts */ - -const { soliditySha3 } = require("web3-utils"); - -const { setupEtherRouter } = require("../helpers/upgradable-contracts"); - -const CoinMachine = artifacts.require("./CoinMachine"); -const EvaluatedExpenditure = artifacts.require("./EvaluatedExpenditure"); -const StakedExpenditure = artifacts.require("./StakedExpenditure"); -const FundingQueue = artifacts.require("./FundingQueue"); -const OneTxPayment = artifacts.require("./OneTxPayment"); -const ReputationBootstrapper = artifacts.require("./ReputationBootstrapper"); -const StreamingPayments = artifacts.require("./StreamingPayments"); -const VotingReputation = artifacts.require("./VotingReputation"); -const VotingReputationStaking = artifacts.require("./VotingReputationStaking"); -const VotingReputationMisalignedRecovery = artifacts.require("./VotingReputationMisalignedRecovery"); -const TokenSupplier = artifacts.require("./TokenSupplier"); -const Whitelist = artifacts.require("./Whitelist"); -const StagedExpenditure = artifacts.require("./StagedExpenditure"); - -const Resolver = artifacts.require("./Resolver"); -const EtherRouter = artifacts.require("./EtherRouter"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const IMetaColony = artifacts.require("./IMetaColony"); - -async function addExtension(colonyNetwork, contractDir, interfaceName, extensionName, implementations) { - const metaColonyAddress = await colonyNetwork.getMetaColony(); - const metaColony = await IMetaColony.at(metaColonyAddress); - - const NAME_HASH = soliditySha3(extensionName); - const deployments = []; - // eslint-disable-next-line no-restricted-syntax - for (const implementation of implementations) { - const deployment = await implementation.new(); - deployments.push(deployment); - } - - const resolver = await Resolver.new(); - - const deployedImplementations = {}; - for (let idx = 0; idx < implementations.length; idx += 1) { - deployedImplementations[implementations[idx].contractName] = deployments[idx].address; - } - await setupEtherRouter(contractDir, interfaceName, deployedImplementations, resolver); - await metaColony.addExtensionToNetwork(NAME_HASH, resolver.address); - console.log(`### ${extensionName} extension installed`); -} - -// eslint-disable-next-line no-unused-vars -module.exports = async function (deployer, network, accounts) { - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouterDeployed = await EtherRouter.at(cnAddress); - const colonyNetwork = await IColonyNetwork.at(etherRouterDeployed.address); - - await addExtension(colonyNetwork, "extensions", "CoinMachine", "CoinMachine", [CoinMachine]); - await addExtension(colonyNetwork, "extensions", "EvaluatedExpenditure", "EvaluatedExpenditure", [EvaluatedExpenditure]); - await addExtension(colonyNetwork, "extensions", "FundingQueue", "FundingQueue", [FundingQueue]); - await addExtension(colonyNetwork, "extensions", "OneTxPayment", "OneTxPayment", [OneTxPayment]); - await addExtension(colonyNetwork, "extensions", "ReputationBootstrapper", "ReputationBootstrapper", [ReputationBootstrapper]); - await addExtension(colonyNetwork, "extensions", "StakedExpenditure", "StakedExpenditure", [StakedExpenditure]); - await addExtension(colonyNetwork, "extensions", "StreamingPayments", "StreamingPayments", [StreamingPayments]); - await addExtension(colonyNetwork, "extensions", "TokenSupplier", "TokenSupplier", [TokenSupplier]); - await addExtension(colonyNetwork, "extensions/votingReputation", "IVotingReputation", "VotingReputation", [ - VotingReputation, - VotingReputationStaking, - VotingReputationMisalignedRecovery, - ]); - await addExtension(colonyNetwork, "extensions", "Whitelist", "Whitelist", [Whitelist]); - await addExtension(colonyNetwork, "extensions", "StagedExpenditure", "StagedExpenditure", [StagedExpenditure]); -}; From 3a82986eb67e06656f42241365cae8f8a2291078 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Mon, 17 Jun 2024 12:45:11 -0400 Subject: [PATCH 2/9] Delete unused scripts --- .solcover.js | 14 --- scripts/deployOldExtensionVersions.js | 82 --------------- scripts/deployUnmockedColonyVersions.js | 128 ------------------------ scripts/process-truffle-security.js | 48 --------- scripts/provision-safe-contracts.sh | 13 --- scripts/provision-token-contracts.sh | 12 --- scripts/resetParity.sh | 40 -------- 7 files changed, 337 deletions(-) delete mode 100644 scripts/deployOldExtensionVersions.js delete mode 100644 scripts/deployUnmockedColonyVersions.js delete mode 100644 scripts/process-truffle-security.js delete mode 100644 scripts/provision-safe-contracts.sh delete mode 100644 scripts/provision-token-contracts.sh delete mode 100644 scripts/resetParity.sh diff --git a/.solcover.js b/.solcover.js index b82a9db62b..112603ae7c 100644 --- a/.solcover.js +++ b/.solcover.js @@ -1,16 +1,3 @@ -const { execSync } = require("child_process"); -const log = console.log; - -// Copies pre-built token artifacts to .coverage_artifacts/contracts -function provisionTokenContracts(config){ - let output; - const provisionColonyToken = `BUILD_DIR="build-coverage" bash ./scripts/provision-token-contracts.sh`; - - log('Provisioning ColonyToken contracts...') - output = execSync(provisionColonyToken); - log(output.toString()) -} - module.exports = { configureYulOptimizer: true, skipFiles: [ @@ -53,7 +40,6 @@ module.exports = { {secretKey:"0xfe6066af949ec3c2c88ac10f47907c6d4e200c37b28b5af49e7d0ffd5c301c5c","balance":"100000000000000000000"} ] }, - onCompileComplete: provisionTokenContracts, istanbulFolder: "./coverage-contracts", modifierWhitelist: ["always", "onlyMiningChain", "onlyNotMiningChain"], } diff --git a/scripts/deployOldExtensionVersions.js b/scripts/deployOldExtensionVersions.js deleted file mode 100644 index 71dc4b66a0..0000000000 --- a/scripts/deployOldExtensionVersions.js +++ /dev/null @@ -1,82 +0,0 @@ -// Input: -/* globals artifacts */ - -const Promise = require("bluebird"); -const exec = Promise.promisify(require("child_process").exec); -const { soliditySha3 } = require("web3-utils"); -const cnAddress = require("../etherrouter-address.json").etherRouterAddress; // eslint-disable-line import/no-unresolved - -const IMetaColony = artifacts.require("./IMetaColony"); -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const ColonyExtension = artifacts.require("./ColonyExtension"); -const Resolver = artifacts.require("./Resolver"); - -module.exports = async (callback) => { - // While debugging, add a line to checkout currenthash - let currentHash = await exec("git log -1 --format='%H'"); - if (currentHash.stdout) { - currentHash = currentHash.stdout; - } - console.log("Current hash is", currentHash); - - const colonyNetwork = await IColonyNetwork.at(cnAddress); - const metaColonyAddress = await colonyNetwork.getMetaColony(); - const metaColony = await IMetaColony.at(metaColonyAddress); - try { - await exec("mv ./build ./buildBackup"); - await exec("git checkout -f lwss && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '19,20 s|^|//|' ./migrations/9_setup_extensions.js"); - await exec("sed -i'' -e '27 s|^|//|' ./migrations/9_setup_extensions.js"); - await exec("sed -i'' -e ' s|EtherRouter.deployed|EtherRouter.new|' ./migrations/9_setup_extensions.js"); - // eslint-disable-next-line no-template-curly-in-string - await exec("sed -i'' -e ' s|installed|installed at address ${resolver.address}|' ./migrations/9_setup_extensions.js"); - - await exec("rm -rf ./build"); - let res = await exec("npx truffle migrate --reset -f 9 --to 9"); - - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - - const regex = /### (.*) extension installed at address ([0-9a-zA-z]*)/g; - const matches = res.matchAll(regex); - - // eslint-disable-next-line no-restricted-syntax - for (const match of matches) { - const NAME_HASH = soliditySha3(match[1]); - const resolver = await Resolver.at(match[2]); - const sig = await resolver.stringToSig("version()"); - const target = await resolver.lookup(sig); - const extensionImplementation = await ColonyExtension.at(target); - const version = await extensionImplementation.version(); - - try { - await metaColony.addExtensionToNetwork(NAME_HASH, match[2]); - console.log(`Installed ${match[1]} version ${version}`); - } catch (err) { - if (err.reason === "colony-network-extension-already-set") { - console.log(`${match[1]} version ${version} is already installed`); - } else { - console.log(err); - } - } - } - } catch (err) { - console.log(err); - } - // console.log(v3ResolverAddress); - // console.log(v4ResolverAddress); - // // put things back how they were. - console.log("Check out original hash"); - await exec(`git checkout -f ${currentHash}`); - console.log("Update submodules"); - await exec("git submodule update"); - console.log("Delete build directory"); - await exec("rm -rf ./build"); - console.log("Restore build directory from backup"); - await exec("mv ./buildBackup ./build"); - callback(); -}; diff --git a/scripts/deployUnmockedColonyVersions.js b/scripts/deployUnmockedColonyVersions.js deleted file mode 100644 index 776cae5f08..0000000000 --- a/scripts/deployUnmockedColonyVersions.js +++ /dev/null @@ -1,128 +0,0 @@ -// Input: -/* globals artifacts */ - -// Check out v3 -// Deploy v3 resolver -// Point v3 on network to that resolver - -// Checkout out v4 -// Deploy v4 resolver -// Point v4 on network to that resolver -const Promise = require("bluebird"); -const exec = Promise.promisify(require("child_process").exec); -const cnAddress = require("../etherrouter-address.json").etherRouterAddress; // eslint-disable-line import/no-unresolved - -const IColonyNetwork = artifacts.require("./IColonyNetwork"); -const IMetaColony = artifacts.require("./IMetaColony"); -const ADDRESS_LENGTH = 42; -const RESOLVER_LOG_OFFSET = 33; - -module.exports = async (callback) => { - // While debugging, add a line to checkout currenthash - const currentHash = await exec("git log -1 --format='%H'"); - let v3ResolverAddress; - let v4ResolverAddress; - let v5ResolverAddress; - let v6ResolverAddress; - let v7ResolverAddress; - const colonyNetwork = await IColonyNetwork.at(cnAddress); - const metaColonyAddress = await colonyNetwork.getMetaColony(); - const metaColony = await IMetaColony.at(metaColonyAddress); - try { - await exec("mv ./build ./buildBackup"); - await exec("git checkout auburn-glider && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '26,27 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e '31 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e 's|await ContractRecovery.deployed()|await ContractRecovery.new()|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("rm -rf ./build"); - let res = await exec("npx truffle migrate --reset -f 4 --to 4"); - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - let index = res.indexOf("Colony version 3 set to Resolver"); - v3ResolverAddress = res.substring(index + RESOLVER_LOG_OFFSET, index + RESOLVER_LOG_OFFSET + ADDRESS_LENGTH); - console.log("v3 address:", v3ResolverAddress); - await metaColony.addNetworkColonyVersion(3, v3ResolverAddress); - - await exec("git checkout -f burgundy-glider && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '27,28 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e '32 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e 's|await ContractRecovery.deployed()|await ContractRecovery.new()|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("rm -rf ./build"); - res = await exec("npx truffle migrate --reset -f 4 --to 4"); - - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - index = res.indexOf("Colony version 4 set to Resolver"); - v4ResolverAddress = res.substring(index + RESOLVER_LOG_OFFSET, index + RESOLVER_LOG_OFFSET + ADDRESS_LENGTH); - await metaColony.addNetworkColonyVersion(4, v4ResolverAddress); - - await exec("git checkout -f lwss && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '29,30 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e '34 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e 's|await ContractRecovery.deployed()|await ContractRecovery.new()|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("rm -rf ./build"); - res = await exec("npx truffle migrate --reset -f 4 --to 4"); - - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - index = res.indexOf("Colony version 5 set to Resolver"); - v5ResolverAddress = res.substring(index + RESOLVER_LOG_OFFSET, index + RESOLVER_LOG_OFFSET + ADDRESS_LENGTH); - await metaColony.addNetworkColonyVersion(5, v5ResolverAddress); - - await exec("git checkout -f clwss && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '29,30 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e '34 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e 's|await ContractRecovery.deployed()|await ContractRecovery.new()|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("rm -rf ./build"); - res = await exec("npx truffle migrate --reset -f 4 --to 4"); - - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - index = res.indexOf("Colony version 6 set to Resolver"); - v6ResolverAddress = res.substring(index + RESOLVER_LOG_OFFSET, index + RESOLVER_LOG_OFFSET + ADDRESS_LENGTH); - await metaColony.addNetworkColonyVersion(6, v6ResolverAddress); - - await exec("git checkout -f dlwss && git submodule update"); - - // Comment out uneeded parts of file - await exec("sed -i'' -e '29,30 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e '34 s|^|//|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("sed -i'' -e 's|await ContractRecovery.deployed()|await ContractRecovery.new()|' ./migrations/4_setup_colony_version_resolver.js"); - await exec("rm -rf ./build"); - res = await exec("npx truffle migrate --reset -f 4 --to 4"); - - if (res.stdout) { - // How this response looks changes node 10->12 - res = res.stdout; - } - index = res.indexOf("Colony version 7 set to Resolver"); - v7ResolverAddress = res.substring(index + RESOLVER_LOG_OFFSET, index + RESOLVER_LOG_OFFSET + ADDRESS_LENGTH); - await metaColony.addNetworkColonyVersion(7, v7ResolverAddress); - } catch (err) { - console.log(err); - } - console.log(v3ResolverAddress); - console.log(v4ResolverAddress); - // put things back how they were. - await exec(`git checkout -f ${currentHash}`); - await exec("git submodule update"); - await exec("rm -rf ./build"); - await exec("mv ./buildBackup ./build"); - callback(); -}; diff --git a/scripts/process-truffle-security.js b/scripts/process-truffle-security.js deleted file mode 100644 index 17792a706d..0000000000 --- a/scripts/process-truffle-security.js +++ /dev/null @@ -1,48 +0,0 @@ -const nthline = require("nthline"); -const findInFiles = require("find-in-files"); -const path = require("path"); - -// This file doesn't exist unless we've run the truffle security package of tests, so we don't expect -// it to exist while running eslint in CI -const results = require("../truffle-security-output.json"); // eslint-disable-line import/no-unresolved - -let fail = false; - -async function main() { - for (let i = 0; i < results.length; i += 1) { - const file = results[i]; - // Only process internal contracts (skip everything we import in /lib) - if (file.filePath.indexOf("/lib/") === -1) { - for (let j = 0; j < file.messages.length; j += 1) { - const message = file.messages[j]; - if (message.ruleId === "N/A") { - // It's the upgrade message, not a real error, so continue to next message - } else { - // Load file, looking for global disables - const globals = await findInFiles.findSync( - `//.*ignore-file-${message.ruleId.toLowerCase()}`, - path.dirname(file.filePath), - path.basename(file.filePath), - ); - if (Object.keys(globals).length === 0) { - // No global ignores. So let's check the specific line. - // load relevant line from file, looking for local disables - try { - const line = await nthline(message.line - 1, file.filePath); - if (line.toLowerCase().search(new RegExp(`//.*ignore-${message.ruleId.toLowerCase()}`, "g")) === -1) { - fail = true; - console.log("Failing file: ", file.filePath); - console.log(message); - } - } catch (err) { - console.log("ERROR:", err); - } - } - } - } - } - } - process.exit(fail); -} - -main(); diff --git a/scripts/provision-safe-contracts.sh b/scripts/provision-safe-contracts.sh deleted file mode 100644 index b70d2cfe79..0000000000 --- a/scripts/provision-safe-contracts.sh +++ /dev/null @@ -1,13 +0,0 @@ -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -cd $DIR -cd .. - -BUILD_DIR="${BUILD_DIR:-build}" - -if [[ "$BUILD_DIR" == "build" ]]; then - echo "No further provisioning needed" - exit 0 -fi - -cp ./build/contracts/Gnosis*.json ./$BUILD_DIR/contracts/ \ No newline at end of file diff --git a/scripts/provision-token-contracts.sh b/scripts/provision-token-contracts.sh deleted file mode 100644 index d43a927c87..0000000000 --- a/scripts/provision-token-contracts.sh +++ /dev/null @@ -1,12 +0,0 @@ -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -cd $DIR -cd .. - -BUILD_DIR="${BUILD_DIR:-build}" - -test ! -d ./$BUILD_DIR/contracts/ && mkdir -p ./$BUILD_DIR/contracts/ - -cp lib/colonyToken/build/contracts/PinnedToken.json ./$BUILD_DIR/contracts/Token.json -cp lib/colonyToken/build/contracts/PinnedTokenAuthority.json ./$BUILD_DIR/contracts/TokenAuthority.json -cp lib/colonyToken/build/contracts/PinnedMultiSigWallet.json ./$BUILD_DIR/contracts/MultiSigWallet.json diff --git a/scripts/resetParity.sh b/scripts/resetParity.sh deleted file mode 100644 index 06aae185d0..0000000000 --- a/scripts/resetParity.sh +++ /dev/null @@ -1,40 +0,0 @@ -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -cd $DIR -cd .. - -if [ ! -e "./parityPassword" ] -then - echo "password" > ./parityPassword -fi - -rm -rf ./keys -rm -rf ./parity-genesis.json -mkdir ./keys - -cp ./parity-genesis.template.json ./parity-genesis.json -# We need to use gsed if it exists (i.e if we're on OSX) -# for cross-platform compatability. -if hash gsed 2>/dev/null; then - SED='gsed' -else - SED='sed' -fi -$SED -i "s/000000000000000000000000000000deadbeef01/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef02/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef03/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef04/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef05/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef06/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef07/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef08/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef09/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef10/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef11/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef12/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef13/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef14/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef15/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef16/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef17/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json -$SED -i "s/000000000000000000000000000000deadbeef18/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json From 363410411559ddab0918d4701791371a34b0de21 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Mon, 17 Jun 2024 14:44:31 -0400 Subject: [PATCH 3/9] Reorganize package.json scripts --- .circleci/config.yml | 3 --- package.json | 52 +++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f015639cbe..5654caf35b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -231,9 +231,6 @@ jobs: - run: name: "Reset chains" command: rm -rf ganache-chain-db* - - run: - name: "Reset ganache chain" - command: rm -rf ganache-chain-db* - run: name: "Running patricia tree tests" command: pnpm run test:contracts:patricia diff --git a/package.json b/package.json index 4d4056dfba..38b5f8756a 100644 --- a/package.json +++ b/package.json @@ -8,22 +8,22 @@ }, "scripts": { "preinstall": "npx only-allow pnpm", - "solhint-staged": "bash ./scripts/solhint.sh", "prepare": "husky install", - "eslint-staged": "bash ./scripts/eslint.sh", - "prettier-contracts-staged": "bash ./scripts/prettier-contracts.sh", "eslint": "eslint .", + "eslint-staged": "bash ./scripts/eslint.sh", "solhint": "solhint ./contracts/**/*.sol", + "solhint-staged": "bash ./scripts/solhint.sh", "build:docs": "scripts/docgen.js", - "ping:osx": "osascript -e 'display notification \"Ping!\"'", + "prettier-contracts-staged": "bash ./scripts/prettier-contracts.sh", + "check:auth": "./scripts/check-auth.js", "check:gitchanges": "./scripts/no-git-changes.sh", "check:storagevars": "./scripts/check-storage.js", - "normalize:storageSlots": "./scripts/normalize-storage-slots.js", "check:recoverymods": "./scripts/check-recovery.js", - "check:coverage": "istanbul-combine -d coverage-merged -p detail -r html -r json coverage-*/coverage-final.json && istanbul check-coverage ./coverage-merged/coverage-final.json --statements 99 --branches 94 --functions 99 --lines 99", - "check:auth": "./scripts/check-auth.js", "check:versioning": "bash ./scripts/versioningCheck.sh", + "check:coverage": "istanbul-combine -d coverage-merged -p detail -r html -r json coverage-*/coverage-final.json && istanbul check-coverage ./coverage-merged/coverage-final.json --statements 99 --branches 94 --functions 99 --lines 99", "version:contracts": "bash ./scripts/version-contracts.sh", + "flatten:contracts": "mkdir -p ./build/flattened/ && steamroller contracts/colonyNetwork/IColonyNetwork.sol > build/flattened/flatIColonyNetwork.sol && steamroller contracts/colony/IColony.sol > build/flattened/flatIColony.sol && steamroller contracts/reputationMiningCycle/IReputationMiningCycle.sol > build/flattened/flatIReputationMiningCycle.sol && steamroller contracts/colony/IMetaColony.sol > build/flattened/flatIMetaColony.sol && steamroller contracts/common/IRecovery.sol > build/flattened/flatIRecovery.sol && steamroller contracts/common/IEtherRouter.sol > build/flattened/flatIEtherRouter.sol", + "normalize:storageSlots": "./scripts/normalize-storage-slots.js", "generate:test:contracts": "bash ./scripts/generate-test-contracts.sh", "clean:test:contracts": "rimraf ./contracts/*Updated*.*", "clean:contracts": "rimraf ./build/contracts/*", @@ -33,43 +33,41 @@ "start:blockchain:client:2": "PORT=8546 DBPATH=./ganache-chain-db-2 bash ./scripts/start-blockchain-client.sh", "start:blockchain:client:both": "CHAIN_ID=$CHAIN_ID_1 pnpm run start:blockchain:client & sleep 1 && CHAIN_ID=$CHAIN_ID_2 pnpm run start:blockchain:client:2", "start:reputation:oracle": "./scripts/start-reputation-oracle.js", - "reset:blockchain:client": "pnpm run stop:blockchain:client && rm -rf ./ganache-chain-db*", "stop:blockchain:client": "bash ./scripts/stop-blockchain-client.sh", "fork:goerli": "ganache --fork https://goerli.infura.io/v3/e21146aa267845a2b7b4da025178196d --port 8605", "fork:mainnet": "ganache --fork https://mainnet.infura.io/v3/e21146aa267845a2b7b4da025178196d --port 8601", - "flatten:contracts": "mkdir -p ./build/flattened/ && steamroller contracts/colonyNetwork/IColonyNetwork.sol > build/flattened/flatIColonyNetwork.sol && steamroller contracts/colony/IColony.sol > build/flattened/flatIColony.sol && steamroller contracts/reputationMiningCycle/IReputationMiningCycle.sol > build/flattened/flatIReputationMiningCycle.sol && steamroller contracts/colony/IMetaColony.sol > build/flattened/flatIMetaColony.sol && steamroller contracts/common/IRecovery.sol > build/flattened/flatIRecovery.sol && steamroller contracts/common/IEtherRouter.sol > build/flattened/flatIEtherRouter.sol", - "test:reputation:1": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/*.js --network development", - "test:reputation:2": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", - "test:reputation:1:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/*.js --network development", - "test:reputation:2:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", - "test:reputation:coverage": "npx hardhat coverage --solcoverjs ./.solcover.reputation.js --temp build-coverage --testfiles './test/reputation-system/**/*'", + "pretest:contracts": "pnpm run stop:blockchain:client", + "pretest:contracts:extensions": "pnpm run stop:blockchain:client", "test:contracts": "pnpm run start:blockchain:client && npx hardhat test ./test/contracts-network/* ./test/packages/* --network development", - "test:contracts:bridging:1": "CHAIN_ID_1=265669100 CHAIN_ID_2=265669101 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat test ./test/cross-chain/* --network development", - "test:contracts:bridging:2": "CHAIN_ID_1=265669101 CHAIN_ID_2=265669100 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat test ./test/cross-chain/* --network development", - "test:contracts:bridging:1:coverage": "CHAIN_ID=265669101 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat --show-stack-traces coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", - "test:contracts:bridging:2:coverage": "CHAIN_ID=265669100 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", "test:contracts:extensions": "pnpm run start:blockchain:client && npx hardhat test ./test/extensions/* --network development", - "test:contracts:chainid": "pnpm run start:blockchain:client && npx hardhat test ./test-chainid/*", - "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover.chainid.js --temp build-coverage --testfiles './test-chainid/**/*'", "test:contracts:upgrade:parity": "pnpm run clean:test:contracts | pnpm run start:blockchain:client parity & pnpm run generate:test:contracts && npx hardhat test ./test-upgrade/* --network integration", "test:contracts:upgrade:ganache": "pnpm run clean:test:contracts | pnpm run start:blockchain:client ganache & pnpm run generate:test:contracts && npx hardhat test ./test-upgrade/* --network development", - "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover.upgrade.js --temp build-coverage --testfiles './test-upgrade/*'", "test:contracts:gasCosts": "pnpm run start:blockchain:client && npx hardhat test test-gas-costs/gasCosts.js --network development", "test:contracts:patricia": "pnpm run start:blockchain:client ganache && npx hardhat test packages/reputation-miner/patricia-test.js --network integration", + "test:contracts:bridging:1": "CHAIN_ID_1=265669100 CHAIN_ID_2=265669101 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat test ./test/cross-chain/* --network development", + "test:contracts:bridging:2": "CHAIN_ID_1=265669101 CHAIN_ID_2=265669100 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat test ./test/cross-chain/* --network development", + "test:contracts:chainid": "pnpm run start:blockchain:client && npx hardhat test ./test-chainid/*", + "test:contracts:e2e": "pnpm run start:blockchain:client && npx hardhat test test-system/end-to-end.js --network development", "test:contracts:coverage": "npx hardhat coverage --temp build-coverage --testfiles './test/contracts-network/*'", "test:contracts:extensions:coverage": "npx hardhat compile && NODE_OPTIONS='--max-old-space-size=6144' npx hardhat coverage --solcoverjs ./.solcover.extensions.js --temp build-coverage --testfiles './test/extensions/*'", - "test:contracts:e2e": "pnpm run start:blockchain:client && npx hardhat test test-system/end-to-end.js --network development", + "test:contracts:bridging:1:coverage": "CHAIN_ID=265669101 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat --show-stack-traces coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", + "test:contracts:bridging:2:coverage": "CHAIN_ID=265669100 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", + "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover.chainid.js --temp build-coverage --testfiles './test-chainid/**/*'", + "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover.upgrade.js --temp build-coverage --testfiles './test-upgrade/*'", + "test:reputation:1": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/*.js --network development", + "test:reputation:2": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", + "test:reputation:1:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/*.js --network development", + "test:reputation:2:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", + "test:reputation:coverage": "npx hardhat coverage --solcoverjs ./.solcover.reputation.js --temp build-coverage --testfiles './test/reputation-system/**/*'", "test:security:slither": "slither . --solc-disable-warnings --exclude-low --exclude-informational --exclude-optimization --filter-paths 'lib|contracts/testHelpers|@openzeppelin'", - "viz:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/viz-bootstrap.js", - "kyc:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/kyc-bootstrap.js", - "pretest:contracts": "pnpm run stop:blockchain:client", - "pretest:contracts:extensions": "pnpm run stop:blockchain:client", "posttest:contracts": "pnpm run stop:blockchain:client", "posttest:contracts:extensions": "pnpm run stop:blockchain:client", "posttest:contracts:upgrade:parity": "pnpm run clean:test:contracts | pnpm run stop:blockchain:client", "posttest:contracts:upgrade:ganache": "pnpm run clean:test:contracts | pnpm run stop:blockchain:client", "posttest:contracts:gasCosts": "pnpm run stop:blockchain:client", - "posttest:contracts:patricia": "pnpm run stop:blockchain:client" + "posttest:contracts:patricia": "pnpm run stop:blockchain:client", + "viz:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/viz-bootstrap.js", + "kyc:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/kyc-bootstrap.js" }, "repository": { "type": "git", From e04e7eeecded881f141b201395a038eba9e8fd16 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jun 2024 09:45:18 -0400 Subject: [PATCH 4/9] Clean up .circle/config.yml --- .circleci/config.yml | 52 +++++++++++++------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5654caf35b..8306065c82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,7 +15,7 @@ job_python: &job_python username: colonyci password: $COLONYCI_DOCKERHUB_PASSWORD working_directory: ~/colonyNetwork -step_setup_pnpm: &step_setup_pnpm #Only used in python image, as node image comes with it +step_setup_pnpm: &step_setup_pnpm # Only used in python image, as node image comes with it run: name: "Install pnpm" command: sudo npm i -g pnpm@8.14.1 #Same version as in cimg/node:20.11.0 @@ -41,17 +41,6 @@ step_pull_solc_docker: &step_pull_solc_docker run: name: "Pull solc docker image" command: docker pull ethereum/solc:0.5.8 -step_setup_slither: &step_setup_slither - run: - name: "Setup slither analyser https://github.com/crytic/slither" - command: | - wget https://github.com/ethereum/solidity/releases/download/v0.5.8/solc-static-linux - chmod +x solc-static-linux - sudo mv solc-static-linux /usr/local/bin/solc - pip install slither-analyzer - pip install solc-select - solc-select install 0.8.25 - solc-select use 0.8.25 step_install_nvm: &step_install_nvm run: name: "Install nvm" @@ -147,7 +136,6 @@ jobs: environment: NODE_OPTIONS: --max-old-space-size=6144 - <<: *step_save_cache - # Save test results - store_test_results: path: test-results.xml - store_artifacts: @@ -170,7 +158,6 @@ jobs: environment: NODE_OPTIONS: --max-old-space-size=6144 - <<: *step_save_cache - # Save test results - store_test_results: path: test-results.xml - store_artifacts: @@ -186,6 +173,7 @@ jobs: version: docker23 - <<: *step_pull_solc_docker - <<: *step_setup_global_packages + - <<: *step_install_lsof - run: name: "Download parity" command: wget https://releases.parity.io/ethereum/v2.7.2/x86_64-unknown-linux-gnu/parity @@ -214,20 +202,14 @@ jobs: sed -i "s/000000000000000000000000000000deadbeef16/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json sed -i "s/000000000000000000000000000000deadbeef17/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json sed -i "s/000000000000000000000000000000deadbeef18/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json - - <<: *step_install_lsof + - run: + name: "Running gas cost tests" + command: pnpm run test:contracts:gasCosts && npx codechecks - run: name: "Running ganache upgrade tests" command: pnpm run test:contracts:upgrade:ganache environment: NODE_OPTIONS: --max-old-space-size=6144 - # name: "Running parity upgrade tests" - # command: pnpm run test:contracts:upgrade:parity - # environment: - # NODE_OPTIONS: --max-old-space-size=6144 - - run: - name: "Running gas cost tests" - command: pnpm run test:contracts:gasCosts && npx codechecks - - <<: *step_install_lsof - run: name: "Reset chains" command: rm -rf ganache-chain-db* @@ -235,7 +217,6 @@ jobs: name: "Running patricia tree tests" command: pnpm run test:contracts:patricia - <<: *step_save_cache - # Save test results - store_test_results: path: test-results.xml - store_artifacts: @@ -368,7 +349,6 @@ jobs: command: pnpm run test:contracts:bridging:1:coverage environment: NODE_OPTIONS: --max-old-space-size=6144 - - <<: *step_install_lsof - run: name: "Running coverage tests for foreign-side of bridge" command: pnpm run test:contracts:bridging:2:coverage @@ -454,7 +434,6 @@ jobs: - run: name: "Merge coverage runs and check coverage thresholds" command: pnpm run check:coverage - # Save coverage artifacts - store_artifacts: path: coverage-merged security-analysis: @@ -467,7 +446,16 @@ jobs: version: docker23 - <<: *step_pull_solc_docker - <<: *step_setup_global_packages - - <<: *step_setup_slither + - run: + name: "Setup slither analyser https://github.com/crytic/slither" + command: | + wget https://github.com/ethereum/solidity/releases/download/v0.5.8/solc-static-linux + chmod +x solc-static-linux + sudo mv solc-static-linux /usr/local/bin/solc + pip install slither-analyzer + pip install solc-select + solc-select install 0.8.25 + solc-select use 0.8.25 - run: name: "Slither analysis" command: pnpm run test:security:slither @@ -531,13 +519,3 @@ workflows: - coverage-test-chainid - coverage-test-upgrade - coverage-test-bridging - # nightly: - # triggers: - # - schedule: - # cron: "0 1 * * *" # 1am UTC - # filters: - # branches: - # only: - # - develop - # jobs: - # - end-to-end-tests From 4852a71785ab6908126ffaa648f071772187b1c2 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jun 2024 09:46:24 -0400 Subject: [PATCH 5/9] Delete task-related scripts and tests --- helpers/task-review-signing.js | 128 - .../colony-task-work-rating.js | 451 ---- test/contracts-network/colony-task.js | 2177 ----------------- 3 files changed, 2756 deletions(-) delete mode 100644 helpers/task-review-signing.js delete mode 100644 test/contracts-network/colony-task-work-rating.js delete mode 100644 test/contracts-network/colony-task.js diff --git a/helpers/task-review-signing.js b/helpers/task-review-signing.js deleted file mode 100644 index 933a1f70c3..0000000000 --- a/helpers/task-review-signing.js +++ /dev/null @@ -1,128 +0,0 @@ -const { soliditySha3, padLeft } = require("web3-utils"); -const { hashPersonalMessage, ecsign } = require("ethereumjs-util"); -const fs = require("fs"); -const { ethers } = require("ethers"); -const { encodeTxData } = require("./test-helper"); - -exports.executeSignedTaskChange = async function executeSignedTaskChange({ colony, taskId, functionName, signers, privKeys, sigTypes, args }) { - const { sigV, sigR, sigS, txData } = await exports.getSigsAndTransactionData({ colony, taskId, functionName, signers, privKeys, sigTypes, args }); - return colony.executeTaskChange(sigV, sigR, sigS, sigTypes, 0, txData); -}; - -exports.executeSignedRoleAssignment = async function executeSignedRoleAssignment({ - colony, - taskId, - functionName, - signers, - privKeys, - sigTypes, - args, -}) { - const { sigV, sigR, sigS, txData } = await exports.getSigsAndTransactionData({ colony, taskId, functionName, signers, privKeys, sigTypes, args }); - return colony.executeTaskRoleAssignment(sigV, sigR, sigS, sigTypes, 0, txData); -}; - -exports.getSigsAndTransactionData = async function getSigsAndTransactionData({ colony, taskId, functionName, signers, privKeys, sigTypes, args }) { - // We have to pass in an ethers BN because of https://github.com/ethereum/web3.js/issues/1920 - // and https://github.com/ethereum/web3.js/issues/2077 - const txData = await encodeTxData(colony, functionName, args); - const ethersBNTaskId = ethers.BigNumber.from(taskId.toString()); - const sigsPromises = sigTypes.map((type, i) => { - let privKey = []; - if (privKeys) { - privKey = [privKeys[i]]; - } - if (type === 0) { - return exports.createSignatures(colony, ethersBNTaskId, [signers[i]], privKey, 0, txData); - } - return exports.createSignaturesTrezor(colony, ethersBNTaskId, [signers[i]], privKey, 0, txData); - }); - const sigs = await Promise.all(sigsPromises); - const sigV = sigs.map((sig) => sig.sigV[0]); - const sigR = sigs.map((sig) => sig.sigR[0]); - const sigS = sigs.map((sig) => sig.sigS[0]); - return { sigV, sigR, sigS, txData }; -}; - -exports.createSignatures = async function createSignatures(colony, taskId, signers, privKeys, value, data) { - const sourceAddress = colony.address; - const destinationAddress = colony.address; - const nonce = await colony.getTaskChangeNonce(taskId); - const input = `0x${sourceAddress.slice(2)}${destinationAddress.slice(2)}${padLeft(value.toString(16), "64", "0")}${data.slice(2)}${padLeft( - nonce.toString(16), - "64", - "0", - )}`; // eslint-disable-line max-len - const sigV = []; - const sigR = []; - const sigS = []; - const msgHash = soliditySha3(input); - - let accountsJson; - // When private keys are not provided, refer to the local test accounts generated by ganache-cli - if (privKeys.length === 0) { - accountsJson = JSON.parse(fs.readFileSync("./ganache-accounts.json", "utf8")); - } - - for (let i = 0; i < signers.length; i += 1) { - let user = signers[i].toString(); - user = user.toLowerCase(); - - let privKey; - if (privKeys[i]) { - privKey = privKeys[i].replace("0x", ""); - } else { - privKey = accountsJson.private_keys[user].replace("0x", ""); - } - - const prefixedMessageHash = hashPersonalMessage(Buffer.from(msgHash.slice(2), "hex")); - const sig = ecsign(prefixedMessageHash, Buffer.from(privKey, "hex")); - - sigV.push(sig.v); - sigR.push(`0x${sig.r.toString("hex")}`); - sigS.push(`0x${sig.s.toString("hex")}`); - } - - return { sigV, sigR, sigS }; -}; - -exports.createSignaturesTrezor = async function createSignaturesTrezor(colony, taskId, signers, privKeys, value, data) { - const sourceAddress = colony.address; - const destinationAddress = colony.address; - const nonce = await colony.getTaskChangeNonce(taskId); - const input = `0x${sourceAddress.slice(2)}${destinationAddress.slice(2)}${padLeft(value.toString(16), "64", "0")}${data.slice(2)}${padLeft( - nonce.toString(16), - "64", - "0", - )}`; // eslint-disable-line max-len - const sigV = []; - const sigR = []; - const sigS = []; - const msgHash = soliditySha3(input); - - let accountsJson; - // When private keys are not provided, refer to the local test accounts generated by ganache-cli - if (privKeys.length === 0) { - accountsJson = JSON.parse(fs.readFileSync("./ganache-accounts.json", "utf8")); - } - - for (let i = 0; i < signers.length; i += 1) { - let user = signers[i].toString(); - user = user.toLowerCase(); - - let privKey; - if (privKeys[i]) { - privKey = privKeys[i].replace("0x", ""); - } else { - privKey = accountsJson.private_keys[user].replace("0x", ""); - } - - const prefixedMessageHash = soliditySha3("\x19Ethereum Signed Message:\n\x20", msgHash); - const sig = ecsign(Buffer.from(prefixedMessageHash.slice(2), "hex"), Buffer.from(privKey, "hex")); - sigV.push(sig.v); - sigR.push(`0x${sig.r.toString("hex")}`); - sigS.push(`0x${sig.s.toString("hex")}`); - } - - return { sigV, sigR, sigS }; -}; diff --git a/test/contracts-network/colony-task-work-rating.js b/test/contracts-network/colony-task-work-rating.js deleted file mode 100644 index c46b401ae0..0000000000 --- a/test/contracts-network/colony-task-work-rating.js +++ /dev/null @@ -1,451 +0,0 @@ -/* globals artifacts */ -const chai = require("chai"); -const bnChai = require("bn-chai"); -const { soliditySha3 } = require("web3-utils"); - -const { - MANAGER_RATING, - WORKER_RATING, - RATING_1_SALT, - RATING_2_SALT, - RATING_1_SECRET, - RATING_2_SECRET, - MANAGER_ROLE, - EVALUATOR_ROLE, - WORKER_ROLE, - DELIVERABLE_HASH, - INITIAL_FUNDING, - SECONDS_PER_DAY, -} = require("../../helpers/constants"); -const { currentBlockTime, checkErrorRevert, forwardTime, expectEvent } = require("../../helpers/test-helper"); -const { fundColonyWithTokens, setupAssignedTask, setupRatedTask, setupRandomColony } = require("../../helpers/test-data-generator"); - -const { expect } = chai; -chai.use(bnChai(web3.utils.BN)); - -const IColonyNetwork = artifacts.require("IColonyNetwork"); -const EtherRouter = artifacts.require("EtherRouter"); - -contract.skip("Colony Task Work Rating", (accounts) => { - const MANAGER = accounts[0]; - const EVALUATOR = MANAGER; - const WORKER = accounts[2]; - const OTHER = accounts[3]; - - let colony; - let colonyNetwork; - let token; - - before(async () => { - const cnAddress = (await EtherRouter.deployed()).address; - - const etherRouter = await EtherRouter.at(cnAddress); - colonyNetwork = await IColonyNetwork.at(etherRouter.address); - }); - - beforeEach(async () => { - ({ colony, token } = await setupRandomColony(colonyNetwork)); - }); - - describe("when rating task work", () => { - it("should allow rating, before the due date but after the work has been submitted", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }); - - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - const currentTime1 = await currentBlockTime(); - const rating1 = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(rating1.nSecrets).to.eq.BN(1); - expect(rating1.lastSubmittedAt.toNumber()).to.be.closeTo(currentTime1, 2); - const ratingSecret1 = await colony.getTaskWorkRatingSecret(taskId, WORKER_ROLE); - expect(ratingSecret1).to.eq.BN(RATING_2_SECRET); - - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - const currentTime2 = await currentBlockTime(); - const rating2 = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(rating2.nSecrets).to.eq.BN(2); - expect(rating2.lastSubmittedAt.toNumber()).to.be.closeTo(currentTime2, 2); - const ratingSecret2 = await colony.getTaskWorkRatingSecret(taskId, MANAGER_ROLE); - expect(ratingSecret2).to.eq.BN(RATING_1_SECRET); - }); - - it("should allow combined submission and rating, before the due date", async () => { - const currentTime = await currentBlockTime(); - const dueDate = currentTime + SECONDS_PER_DAY * 7; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - - await colony.submitTaskDeliverableAndRating(taskId, DELIVERABLE_HASH, RATING_1_SECRET, { from: WORKER }); - const currentTime2 = await currentBlockTime(); - const ratings = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratings.nSecrets).to.eq.BN(1); - expect(ratings.lastSubmittedAt.toNumber()).to.be.closeTo(currentTime2, 2); - const ratingSecret = await colony.getTaskWorkRatingSecret(taskId, MANAGER_ROLE); - expect(ratingSecret).to.eq.BN(RATING_1_SECRET); - }); - - it("should allow rating after the due date has passed when no work has been submitted and the manager has marked the task complete", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - const ratingSecret1 = await colony.getTaskWorkRatingSecret(taskId, MANAGER_ROLE); - const ratingSecret2 = await colony.getTaskWorkRatingSecret(taskId, WORKER_ROLE); - expect(ratingSecret1).to.eq.BN(RATING_1_SECRET); - expect(ratingSecret2).to.eq.BN(RATING_2_SECRET); - }); - - it("should fail if I try to rate before task's due date has passed and work has not been submitted", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await checkErrorRevert(colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }), "colony-task-not-complete"); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.be.zero; - }); - - it.skip("should not allow the manager to mark a task as complete if no due date is set", async () => { - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate: 0 }); - await checkErrorRevert(colony.completeTask(taskId), "colony-task-due-date-not-set"); - }); - - it("should not allow the manager to mark a task as complete if before the due date and work has not been submitted", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await checkErrorRevert(colony.completeTask(taskId), "colony-task-due-date-in-future"); - }); - - it("should not allow the manager to (re-)mark a task as complete if work has already been submitted", async () => { - const taskId = await setupAssignedTask({ colonyNetwork, colony }); - await colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }); - await checkErrorRevert(colony.completeTask(taskId), "colony-task-complete"); - }); - - it("should allow the manager to mark a task as complete if after the due date and no work has been submitted", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - }); - - it("should not allow ratings to be submitted after the due date if no work is submitted and task not marked complete", async () => { - const taskId = await setupAssignedTask({ colonyNetwork, colony }); - await checkErrorRevert(colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }), "colony-task-not-complete"); - await checkErrorRevert(colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }), "colony-task-not-complete"); - }); - - it("should fail if user rates worker on behalf of the evaluator", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: OTHER }), - "colony-user-cannot-rate-task-worker", - ); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets[1]).to.be.zero; - }); - - it("should fail if user rates manager on behalf of the worker", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: OTHER }), - "colony-user-cannot-rate-task-manager", - ); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.be.zero; - }); - - it("should fail if I try to rate work for a role that's not setup to be rated", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, EVALUATOR_ROLE, RATING_2_SECRET, { from: EVALUATOR }), - "colony-unsupported-role-to-rate", - ); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.be.zero; - }); - - it("should fail, if I try to rate work twice", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_1_SECRET, { from: EVALUATOR }), - "colony-task-rating-secret-already-exists", - ); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.eq.BN(1); - const ratingSecret = await colony.getTaskWorkRatingSecret(taskId, WORKER_ROLE); - expect(ratingSecret).to.eq.BN(RATING_2_SECRET); - }); - - it("should fail if I try to rate a task too late", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }), - "colony-task-rating-secret-submit-period-closed", - ); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.be.zero; - }); - - it("should fail if I try to rate task using an invalid id", async () => { - const taskId = await setupAssignedTask({ colonyNetwork, colony }); - - await checkErrorRevert(colony.submitTaskWorkRating(10, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }), "colony-task-not-complete"); - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - expect(ratingSecrets.nSecrets).to.be.zero; - }); - - it("should fail if I try to submit an empty rating", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - - const EMPTY_RATING_SECRET = web3.utils.fromAscii(""); - await checkErrorRevert( - colony.submitTaskWorkRating(taskId, WORKER_ROLE, EMPTY_RATING_SECRET, { from: EVALUATOR }), - "colony-task-rating-secret-missing", - ); - - const ratingSecrets = await colony.getTaskWorkRatingSecretsInfo(taskId); - // No rating was accepted. Ratings count is 0 - expect(ratingSecrets.nSecrets).to.be.zero; - }); - }); - - describe("when revealing a task work rating", () => { - it("should allow revealing a rating by evaluator and worker", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupRatedTask({ colonyNetwork, colony, token }); - - const roleManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(roleManager.rating).to.eq.BN(MANAGER_RATING); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rateFail).to.be.false; - expect(roleWorker.rating).to.eq.BN(WORKER_RATING); - - const roleEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(roleEvaluator.rateFail).to.be.false; - }); - - it("should allow revealing a rating from the evaluator after the 5 days wait for rating commits expires", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 8; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.submitTaskDeliverable(1, DELIVERABLE_HASH, { from: WORKER }); - await colony.submitTaskWorkRating(1, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await colony.revealTaskWorkRating(1, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rating).to.eq.BN(WORKER_RATING); - - const roleEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(roleEvaluator.rateFail).to.be.false; - }); - - it("should fail if I try to reveal rating with an incorrect secret", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, MANAGER_ROLE, MANAGER_RATING, RATING_2_SALT, { from: WORKER }), - "colony-task-rating-secret-mismatch", - ); - - const roleManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(roleManager.rating).to.be.zero; - }); - - it("should fail if there are two rating secrets and I try to reveal the one from the evaluator late", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await forwardTime(SECONDS_PER_DAY * 5 + 2, this); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }), - "colony-task-rating-secret-reveal-period-closed", - ); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rating).to.be.zero; - }); - - it("should fail if there are two rating secrets and I try to reveal the one from the worker late", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await forwardTime(SECONDS_PER_DAY * 5 + 2, this); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, MANAGER_ROLE, MANAGER_RATING, RATING_1_SALT, { from: WORKER }), - "colony-task-rating-secret-reveal-period-closed", - ); - - const roleManager = await colony.getTaskRole(1, MANAGER_ROLE); - expect(roleManager.rating).to.be.zero; - }); - - it("should fail if evaluator tries to reveal rating before the 5 days wait for rating commits expires", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - await forwardTime(SECONDS_PER_DAY * 4, this); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }), - "colony-task-rating-secret-reveal-period-not-open", - ); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rating).to.be.zero; - }); - - it("should fail if evaluator tries to reveal rating after 5 days wait for rating reveal expires", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await forwardTime(SECONDS_PER_DAY * 10 + 1, this); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }), - "colony-task-rating-secret-reveal-period-closed", - ); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rating).to.be.zero; - }); - - it("should fail if the submitted rating was None", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - const badWorkerRating = 0; - const ratingSecret = soliditySha3(RATING_2_SALT, badWorkerRating); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, ratingSecret, { from: EVALUATOR }); - - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await checkErrorRevert( - colony.revealTaskWorkRating(taskId, WORKER_ROLE, badWorkerRating, RATING_2_SALT, { from: EVALUATOR }), - "colony-task-rating-missing", - ); - }); - - it("should log a TaskWorkRatingRevealed event", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 8; - - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.submitTaskDeliverable(1, DELIVERABLE_HASH, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - - await expectEvent( - colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }), - "TaskWorkRatingRevealed", - [EVALUATOR, taskId, WORKER_ROLE, WORKER_RATING], - ); - }); - }); - - describe("when assigning work ratings after the user not commiting or revealing on time", () => { - it("should assign rating 2 to manager and penalise worker, when they haven't submitted rating on time", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }); - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await colony.finalizeTask(taskId); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rateFail).to.be.true; - expect(roleWorker.rating).to.eq.BN(WORKER_RATING); - - const roleManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(roleManager.rating).to.eq.BN(2); - - const roleEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(roleEvaluator.rateFail).to.be.false; - }); - - it("should assign rating 2 to worker and 1 to evaluator if evaluator hasn't submitted rating on time", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await colony.submitTaskWorkRating(taskId, MANAGER_ROLE, RATING_1_SECRET, { from: WORKER }); - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await colony.revealTaskWorkRating(taskId, MANAGER_ROLE, MANAGER_RATING, RATING_1_SALT, { from: WORKER }); - await forwardTime(SECONDS_PER_DAY * 5 + 1, this); - await colony.finalizeTask(taskId); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rateFail).to.be.false; - expect(roleWorker.rating).to.eq.BN(2); - - const roleManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(roleManager.rateFail).to.be.false; - expect(roleManager.rating).to.eq.BN(MANAGER_RATING); - - const roleEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(roleEvaluator.rateFail).to.be.true; - expect(roleEvaluator.rating).to.eq.BN(1); - }); - - it("should assign rating 2 to manager and 2 to worker, with penalties, when no one has submitted any ratings", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await forwardTime(SECONDS_PER_DAY * 10 + 1, this); - await colony.finalizeTask(taskId); - - const roleWorker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(roleWorker.rateFail).to.be.true; - expect(roleWorker.rating).to.eq.BN(2); - - const roleManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(roleManager.rateFail).to.be.false; - expect(roleManager.rating).to.eq.BN(2); - - const roleEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(roleEvaluator.rateFail).to.be.true; - expect(roleEvaluator.rating).to.eq.BN(1); - }); - - it("should revert if I try to assign ratings before the reveal period is over", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.completeTask(taskId); - await forwardTime(SECONDS_PER_DAY * 6, this); - await checkErrorRevert(colony.finalizeTask(1), "colony-task-ratings-incomplete"); - const roleWorker = await colony.getTaskRole(1, WORKER_ROLE); - expect(roleWorker.rateFail).to.be.false; - }); - }); -}); diff --git a/test/contracts-network/colony-task.js b/test/contracts-network/colony-task.js deleted file mode 100644 index 84a843ba3d..0000000000 --- a/test/contracts-network/colony-task.js +++ /dev/null @@ -1,2177 +0,0 @@ -/* global artifacts */ -const BN = require("bn.js"); -const { ethers } = require("ethers"); -const chai = require("chai"); -const bnChai = require("bn-chai"); -const { soliditySha3 } = require("web3-utils"); - -const { - UINT256_MAX, - WAD, - MANAGER_ROLE, - EVALUATOR_ROLE, - WORKER_ROLE, - SPECIFICATION_HASH, - SPECIFICATION_HASH_UPDATED, - DELIVERABLE_HASH, - INITIAL_FUNDING, - SECONDS_PER_DAY, - MANAGER_PAYOUT, - WORKER_PAYOUT, - EVALUATOR_PAYOUT, - ACTIVE_TASK_STATE, - CANCELLED_TASK_STATE, - FINALIZED_TASK_STATE, - MANAGER_RATING, - WORKER_RATING, - RATING_1_SALT, - RATING_2_SALT, - RATING_1_SECRET, - RATING_2_SECRET, - MAX_PAYOUT, - GLOBAL_SKILL_ID, - ADDRESS_ZERO, -} = require("../../helpers/constants"); - -const { getSigsAndTransactionData, executeSignedTaskChange, executeSignedRoleAssignment } = require("../../helpers/task-review-signing"); - -const { - getTokenArgs, - web3GetBalance, - checkErrorRevert, - expectEvent, - expectAllEvents, - forwardTime, - currentBlockTime, - web3GetStorageAt, -} = require("../../helpers/test-helper"); - -const { - fundColonyWithTokens, - setupFinalizedTask, - setupRatedTask, - setupAssignedTask, - setupFundedTask, - makeTask, - setupRandomColony, - assignRoles, -} = require("../../helpers/test-data-generator"); -const { setupEtherRouter } = require("../../helpers/upgradable-contracts"); - -const { expect } = chai; -chai.use(bnChai(web3.utils.BN)); - -const EtherRouter = artifacts.require("EtherRouter"); -const IMetaColony = artifacts.require("IMetaColony"); -const IColonyNetwork = artifacts.require("IColonyNetwork"); -const Token = artifacts.require("Token"); -const IReputationMiningCycle = artifacts.require("IReputationMiningCycle"); -const TestExtension0 = artifacts.require("TestExtension0"); -const Resolver = artifacts.require("Resolver"); - -contract.skip("ColonyTask", (accounts) => { - const MANAGER = accounts[0]; - const EVALUATOR = MANAGER; - const WORKER = accounts[2]; - const OTHER = accounts[3]; - const COLONY_ADMIN = accounts[4]; - - let colony; - let metaColony; - let token; - let otherToken; - let colonyNetwork; - - before(async () => { - const cnAddress = (await EtherRouter.deployed()).address; - - const etherRouter = await EtherRouter.at(cnAddress); - 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, COLONY_ADMIN, 1, true); - - const otherTokenArgs = getTokenArgs(); - otherToken = await Token.new(...otherTokenArgs); - await otherToken.unlock(); - }); - - describe("when creating tasks", () => { - it("should allow admins to make task", async () => { - const dueDate = await currentBlockTime(); - const taskId = await makeTask({ colony, dueDate }); - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.equal(SPECIFICATION_HASH); - expect(task.deliverableHash).to.equal(ethers.constants.HashZero); - expect(task.status).to.eq.BN(ACTIVE_TASK_STATE); - expect(task.dueDate).to.eq.BN(dueDate); - expect(task.domainId).to.eq.BN(1); - }); - - it("should fail if a non-admin user tries to make a task", async () => { - const taskCountBefore = await colony.getTaskCount(); - await checkErrorRevert(colony.makeTask(1, UINT256_MAX, SPECIFICATION_HASH, 1, 1, 0, { from: OTHER }), "ds-auth-unauthorized"); - const taskCountAfter = await colony.getTaskCount(); - expect(taskCountBefore).to.be.eq.BN(taskCountAfter); - }); - - it("should set the task manager as the creator and evaluator", async () => { - const taskId = await makeTask({ colony }); - - const taskManager = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(taskManager.user).to.equal(MANAGER); - - const taskEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(taskEvaluator.user).to.equal(MANAGER); - }); - - it("should allow the reassignment of evaluator", async () => { - const newEvaluator = accounts[1]; - expect(MANAGER).to.not.equal(newEvaluator); - - const taskId = await makeTask({ colony }); - - let taskEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(taskEvaluator.user).to.equal(EVALUATOR); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskEvaluatorRole", - signers: [MANAGER], // NOTE: only one signature because manager === evaluator - sigTypes: [0], - args: [taskId], - }); - - taskEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(taskEvaluator.user).to.equal(ethers.constants.AddressZero); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER, newEvaluator], - sigTypes: [0, 0], - args: [taskId, newEvaluator], - }); - - taskEvaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(taskEvaluator.user).to.equal(newEvaluator); - }); - - it("should return the correct number of tasks", async () => { - const taskCountBefore = await colony.getTaskCount(); - - for (let i = 0; i < 5; i += 1) { - await makeTask({ colony }); - } - - const taskCountAfter = await colony.getTaskCount(); - expect(taskCountAfter).to.be.eq.BN(taskCountBefore.addn(5)); - }); - - it("should set the task domain correctly", async () => { - await colony.addDomain(1, UINT256_MAX, 1); - const taskId = await makeTask({ colonyNetwork, colony, domainId: 2 }); - const task = await colony.getTask(taskId); - expect(task.domainId).to.eq.BN(2); - }); - - it("should log TaskAdded and FundingPotAdded events", async () => { - await expectAllEvents(colony.makeTask(1, UINT256_MAX, SPECIFICATION_HASH, 1, GLOBAL_SKILL_ID, 0), ["TaskAdded", "FundingPotAdded"]); - }); - - it("should optionally set the skill and due date", async () => { - const skillId = GLOBAL_SKILL_ID; - const currTime = await currentBlockTime(); - const dueDate = currTime + SECONDS_PER_DAY * 10; - - const taskId = await makeTask({ colony, skillId, dueDate }); - const task = await colony.getTask(taskId); - expect(task.dueDate).to.eq.BN(dueDate); - expect(task.skillIds[0]).to.eq.BN(skillId); - }); - - it("should set the due date to 90 days from now if unspecified", async () => { - const skillId = GLOBAL_SKILL_ID; - const dueDate = 0; - const taskId = await makeTask({ colony, skillId, dueDate }); - const task = await colony.getTask(taskId); - const currTime = await currentBlockTime(); - const expectedDueDate = currTime + SECONDS_PER_DAY * 90; - expect(task.dueDate).to.eq.BN(expectedDueDate); - }); - }); - - describe("when updating tasks", () => { - it("should not be able to pass unallowed function signature to `executeTaskRoleAssignment`", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }), - "colony-task-change-is-not-role-assignment", - ); - }); - - it("should not be able to send any ether while assigning a role", async () => { - const taskId = await makeTask({ colony }); - - const sigTypes = [0, 0]; - const signers = [MANAGER, WORKER]; - const args = [taskId, WORKER]; - const { sigV, sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers, - sigTypes, - args, - }); - await checkErrorRevert(colony.executeTaskRoleAssignment(sigV, sigR, sigS, sigTypes, 10, txData), "colony-task-role-assignment-non-zero-value"); - }); - - it("should not be able to execute task change when the number of signature parts differ", async () => { - const taskId = await makeTask({ colony }); - const sigTypes = [0, 0]; - const signers = [MANAGER, WORKER]; - const args = [taskId, WORKER]; - const { sigV, sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers, - sigTypes, - args, - }); - - await checkErrorRevert( - colony.executeTaskRoleAssignment([sigV[0]], sigR, sigS, [0], 0, txData), - "colony-task-role-assignment-signatures-count-do-not-match", - ); - }); - - it("should allow the worker and evaluator roles to be assigned", async () => { - const newEvaluator = accounts[1]; - expect(MANAGER).to.not.equal(newEvaluator); - - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId], - }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER, newEvaluator], - sigTypes: [0, 0], - args: [taskId, newEvaluator], - }); - - const worker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(worker.user).to.equal(WORKER); - - const evaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(evaluator.user).to.equal(newEvaluator); - }); - - it("should not allow a worker to be assigned if the task has no skill", async () => { - const taskId = await makeTask({ colony, skillId: 0 }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }), - "colony-task-role-assignment-execution-failed", - ); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskSkill", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, GLOBAL_SKILL_ID], - }); - - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - }); - - it("should not allow the worker or evaluator roles to be assigned only by manager", async () => { - const newEvaluator = accounts[1]; - expect(MANAGER).to.not.equal(newEvaluator); - - const taskId = await makeTask({ colony }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId], - }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, newEvaluator], - }), - "colony-task-role-assignment-does-not-meet-required-signatures", - ); - - const evaluator = await colony.getTaskRole(taskId, EVALUATOR_ROLE); - expect(evaluator.user).to.equal(ethers.constants.AddressZero); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, WORKER], - }), - "colony-task-role-assignment-does-not-meet-required-signatures", - ); - - const worker = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(worker.user).to.equal(ethers.constants.AddressZero); - }); - - it("should not allow role to be assigned if it is already assigned to somebody", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, OTHER], - sigTypes: [0, 0], - args: [taskId, OTHER], - }), - "colony-task-role-assignment-execution-failed", - ); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER, OTHER], - sigTypes: [0, 0], - args: [taskId, OTHER], - }), - "colony-task-role-assignment-execution-failed", - ); - }); - - it("should allow role to be unassigned, as long as the current assigned address agrees", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - let workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(WORKER); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId], - }); - - workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(ethers.constants.AddressZero); - }); - - it("should not allow role to be unassigned, if current assigned address does not agree", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, OTHER], - sigTypes: [0, 0], - args: [taskId, ethers.constants.AddressZero], - }), - "colony-task-role-assignment-not-signed-by-new-user-for-role", - ); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(WORKER); - }); - - it("should not allow role to be assigned if passed address is not equal to one of the signers", async () => { - const newEvaluator = accounts[1]; - expect(MANAGER).to.not.equal(newEvaluator); - - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, newEvaluator], - }), - "colony-task-role-assignment-not-signed-by-new-user-for-role", - ); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(ethers.constants.AddressZero); - }); - - it("should allow manager to assign himself to a role", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, MANAGER], - }); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(MANAGER); - }); - - it("should not allow anyone to assign himself to a role with one signature except manager", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [WORKER], - sigTypes: [0], - args: [taskId, WORKER], - }), - "colony-task-role-assignment-does-not-meet-required-signatures", - ); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(ethers.constants.AddressZero); - }); - - it("should allow different modes of signing when assigning roles", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [WORKER, MANAGER], - sigTypes: [0, 1], - args: [taskId, WORKER], - }); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(WORKER); - }); - - it("should not allow role assignment if none of the signers is manager", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [WORKER, OTHER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }), - "colony-task-role-assignment-not-signed-by-manager", - ); - - const workerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(workerInfo.user).to.equal(ethers.constants.AddressZero); - }); - - it("should allow to change manager role if the user agrees", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [MANAGER, COLONY_ADMIN], - sigTypes: [0, 0], - args: [taskId, COLONY_ADMIN, 1, UINT256_MAX], - }); - - const managerInfo = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(managerInfo.user).to.equal(COLONY_ADMIN); - }); - - it("should not allow assignment of manager to other role with 1 signature if signer is not manager", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [COLONY_ADMIN], - sigTypes: [0], - args: [taskId, MANAGER], - }), - "colony-task-role-assignment-not-signed-by-manager", - ); - - const managerInfo = await colony.getTaskRole(taskId, WORKER_ROLE); - expect(managerInfo.user).to.equal(ethers.constants.AddressZero); - }); - - it("should not allow assignment of manager role if the user does not agree", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, COLONY_ADMIN, 1, UINT256_MAX], - }), - "colony-task-role-assignment-not-signed-by-new-user-for-role", - ); - - const managerInfo = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(managerInfo.user).to.equal(MANAGER); - }); - - it("should not allow assignment of manager role if user is not an admin", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [MANAGER, OTHER], - sigTypes: [0, 0], - args: [taskId, OTHER, 1, UINT256_MAX], - }), - "colony-task-role-assignment-execution-failed", - ); - - const managerInfo = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(managerInfo.user).to.equal(MANAGER); - }); - - it("should not allow removal of manager role", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [MANAGER, COLONY_ADMIN], - sigTypes: [0, 0], - args: [taskId, ethers.constants.AddressZero, 1, UINT256_MAX], - }), - "colony-task-role-assignment-not-signed-by-new-user-for-role", - ); - - const managerInfo = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(managerInfo.user).to.equal(MANAGER); - }); - - it("should not allow assignment of manager role if current manager is not one of the signers", async () => { - const newEvaluator = accounts[1]; - expect(MANAGER).to.not.equal(newEvaluator); - - const taskId = await makeTask({ colony }); - - // Setting the worker - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, COLONY_ADMIN], - sigTypes: [0, 0], - args: [taskId, COLONY_ADMIN], - }); - - // Setting the evaluator - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId], - }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER, newEvaluator], - sigTypes: [0, 0], - args: [taskId, newEvaluator], - }); - - await checkErrorRevert( - // Evaluator and worker trying to set a manager - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [newEvaluator, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER, 1, UINT256_MAX], - }), - "colony-task-role-assignment-not-signed-by-manager", - ); - - const managerInfo = await colony.getTaskRole(taskId, MANAGER_ROLE); - expect(managerInfo.user).to.equal(MANAGER); - }); - - it("should correctly increment `taskChangeNonce` for multiple updates on a single task", async () => { - const taskId = await makeTask({ colony }); - - // Change the task brief - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - - let taskChangeNonce = await colony.getTaskChangeNonce(taskId); - expect(taskChangeNonce).to.eq.BN(1); - - // Change the due date - const dueDate = await currentBlockTime(); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, dueDate], - }); - - taskChangeNonce = await colony.getTaskChangeNonce(taskId); - expect(taskChangeNonce).to.eq.BN(2); - }); - - it("should correctly increment `taskChangeNonce` for multiple updates on multiple tasks", async () => { - const taskId1 = await makeTask({ colony }); - const taskId2 = await makeTask({ colony }); - - // Change the task1 brief - await executeSignedTaskChange({ - colony, - taskId: taskId1, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId1, SPECIFICATION_HASH_UPDATED], - }); - let taskChangeNonce = await colony.getTaskChangeNonce(taskId1); - expect(taskChangeNonce).to.eq.BN(1); - - await executeSignedTaskChange({ - colony, - taskId: taskId2, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId2, SPECIFICATION_HASH_UPDATED], - }); - - taskChangeNonce = await colony.getTaskChangeNonce(taskId2); - expect(taskChangeNonce).to.eq.BN(1); - - // Change the task2 due date - const dueDate = await currentBlockTime(); - - await executeSignedTaskChange({ - colony, - taskId: taskId2, - functionName: "setTaskDueDate", - signers: [MANAGER], - sigTypes: [0], - args: [taskId2, dueDate], - }); - - taskChangeNonce = await colony.getTaskChangeNonce(taskId2); - expect(taskChangeNonce).to.eq.BN(2); - }); - - it("should allow update of task brief signed by manager only when worker has not been assigned", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.eq.BN(SPECIFICATION_HASH_UPDATED); - }); - - it("should allow update of task brief signed by manager and worker", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.eq.BN(SPECIFICATION_HASH_UPDATED); - }); - - it("should allow update of task brief signed by manager and worker using Trezor-style signatures", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER, WORKER], - sigTypes: [1, 1], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.eq.BN(SPECIFICATION_HASH_UPDATED); - }); - - it("should allow update of task brief signed by manager and worker if one uses Trezor-style signatures and the other does not", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER, WORKER], - sigTypes: [0, 1], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.eq.BN(SPECIFICATION_HASH_UPDATED); - }); - - it("should not allow update of task brief signed by manager twice, with two different signature styles", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER, MANAGER], - sigTypes: [0, 1], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-duplicate-reviewers", - ); - - const task = await colony.getTask(taskId); - expect(task.specificationHash).to.eq.BN(SPECIFICATION_HASH); - }); - - it("should allow update of task due date signed by manager and worker", async () => { - const dueDate = await currentBlockTime(); - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, dueDate], - }); - - const task = await colony.getTask(taskId); - expect(task.dueDate).to.eq.BN(dueDate); - }); - - it("should not allow update of task due if it is trying to be set to 0", async () => { - const dueDate = await currentBlockTime(); - const taskId = await makeTask({ colony, dueDate }); - - await checkErrorRevert( - executeSignedTaskChange({ colony, taskId, functionName: "setTaskDueDate", signers: [MANAGER], sigTypes: [0], args: [taskId, 0] }), - "colony-task-change-execution-failed", - ); - - const task = await colony.getTask(taskId); - expect(task.dueDate).to.eq.BN(dueDate); - }); - - it("should fail if a non-colony call is made to the task update functions", async () => { - await makeTask({ colony }); - await checkErrorRevert(colony.setTaskBrief(1, SPECIFICATION_HASH_UPDATED, { from: OTHER }), "colony-not-self"); - await checkErrorRevert(colony.setTaskManagerPayout(1, ADDRESS_ZERO, 0), "colony-not-self"); - await checkErrorRevert(colony.setTaskEvaluatorPayout(1, ADDRESS_ZERO, 0), "colony-not-self"); - await checkErrorRevert(colony.setTaskWorkerPayout(1, ADDRESS_ZERO, 0), "colony-not-self"); - await checkErrorRevert(colony.setTaskManagerRole(1, ADDRESS_ZERO, 0, 0), "colony-not-self"); - await checkErrorRevert(colony.setTaskEvaluatorRole(1, ADDRESS_ZERO), "colony-not-self"); - await checkErrorRevert(colony.setTaskWorkerRole(1, ADDRESS_ZERO), "colony-not-self"); - await checkErrorRevert(colony.removeTaskEvaluatorRole(1), "colony-not-self"); - await checkErrorRevert(colony.removeTaskWorkerRole(1), "colony-not-self"); - await checkErrorRevert(colony.setTaskDueDate(1, 0), "colony-not-self"); - await checkErrorRevert(colony.cancelTask(1), "colony-not-self"); - }); - - it("should fail update of task brief signed by a non-registered role", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER, OTHER], - sigTypes: [0, 0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-change-does-not-meet-signatures-required", - ); - }); - - it("should fail update of task brief signed by manager and evaluator", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-change-does-not-meet-signatures-required", - ); - }); - - it("should fail to execute task change for a non-registered function signature", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "getTaskRole", - signers: [MANAGER, EVALUATOR], - sigTypes: [0, 0], - args: [taskId, 0], - }), - "colony-task-change-does-not-meet-signatures-required", - ); - }); - - it("should fail to execute change of task brief, using an invalid task id", async () => { - const taskId = await makeTask({ colony }); - const taskCount = await colony.getTaskCount(); - const nonExistentTaskId = taskCount.addn(10); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [nonExistentTaskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-does-not-exist", - ); - }); - - it("should fail to execute change of task brief, using invalid task id 0", async () => { - const taskId = 0; - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-does-not-exist", - ); - }); - - it("should fail to execute task change, when trying to set skill to 0", async () => { - const taskId = await makeTask({ colony }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - functionName: "setTaskSkill", - taskId, - signers: [MANAGER], - sigTypes: [0], - args: [taskId, 0], - }), - "colony-task-change-execution-failed", - ); - }); - - it("should fail to execute task change, if the task is already finalized", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ colonyNetwork, colony, token }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }), - "colony-task-finalized", - ); - }); - - it("should fail to change task manager, if the task is complete", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const dueDate = await currentBlockTime(); - const taskId = await setupFundedTask({ colonyNetwork, colony, token, dueDate }); - - await forwardTime(SECONDS_PER_DAY); - await colony.completeTask(taskId); - - await checkErrorRevert( - executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskManagerRole", - signers: [MANAGER, COLONY_ADMIN], - sigTypes: [0, 0], - args: [taskId, COLONY_ADMIN, 1, UINT256_MAX], - }), - "colony-task-role-assignment-execution-failed", - ); - }); - - it("should log a TaskBriefSet event, if the task brief gets changed", async () => { - const taskId = await makeTask({ colony }); - - const tx = executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskBrief", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, SPECIFICATION_HASH_UPDATED], - }); - await expectEvent(tx, "TaskBriefSet", [taskId, SPECIFICATION_HASH_UPDATED]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER]]); - }); - - it("should log a TaskDueDateSet event, if the task due date gets changed", async () => { - const taskId = await makeTask({ colony }); - - const dueDate = await currentBlockTime(); - const tx = executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, dueDate], - }); - - await expectEvent(tx, "TaskDueDateSet", [taskId, dueDate]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER]]); - }); - - it("should log a TaskSkillSet event, if the task skill gets changed", async () => { - const taskId = await makeTask({ colony }); - await metaColony.addGlobalSkill(); - - const skillCount = await colonyNetwork.getSkillCount(); - - const tx = executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskSkill", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, skillCount], - }); - await expectEvent(tx, "TaskSkillSet", [taskId, skillCount]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER]]); - }); - - it("should log a TaskRoleUserSet event, if a task role's user gets changed", async () => { - const taskId = await makeTask({ colony }); - - // Change the task role's user - const tx = await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - // await expectEvent(tx, "TaskRoleUserSet", [taskId, WORKER_ROLE, WORKER]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER, WORKER]]); - }); - - it("should fail to execute task change with a non zero value", async () => { - const taskId = await makeTask({ colony }); - const { sigV, sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, 1], - }); - - await checkErrorRevert(colony.executeTaskChange(sigV, sigR, sigS, [0], 100, txData), "colony-task-change-non-zero-value"); - }); - - it("should fail to execute task change with a mismatched set of signature parts", async () => { - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - const { sigV, sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, 1], - }); - - await checkErrorRevert(colony.executeTaskChange([sigV[0]], sigR, sigS, [0], 0, txData), "colony-task-change-signatures-count-do-not-match"); - }); - - it("should fail to execute task change with a bad signature and only one of the relevant roles set", async () => { - const taskId = await makeTask({ colony }); - const { sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskDueDate", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, "1"], - }); - - // Make the signature bad - const sigV = [11]; - await checkErrorRevert(colony.executeTaskChange(sigV, sigR, sigS, [0], 0, txData), "colony-task-invalid-signature"); - }); - - it("should fail to execute task change send for a task role assignment call (which should be using executeTaskRoleAssignment)", async () => { - const taskId = await makeTask({ colony }); - const { sigV, sigR, sigS, txData } = await getSigsAndTransactionData({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, "0x29738B9BB168790211D84C99c4AEAd215c34D731"], - }); - - await checkErrorRevert(colony.executeTaskChange(sigV, sigR, sigS, [0], 0, txData), "colony-task-change-is-role-assignment"); - }); - }); - - describe("when submitting task deliverable", () => { - it("should update task", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 4; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - - let task = await colony.getTask(taskId); - expect(task.deliverableHash).to.equal(ethers.constants.HashZero); - - await colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }); - const currentTime = await currentBlockTime(); - task = await colony.getTask(taskId); - expect(task.deliverableHash).to.equal(DELIVERABLE_HASH); - expect(task.completionTimestamp).to.eq.BN(currentTime); - }); - - it("should fail if I try to submit work for a task that is complete", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, token, dueDate }); - await colony.completeTask(taskId); - await checkErrorRevert(colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH), "colony-task-complete"); - }); - - it("should fail if I try to submit work for a task that is finalized", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const dueDate = await currentBlockTime(); - const taskId = await setupFinalizedTask({ colonyNetwork, colony, dueDate, token }); - await checkErrorRevert(colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH), "colony-task-complete"); - }); - - it("should succeed if I try to submit work for a task that is past its due date but not yet marked as complete", async () => { - let dueDate = await currentBlockTime(); - dueDate -= 1; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }); - const task = await colony.getTask(taskId); - expect(task.deliverableHash).to.equal(DELIVERABLE_HASH); - }); - - it("should fail if I try to submit work for a task using an invalid id", async () => { - const taskCount = await colony.getTaskCount(); - const invalidTaskId = taskCount.addn(10); - await checkErrorRevert(colony.submitTaskDeliverable(invalidTaskId, DELIVERABLE_HASH), "colony-task-does-not-exist"); - }); - - it("should fail if I try to submit work twice", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 4; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - await colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }); - - await checkErrorRevert(colony.submitTaskDeliverable(taskId, SPECIFICATION_HASH, { from: WORKER }), "colony-task-complete"); - const task = await colony.getTask(taskId); - expect(task.deliverableHash).to.equal(DELIVERABLE_HASH); - }); - - it("should fail if I try to submit work if I'm not the assigned worker", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 4; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - - await checkErrorRevert(colony.submitTaskDeliverable(taskId, SPECIFICATION_HASH, { from: OTHER }), "colony-task-role-identity-mismatch"); - const task = await colony.getTask(taskId); - expect(task.deliverableHash).to.not.equal(DELIVERABLE_HASH); - }); - - it("should log a TaskDeliverableSubmitted event", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 4; - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate }); - - await expectEvent(colony.submitTaskDeliverable(taskId, DELIVERABLE_HASH, { from: WORKER }), "TaskDeliverableSubmitted", [ - WORKER, - taskId, - DELIVERABLE_HASH, - ]); - }); - }); - - describe("when finalizing a task", () => { - it('should set the task "status" property to "finalized"', async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ colonyNetwork, colony, token }); - const task = await colony.getTask(taskId); - expect(task.status).to.eq.BN(FINALIZED_TASK_STATE); - }); - - it("cannot complete a task that does not exist", async () => { - await checkErrorRevert(colony.completeTask(100), "colony-task-does-not-exist"); - }); - - it("should fail if the task work ratings have not been assigned and they still have time to be", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const dueDate = await currentBlockTime(); - const taskId = await setupAssignedTask({ colonyNetwork, colony, dueDate, token }); - await colony.completeTask(taskId); - await checkErrorRevert(colony.finalizeTask(taskId), "colony-task-ratings-incomplete"); - }); - - it("should fail if it's not sufficiently funded to support all its payouts", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await makeTask({ colonyNetwork, colony, token }); - await colony.setAllTaskPayouts(taskId, token.address, MANAGER_PAYOUT, EVALUATOR_PAYOUT, WORKER_PAYOUT, { from: MANAGER }); - await assignRoles({ colony, taskId, manager: MANAGER, evaluator: EVALUATOR, worker: WORKER }); - - await colony.submitTaskDeliverableAndRating(taskId, DELIVERABLE_HASH, RATING_1_SECRET, { from: WORKER }); - await colony.submitTaskWorkRating(taskId, WORKER_ROLE, RATING_2_SECRET, { from: EVALUATOR }); - await colony.revealTaskWorkRating(taskId, MANAGER_ROLE, MANAGER_RATING, RATING_1_SALT, { from: WORKER }); - await colony.revealTaskWorkRating(taskId, WORKER_ROLE, WORKER_RATING, RATING_2_SALT, { from: EVALUATOR }); - await checkErrorRevert(colony.finalizeTask(taskId), "colony-task-not-funded"); - }); - - it("should fail if I try to accept a task that was finalized before", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ colonyNetwork, colony, token }); - await checkErrorRevert(colony.finalizeTask(taskId), "colony-task-already-finalized"); - }); - - it("should fail if I try to accept a task using an invalid id", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskCount = await colony.getTaskCount(); - const nonExistentTaskId = taskCount.addn(10); - await checkErrorRevert(colony.finalizeTask(nonExistentTaskId), "colony-task-not-complete"); - }); - - it("should log a TaskFinalized event", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupRatedTask({ colonyNetwork, colony, token }); - await expectEvent(colony.finalizeTask(taskId), "TaskFinalized", [MANAGER, taskId]); - }); - }); - - describe("when cancelling a task", () => { - it('should set the task "status" property to "cancelled"', async () => { - const taskId = await makeTask({ colony }); - await executeSignedTaskChange({ - colony, - taskId, - functionName: "cancelTask", - signers: [MANAGER], - sigTypes: [0], - args: [taskId], - }); - - const task = await colony.getTask(taskId); - expect(task.status).to.eq.BN(CANCELLED_TASK_STATE); - }); - - it("cannot cancel a task that doesn't exist", async () => { - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId: 100, - functionName: "cancelTask", - signers: [MANAGER], - sigTypes: [0], - args: [100], - }), - "colony-task-does-not-exist", - ); - }); - - it("should be possible to return funds back to the domain", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFundedTask({ colonyNetwork, colony, token }); - const task = await colony.getTask(taskId); - const { domainId } = task; - const domain = await colony.getDomain(domainId); - const taskPotId = task.fundingPotId; - const domainPotId = domain.fundingPotId; - - // Our test-data-generator already set up some task fund with tokens, - // but we need some Ether, too - await colony.send(101); - await colony.claimColonyFunds(ethers.constants.AddressZero); - await colony.moveFundsBetweenPots(1, UINT256_MAX, 1, UINT256_MAX, UINT256_MAX, domainPotId, taskPotId, 100, ethers.constants.AddressZero); - - // And another token - await otherToken.mint(colony.address, 101); - await colony.claimColonyFunds(otherToken.address); - await colony.moveFundsBetweenPots(1, UINT256_MAX, 1, UINT256_MAX, UINT256_MAX, domainPotId, taskPotId, 100, otherToken.address); - - // Keep track of original Ether balance in funding pots - const originalDomainEtherBalance = await colony.getFundingPotBalance(domainPotId, ethers.constants.AddressZero); - const originalTaskEtherBalance = await colony.getFundingPotBalance(taskPotId, ethers.constants.AddressZero); - // And same for the token - const originalDomainTokenBalance = await colony.getFundingPotBalance(domainPotId, token.address); - const originalTaskTokenBalance = await colony.getFundingPotBalance(taskPotId, token.address); - // And the other token - const originalDomainOtherTokenBalance = await colony.getFundingPotBalance(domainPotId, otherToken.address); - const originalTaskOtherTokenBalance = await colony.getFundingPotBalance(taskPotId, otherToken.address); - - // Now that everything is set up, let's cancel the task, move funds and compare funding pots afterwards - await executeSignedTaskChange({ - colony, - taskId, - functionName: "cancelTask", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId], - }); - - await colony.moveFundsBetweenPots( - 1, - UINT256_MAX, - 1, - UINT256_MAX, - UINT256_MAX, - taskPotId, - domainPotId, - originalTaskEtherBalance, - ethers.constants.AddressZero, - ); - await colony.moveFundsBetweenPots(1, UINT256_MAX, 1, UINT256_MAX, UINT256_MAX, taskPotId, domainPotId, originalTaskTokenBalance, token.address); - await colony.moveFundsBetweenPots( - 1, - UINT256_MAX, - 1, - UINT256_MAX, - UINT256_MAX, - taskPotId, - domainPotId, - originalTaskOtherTokenBalance, - otherToken.address, - ); - - const cancelledTaskEtherBalance = await colony.getFundingPotBalance(taskPotId, ethers.constants.AddressZero); - const cancelledDomainEtherBalance = await colony.getFundingPotBalance(domainPotId, ethers.constants.AddressZero); - const cancelledTaskTokenBalance = await colony.getFundingPotBalance(taskPotId, token.address); - const cancelledDomainTokenBalance = await colony.getFundingPotBalance(domainPotId, token.address); - const cancelledTaskOtherTokenBalance = await colony.getFundingPotBalance(taskPotId, otherToken.address); - const cancelledDomainOtherTokenBalance = await colony.getFundingPotBalance(domainPotId, otherToken.address); - - expect(originalTaskEtherBalance).to.not.eq.BN(cancelledTaskEtherBalance); - expect(originalDomainEtherBalance).to.not.eq.BN(cancelledDomainEtherBalance); - expect(originalTaskTokenBalance).to.not.eq.BN(cancelledTaskTokenBalance); - expect(originalDomainTokenBalance).to.not.eq.BN(cancelledDomainTokenBalance); - expect(originalTaskOtherTokenBalance).to.not.eq.BN(cancelledTaskOtherTokenBalance); - expect(originalDomainOtherTokenBalance).to.not.eq.BN(cancelledDomainOtherTokenBalance); - - expect(cancelledTaskEtherBalance).to.be.zero; - expect(cancelledTaskTokenBalance).to.be.zero; - expect(cancelledTaskOtherTokenBalance).to.be.zero; - - expect(originalDomainEtherBalance.add(originalTaskEtherBalance)).to.eq.BN(cancelledDomainEtherBalance); - expect(originalDomainTokenBalance.add(originalTaskTokenBalance)).to.eq.BN(cancelledDomainTokenBalance); - expect(originalDomainOtherTokenBalance.add(originalTaskOtherTokenBalance)).to.eq.BN(cancelledDomainOtherTokenBalance); - }); - - it("should fail if manager tries to cancel a task that was completed", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFundedTask({ colonyNetwork, colony, token }); - await colony.submitTaskDeliverable(taskId, SPECIFICATION_HASH, { from: WORKER }); - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "cancelTask", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId], - }), - "colony-task-change-execution-failed", - ); - }); - - it("should fail if manager tries to cancel a task with invalid id", async () => { - const taskId = await makeTask({ colony }); - const taskCount = await colony.getTaskCount(); - const invalidTaskId = taskCount.addn(10); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "cancelTask", - signers: [MANAGER], - sigTypes: [0], - args: [invalidTaskId], - }), - "colony-task-does-not-exist", - ); - }); - - it("should log a TaskCanceled event", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFundedTask({ colonyNetwork, colony, token }); - const tx = executeSignedTaskChange({ - colony, - taskId, - functionName: "cancelTask", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId], - }); - - await expectEvent(tx, "TaskCanceled", [taskId]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER, WORKER]]); - }); - }); - - describe("when funding tasks", () => { - it("should be able to set the task payouts for different roles", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - - const taskId = await makeTask({ colony, dueDate }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - await colony.mintTokens(100); - - // Set the manager payout as 5000 wei and 100 colony tokens - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskManagerPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, ethers.constants.AddressZero, 5000], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskManagerPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, token.address, 100], - }); - - // Set the evaluator payout as 1000 ethers - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskEvaluatorPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, ethers.constants.AddressZero, 1000], - }); - - // Set the evaluator payout as 40 colony tokens - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskEvaluatorPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, token.address, 40], - }); - - // Set the worker payout as 98000 wei and 200 colony tokens - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskWorkerPayout", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, ethers.constants.AddressZero, 98000], - }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskWorkerPayout", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, token.address, 200], - }); - - const taskPayoutManager1 = await colony.getTaskPayout(taskId, MANAGER_ROLE, ethers.constants.AddressZero); - expect(taskPayoutManager1).to.eq.BN(5000); - const taskPayoutManager2 = await colony.getTaskPayout(taskId, MANAGER_ROLE, token.address); - expect(taskPayoutManager2).to.eq.BN(100); - - const taskPayoutEvaluator1 = await colony.getTaskPayout(taskId, EVALUATOR_ROLE, ethers.constants.AddressZero); - expect(taskPayoutEvaluator1).to.eq.BN(1000); - const taskPayoutEvaluator2 = await colony.getTaskPayout(taskId, EVALUATOR_ROLE, token.address); - expect(taskPayoutEvaluator2).to.eq.BN(40); - - const taskPayoutWorker1 = await colony.getTaskPayout(taskId, WORKER_ROLE, ethers.constants.AddressZero); - expect(taskPayoutWorker1).to.eq.BN(98000); - const taskPayoutWorker2 = await colony.getTaskPayout(taskId, WORKER_ROLE, token.address); - expect(taskPayoutWorker2).to.eq.BN(200); - }); - - it("should be able (if manager) to set all payments at once if evaluator and worker are manager or unassigned", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - - const taskId = await makeTask({ colony, dueDate }); - await checkErrorRevert( - colony.setAllTaskPayouts(taskId, ethers.constants.AddressZero, 5000, 1000, 98000, { from: OTHER }), - "colony-task-role-identity-mismatch", - ); - await colony.setAllTaskPayouts(taskId, ethers.constants.AddressZero, 5000, 1000, 98000); - - const taskPayoutManager = await colony.getTaskPayout(taskId, MANAGER_ROLE, ethers.constants.AddressZero); - expect(taskPayoutManager).to.eq.BN(5000); - - const taskPayoutEvaluator = await colony.getTaskPayout(taskId, EVALUATOR_ROLE, ethers.constants.AddressZero); - expect(taskPayoutEvaluator).to.eq.BN(1000); - - const taskPayoutWorker = await colony.getTaskPayout(taskId, WORKER_ROLE, ethers.constants.AddressZero); - expect(taskPayoutWorker).to.eq.BN(98000); - }); - - it("should not be able to set all payments at once if worker is assigned and not manager", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - - const taskId = await makeTask({ colony, dueDate }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - - await checkErrorRevert(colony.setAllTaskPayouts(taskId, ethers.constants.AddressZero, 5000, 1000, 98000), "colony-funding-worker-already-set"); - }); - - it("should not be able to set all payments at once if evaluator is assigned and not manager", async () => { - let dueDate = await currentBlockTime(); - dueDate += SECONDS_PER_DAY * 7; - - const taskId = await makeTask({ colony, dueDate, evaluator: accounts[6] }); - await executeSignedTaskChange({ - colony, - taskId, - functionName: "removeTaskEvaluatorRole", - signers: [MANAGER], - sigTypes: [0], - args: [taskId], - }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskEvaluatorRole", - signers: [MANAGER, accounts[4]], - sigTypes: [0, 0], - args: [taskId, accounts[4]], - }); - - await checkErrorRevert( - colony.setAllTaskPayouts(taskId, ethers.constants.AddressZero, 5000, 1000, 98000), - "colony-funding-evaluator-already-set", - ); - }); - - it("should log a TaskWorkerPayoutSet event, if the task's worker's payout changed", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedRoleAssignment({ - colony, - taskId, - functionName: "setTaskWorkerRole", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, WORKER], - }); - await colony.mintTokens(100); - - // Set the worker payout as 98000 wei - const tx = executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskWorkerPayout", - signers: [MANAGER, WORKER], - sigTypes: [0, 0], - args: [taskId, ethers.constants.AddressZero, 98000], - }); - await expectEvent(tx, "TaskPayoutSet", [taskId, WORKER_ROLE, ethers.constants.AddressZero, 98000]); - await expectEvent(tx, "TaskChangedViaSignatures", [[MANAGER, WORKER]]); - }); - - it("should correctly return the current total payout", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFundedTask({ colonyNetwork, colony, token }); - const { fundingPotId } = await colony.getTask(taskId); - - const totalTokenPayout = await colony.getFundingPotPayout(fundingPotId, token.address); - const totalTokenPayoutExpected = MANAGER_PAYOUT.add(EVALUATOR_PAYOUT).add(WORKER_PAYOUT); - expect(totalTokenPayout).to.eq.BN(totalTokenPayoutExpected); - }); - - it("should not be able to set a payout above the limit", async () => { - const taskId = await makeTask({ colony }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskManagerPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, ethers.constants.AddressZero, MAX_PAYOUT], - }); - - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskManagerPayout", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, ethers.constants.AddressZero, MAX_PAYOUT.addn(1)], - }), - "colony-task-change-execution-failed", // Should be "colony-payout-too-large" - ); - }); - - it("should not be able to set a payout on a task that doesn't exist", async () => { - await checkErrorRevert( - executeSignedTaskChange({ - colony, - taskId: 1000, - functionName: "setTaskManagerPayout", - signers: [MANAGER], - sigTypes: [0], - args: [1000, ethers.constants.AddressZero, MAX_PAYOUT.addn(1)], - }), - "colony-task-does-not-exist", - ); - }); - }); - - describe("when claiming payout for a task", () => { - it("should payout agreed tokens for a task", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ colonyNetwork, colony, token }); - const task = await colony.getTask(taskId); - const taskPotId = task.fundingPotId; - - const networkBalanceBefore = await token.balanceOf(colonyNetwork.address); - const managerBalanceBefore = await token.balanceOf(MANAGER); - const potBalanceBefore = await colony.getFundingPotBalance(taskPotId, token.address); - - await colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address); - - const networkBalanceAfter = await token.balanceOf(colonyNetwork.address); - expect(networkBalanceAfter.sub(networkBalanceBefore)).to.eq.BN(WAD.addn(1)); - - const managerBalanceAfter = await token.balanceOf(MANAGER); - expect(managerBalanceAfter.sub(managerBalanceBefore)).to.eq.BN(WAD.muln(99).subn(1)); - - const potBalanceAfter = await colony.getFundingPotBalance(taskPotId, token.address); - expect(potBalanceBefore.sub(potBalanceAfter)).to.eq.BN(WAD.muln(100)); - }); - - it("should payout agreed ether for a task", async () => { - await colony.send(400); - await colony.claimColonyFunds(ethers.constants.AddressZero); - - let dueDate = await currentBlockTime(); - dueDate -= 1; - const taskId = await setupFinalizedTask({ - colonyNetwork, - colony, - token: ethers.constants.AddressZero, - dueDate, - managerPayout: 100, - evaluatorPayout: 50, - workerPayout: 200, - }); - - const task = await colony.getTask(taskId); - const taskPotId = task.fundingPotId; - const potBalanceBefore = await colony.getFundingPotBalance(taskPotId, ethers.constants.AddressZero); - - const workerBalanceBefore = await web3GetBalance(WORKER); - const metaBalanceBefore = await web3GetBalance(metaColony.address); - - await colony.claimTaskPayout(taskId, WORKER_ROLE, ethers.constants.AddressZero); - - const workerBalanceAfter = await web3GetBalance(WORKER); - expect(new BN(workerBalanceAfter).sub(new BN(workerBalanceBefore))).to.eq.BN(new BN(197)); - - const metaBalanceAfter = await web3GetBalance(metaColony.address); - expect(new BN(metaBalanceAfter).sub(new BN(metaBalanceBefore))).to.eq.BN(3); - - const potBalanceAfter = await colony.getFundingPotBalance(taskPotId, ethers.constants.AddressZero); - expect(potBalanceBefore.sub(potBalanceAfter)).to.eq.BN(new BN(200)); - }); - - it("should disburse nothing for unsatisfactory work, for manager and worker", async () => { - const evaluator = accounts[1]; - const managerBalanceBefore = await token.balanceOf(MANAGER); - const evaluatorBalanceBefore = await token.balanceOf(evaluator); - const workerBalanceBefore = await token.balanceOf(WORKER); - - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ - colonyNetwork, - colony, - token, - evaluator, - managerRating: 1, - workerRating: 1, - }); - - await colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address); - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - await colony.claimTaskPayout(taskId, EVALUATOR_ROLE, token.address); - - const managerBalanceAfter = await token.balanceOf(MANAGER); - expect(managerBalanceAfter.sub(managerBalanceBefore)).to.be.zero; - - const workerBalanceAfter = await token.balanceOf(WORKER); - expect(workerBalanceAfter.sub(workerBalanceBefore)).to.be.zero; - - const evaluatorBalanceAfter = await token.balanceOf(evaluator); - const evaluatorPayout = EVALUATOR_PAYOUT.divn(100).muln(99).subn(1); // "Subtract" 1% fee - expect(evaluatorBalanceAfter.sub(evaluatorBalanceBefore)).to.eq.BN(evaluatorPayout); - }); - - it("should disburse nothing for unsatisfactory work, for evaluator", async () => { - const evaluator = accounts[1]; - const managerBalanceBefore = await token.balanceOf(MANAGER); - const evaluatorBalanceBefore = await token.balanceOf(evaluator); - const workerBalanceBefore = await token.balanceOf(WORKER); - - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const dueDate = await currentBlockTime(); - const taskId = await setupFundedTask({ colonyNetwork, colony, dueDate, token, evaluator }); - - await colony.completeTask(taskId); - - await forwardTime(SECONDS_PER_DAY * 10 + 1, this); - await colony.finalizeTask(taskId); - - await colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address); - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - await colony.claimTaskPayout(taskId, EVALUATOR_ROLE, token.address); - - const managerBalanceAfter = await token.balanceOf(MANAGER); - const managerPayout = MANAGER_PAYOUT.divn(100).muln(99).subn(1); // "Subtract" 1% fee - expect(managerBalanceAfter.sub(managerBalanceBefore)).to.eq.BN(managerPayout); - - const workerBalanceAfter = await token.balanceOf(WORKER); - const workerPayout = WORKER_PAYOUT.divn(100).muln(99).subn(1); // "Subtract" 1% fee - expect(workerBalanceAfter.sub(workerBalanceBefore)).to.eq.BN(workerPayout); - - const evaluatorBalanceAfter = await token.balanceOf(evaluator); - expect(evaluatorBalanceAfter.sub(evaluatorBalanceBefore)).to.be.zero; - }); - - it("should return error when task is not finalized", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupRatedTask({ colonyNetwork, colony, token }); - await checkErrorRevert(colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address), "colony-task-not-finalized"); - }); - - it("should payout correct rounded up network fees, for small task payouts", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ - colonyNetwork, - colony, - token, - managerPayout: 99, - workerPayout: 1, - evaluatorPayout: 2, - }); - - const networkBalance1 = await token.balanceOf(colonyNetwork.address); - const managerBalanceBefore = await token.balanceOf(MANAGER); - - await colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address); - const networkBalance2 = await token.balanceOf(colonyNetwork.address); - const managerBalanceAfter = await token.balanceOf(MANAGER); - expect(networkBalance2.sub(networkBalance1)).to.eq.BN(1); - expect(managerBalanceAfter.sub(managerBalanceBefore)).to.eq.BN(98); - - const workerBalanceBefore = await token.balanceOf(WORKER); - - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - const networkBalance3 = await token.balanceOf(colonyNetwork.address); - const workerBalanceAfter = await token.balanceOf(WORKER); - expect(networkBalance3.sub(networkBalance2)).to.eq.BN(1); - expect(workerBalanceAfter.sub(workerBalanceBefore)).to.be.zero; - }); - - it("should take the whole payout as fee, when network fee is 1 (=100%)", async () => { - await metaColony.setNetworkFeeInverse(1); - - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ - colonyNetwork, - colony, - token, - managerPayout: 99, - workerPayout: 1, - evaluatorPayout: 2, - }); - - const networkBalance1 = await token.balanceOf(colonyNetwork.address); - const managerBalanceBefore = await token.balanceOf(MANAGER); - - await colony.claimTaskPayout(taskId, MANAGER_ROLE, token.address); - const networkBalance2 = await token.balanceOf(colonyNetwork.address); - const managerBalanceAfter = await token.balanceOf(MANAGER); - expect(networkBalance2.sub(networkBalance1)).to.eq.BN(99); - expect(managerBalanceAfter.sub(managerBalanceBefore)).to.be.zero; - - const workerBalanceBefore = await token.balanceOf(WORKER); - - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - const networkBalance3 = await token.balanceOf(colonyNetwork.address); - const workerBalanceAfter = await token.balanceOf(WORKER); - expect(networkBalance3.sub(networkBalance2)).to.eq.BN(1); - expect(workerBalanceAfter.sub(workerBalanceBefore)).to.be.zero; - }); - - it("should payout 0 network fees, for 0 value payouts", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ - colonyNetwork, - colony, - token, - managerPayout: 100, - workerPayout: 0, - evaluatorPayout: 0, - }); - - const networkBalanceBefore = await token.balanceOf(colonyNetwork.address); - const workerBalanceBefore = await token.balanceOf(WORKER); - - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - - const networkBalanceAfter = await token.balanceOf(colonyNetwork.address); - const workerBalanceAfter = await token.balanceOf(WORKER); - expect(networkBalanceAfter.sub(networkBalanceBefore)).to.be.zero; - expect(workerBalanceAfter.sub(workerBalanceBefore)).to.be.zero; - }); - }); - - describe("when claiming payout for a task for an extension", () => { - let extensionAddress; - const TEST_EXTENSION = soliditySha3("TestExtension"); - const extensionVersion = 0; - - before(async () => { - // Install an extension - - const extensionImplementation = await TestExtension0.new(); - const resolver = await Resolver.new(); - await setupEtherRouter("testHelpers/testExtensions", "TestExtension0", { TestExtension0: extensionImplementation.address }, resolver); - - await metaColony.addExtensionToNetwork(TEST_EXTENSION, resolver.address); - - await colony.installExtension(TEST_EXTENSION, extensionVersion); - extensionAddress = await colonyNetwork.getExtensionInstallation(TEST_EXTENSION, colony.address); - }); - - it("if recipient is own extension, should not award reputation or pay network fee", async () => { - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupRatedTask({ colonyNetwork, colony, token }); - - // Enter recovery mode, and change the worker to the extension address. - // This is required because the extension can't sign the messages for tasks - await colony.enterRecoveryMode(); - - // Task mapping is storage slot 14 - const taskSlot = soliditySha3(taskId.toNumber(), 14); - - // Roles mapping in slot 8 of the struct - // Worker is index 2 - const workerSlot = soliditySha3(2, new BN(taskSlot.slice(2), 16).addn(8)); - - // We also have the 'failed to rate' and 'rating' in this slot, so we do some quick string manipulation - // to make sure we're only changing the address. - const oldValue = await web3GetStorageAt(colony.address, workerSlot); - const newValue = ethers.utils.hexZeroPad(oldValue.slice(0, oldValue.length - 40) + extensionAddress.slice(2), 32); - await colony.setStorageSlotRecovery(workerSlot, newValue); - await colony.approveExitRecovery(); - await colony.exitRecoveryMode(); - - const taskRole = await colony.getTaskRole(taskId, 2); - expect(taskRole.user).to.equal(extensionAddress); - - await colony.finalizeTask(taskId); - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - - const addr = await colonyNetwork.getReputationMiningCycle(false); - const repCycle = await IReputationMiningCycle.at(addr); - const numEntries = await repCycle.getReputationUpdateLogLength(); - - // No entry in the log should be for this address - for (let i = new BN(0); i.lt(numEntries); i = i.addn(1)) { - const skillEntry = await repCycle.getReputationUpdateLogEntry(i); - expect(skillEntry.user).to.not.equal(extensionAddress); - } - - // Balance should be whole payout - const balance = await token.balanceOf(extensionAddress); - expect(balance).to.eq.BN(WORKER_PAYOUT); - }); - - it("if recipient is an extension for another colony, should not award reputation but should pay fee", async () => { - const { colony: otherColony } = await setupRandomColony(colonyNetwork); - - await otherColony.installExtension(TEST_EXTENSION, extensionVersion); - const otherExtensionAddress = await colonyNetwork.getExtensionInstallation(TEST_EXTENSION, otherColony.address); - - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupRatedTask({ colonyNetwork, colony, token }); - - // Enter recovery mode, and change the worker to the extension address. - // This is required because the extension can't sign the messages for tasks - await colony.enterRecoveryMode(); - - // Task mapping is storage slot 14 - const taskSlot = soliditySha3(taskId.toNumber(), 14); - - // Roles mapping in slot 8 of the struct - // Worker is index 2 - const workerSlot = soliditySha3(2, new BN(taskSlot.slice(2), 16).addn(8)); - - const oldValue = await web3GetStorageAt(colony.address, workerSlot); - const newValue = ethers.utils.hexZeroPad(oldValue.slice(0, oldValue.length - 40) + otherExtensionAddress.slice(2), 32); - await colony.setStorageSlotRecovery(workerSlot, newValue); - - await colony.approveExitRecovery(); - await colony.exitRecoveryMode(); - - const taskRole = await colony.getTaskRole(taskId, 2); - expect(taskRole.user).to.equal(otherExtensionAddress); - - await colony.finalizeTask(taskId); - await colony.claimTaskPayout(taskId, WORKER_ROLE, token.address); - - const addr = await colonyNetwork.getReputationMiningCycle(false); - const repCycle = await IReputationMiningCycle.at(addr); - const numEntries = await repCycle.getReputationUpdateLogLength(); - - // No entry in the log should be for this address - for (let i = new BN(0); i.lt(numEntries); i = i.addn(1)) { - const skillEntry = await repCycle.getReputationUpdateLogEntry(numEntries.subn(1)); - expect(skillEntry.user).to.not.equal(otherExtensionAddress); - } - - // But the balance should have the fee deducted - const balance = await token.balanceOf(otherExtensionAddress); - expect(balance).to.be.lt.BN(WORKER_PAYOUT); - }); - }); - - describe("when setting domain and skill on task", () => { - beforeEach(async () => { - ({ colony, token } = await setupRandomColony(colonyNetwork)); - }); - - it("should be able to set domain on task", async () => { - await colony.addDomain(1, UINT256_MAX, 1); - - const { logs } = await colony.makeTask(1, 0, SPECIFICATION_HASH, 2, 0, 0); - const { taskId } = logs[0].args; - - const task = await colony.getTask(taskId); - expect(task.domainId).to.eq.BN(2); - }); - - it("should NOT be able to set a nonexistent domain on task", async () => { - await checkErrorRevert(colony.makeTask(1, 0, SPECIFICATION_HASH, 2, 0, 0), "ds-auth-child-domain-does-not-exist"); - }); - - it("should be able to set global skill on task", async () => { - await metaColony.addGlobalSkill(); - await metaColony.addGlobalSkill(); - const globalSkillId = await colonyNetwork.getSkillCount(); - - const taskId = await makeTask({ colony }); - - await executeSignedTaskChange({ - colony, - taskId, - functionName: "setTaskSkill", - signers: [MANAGER], - sigTypes: [0], - args: [taskId, globalSkillId], - }); - - const task = await colony.getTask(taskId); - expect(task.skillIds[0]).to.eq.BN(globalSkillId); - }); - - it("should not allow anyone but the colony to set global skill on task", async () => { - await metaColony.addGlobalSkill(); - const globalSkillId = await colonyNetwork.getSkillCount(); - - const taskId = await makeTask({ colony, skillId: 0 }); - await checkErrorRevert(colony.setTaskSkill(taskId, globalSkillId, { from: MANAGER }), "colony-not-self"); - - const task = await colony.getTask(taskId); - expect(task.skillIds[0]).to.be.zero; - }); - - it("should NOT be able to set global skill on nonexistent task", async () => { - await checkErrorRevert(colony.setTaskSkill(10, 1), "colony-task-does-not-exist"); - }); - - it("should NOT be able to set global skill on completed task", async () => { - await metaColony.addGlobalSkill(); - await metaColony.addGlobalSkill(); - const globalSkillId = await colonyNetwork.getSkillCount(); - - await fundColonyWithTokens(colony, token, INITIAL_FUNDING); - const taskId = await setupFinalizedTask({ colonyNetwork, colony }); - await checkErrorRevert(colony.setTaskSkill(taskId, globalSkillId), "colony-task-complete"); - - const task = await colony.getTask(taskId); - expect(task.skillIds[0]).to.eq.BN(GLOBAL_SKILL_ID); - }); - - it("should NOT be able to set nonexistent skill on task", async () => { - const taskId = await makeTask({ colony }); - await checkErrorRevert(colony.setTaskSkill(taskId, 100), "colony-not-valid-local-skill"); - }); - - it("should NOT be able to set a domain skill on task", async () => { - const taskId = await makeTask({ colony }); - await checkErrorRevert(colony.setTaskSkill(taskId, 1), "colony-not-valid-local-skill"); - }); - - it("should NOT be able to set a deprecated global skill on task", async () => { - const taskId = await makeTask({ colony }); - await metaColony.addGlobalSkill(); - const skillId = await colonyNetwork.getSkillCount(); - await metaColony.deprecateGlobalSkill(skillId); - - await checkErrorRevert(colony.setTaskSkill(taskId, skillId), "colony-not-valid-local-skill"); - }); - }); -}); From 16aeb4fbed68118ca8ee2d2fda8899df8fab382d Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jun 2024 09:55:35 -0400 Subject: [PATCH 6/9] Consolidate test files --- .circleci/config.yml | 8 +- package.json | 16 +- test-smoke/colony-storage-consistent.js | 155 ------------------ .../misc/chainid.js | 8 +- {test-system => test/misc}/end-to-end.js | 12 +- .../gasCosts.js => test/misc/gas-costs.js | 16 +- .../upgrade}/colony-network-upgrade.js | 2 +- .../upgrade}/colony-upgrade.js | 6 +- .../reputation-mining-cycle-upgrade.js | 4 +- 9 files changed, 36 insertions(+), 191 deletions(-) delete mode 100644 test-smoke/colony-storage-consistent.js rename test-chainid/chainid-dependent-behaviour.js => test/misc/chainid.js (97%) rename {test-system => test/misc}/end-to-end.js (97%) rename test-gas-costs/gasCosts.js => test/misc/gas-costs.js (97%) rename {test-upgrade => test/upgrade}/colony-network-upgrade.js (95%) rename {test-upgrade => test/upgrade}/colony-upgrade.js (95%) rename {test-upgrade => test/upgrade}/reputation-mining-cycle-upgrade.js (93%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8306065c82..96ca02836d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -204,7 +204,7 @@ jobs: sed -i "s/000000000000000000000000000000deadbeef18/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json - run: name: "Running gas cost tests" - command: pnpm run test:contracts:gasCosts && npx codechecks + command: pnpm run test:contracts:gas && npx codechecks - run: name: "Running ganache upgrade tests" command: pnpm run test:contracts:upgrade:ganache @@ -241,7 +241,7 @@ jobs: root: ./ paths: - coverage-contracts - coverage-test-upgrade: + coverage-test/upgrade: <<: *job_common steps: - checkout @@ -506,7 +506,7 @@ workflows: context: dockerhub-credentials - coverage-test-chainid: context: dockerhub-credentials - - coverage-test-upgrade: + - coverage-test/upgrade: context: dockerhub-credentials - coverage-test-bridging: context: dockerhub-credentials @@ -517,5 +517,5 @@ workflows: - coverage-test-extensions - coverage-test-reputation - coverage-test-chainid - - coverage-test-upgrade + - coverage-test/upgrade - coverage-test-bridging diff --git a/package.json b/package.json index 38b5f8756a..97b2b94eaf 100644 --- a/package.json +++ b/package.json @@ -40,20 +40,20 @@ "pretest:contracts:extensions": "pnpm run stop:blockchain:client", "test:contracts": "pnpm run start:blockchain:client && npx hardhat test ./test/contracts-network/* ./test/packages/* --network development", "test:contracts:extensions": "pnpm run start:blockchain:client && npx hardhat test ./test/extensions/* --network development", - "test:contracts:upgrade:parity": "pnpm run clean:test:contracts | pnpm run start:blockchain:client parity & pnpm run generate:test:contracts && npx hardhat test ./test-upgrade/* --network integration", - "test:contracts:upgrade:ganache": "pnpm run clean:test:contracts | pnpm run start:blockchain:client ganache & pnpm run generate:test:contracts && npx hardhat test ./test-upgrade/* --network development", - "test:contracts:gasCosts": "pnpm run start:blockchain:client && npx hardhat test test-gas-costs/gasCosts.js --network development", + "test:contracts:upgrade:parity": "pnpm run clean:test:contracts | pnpm run start:blockchain:client parity & pnpm run generate:test:contracts && npx hardhat test ./test/upgrade/* --network integration", + "test:contracts:upgrade:ganache": "pnpm run clean:test:contracts | pnpm run start:blockchain:client ganache & pnpm run generate:test:contracts && npx hardhat test ./test/upgrade/* --network development", + "test:contracts:gas": "pnpm run start:blockchain:client && npx hardhat test test/misc/gas-costs.js --network development", "test:contracts:patricia": "pnpm run start:blockchain:client ganache && npx hardhat test packages/reputation-miner/patricia-test.js --network integration", "test:contracts:bridging:1": "CHAIN_ID_1=265669100 CHAIN_ID_2=265669101 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat test ./test/cross-chain/* --network development", "test:contracts:bridging:2": "CHAIN_ID_1=265669101 CHAIN_ID_2=265669100 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat test ./test/cross-chain/* --network development", - "test:contracts:chainid": "pnpm run start:blockchain:client && npx hardhat test ./test-chainid/*", - "test:contracts:e2e": "pnpm run start:blockchain:client && npx hardhat test test-system/end-to-end.js --network development", + "test:contracts:chainid": "pnpm run start:blockchain:client && npx hardhat test ./test/misc/chainid.js", + "test:contracts:e2e": "pnpm run start:blockchain:client && npx hardhat test test/misc/end-to-end.js --network development", "test:contracts:coverage": "npx hardhat coverage --temp build-coverage --testfiles './test/contracts-network/*'", "test:contracts:extensions:coverage": "npx hardhat compile && NODE_OPTIONS='--max-old-space-size=6144' npx hardhat coverage --solcoverjs ./.solcover.extensions.js --temp build-coverage --testfiles './test/extensions/*'", "test:contracts:bridging:1:coverage": "CHAIN_ID=265669101 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat --show-stack-traces coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", "test:contracts:bridging:2:coverage": "CHAIN_ID=265669100 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", - "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover.chainid.js --temp build-coverage --testfiles './test-chainid/**/*'", - "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover.upgrade.js --temp build-coverage --testfiles './test-upgrade/*'", + "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover.chainid.js --temp build-coverage --testfiles './test/misc/chainid.js'", + "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover.upgrade.js --temp build-coverage --testfiles './test/upgrade/*'", "test:reputation:1": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/*.js --network development", "test:reputation:2": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", "test:reputation:1:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/*.js --network development", @@ -64,7 +64,7 @@ "posttest:contracts:extensions": "pnpm run stop:blockchain:client", "posttest:contracts:upgrade:parity": "pnpm run clean:test:contracts | pnpm run stop:blockchain:client", "posttest:contracts:upgrade:ganache": "pnpm run clean:test:contracts | pnpm run stop:blockchain:client", - "posttest:contracts:gasCosts": "pnpm run stop:blockchain:client", + "posttest:contracts:gas": "pnpm run stop:blockchain:client", "posttest:contracts:patricia": "pnpm run stop:blockchain:client", "viz:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/viz-bootstrap.js", "kyc:bootstrap": "pnpm run start:blockchain:client && HARDHAT_NETWORK=development npx hardhat run scripts/kyc-bootstrap.js" diff --git a/test-smoke/colony-storage-consistent.js b/test-smoke/colony-storage-consistent.js deleted file mode 100644 index ea737c5241..0000000000 --- a/test-smoke/colony-storage-consistent.js +++ /dev/null @@ -1,155 +0,0 @@ -/* global artifacts */ -const chai = require("chai"); -const bnChai = require("bn-chai"); -const BN = require("bn.js"); -const { ethers } = require("ethers"); - -const { UINT256_MAX, WAD } = require("../helpers/constants"); -const { fundColonyWithTokens, setupColony } = require("../helpers/test-data-generator"); -const { setStorageSlot } = require("../helpers/test-helper"); - -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 Token = artifacts.require("Token"); - -const TokenAuthority = artifacts.require("contracts/common/TokenAuthority.sol:TokenAuthority"); - -contract("Contract Storage", (accounts) => { - const SLOT0 = 0; - - const RECIPIENT = accounts[3]; - const ADMIN = accounts[4]; - const ARBITRATOR = accounts[5]; - - let colony; - let token; - let localSkillId; - let otherToken; - let colonyNetwork; - let metaColony; - let domain1; - let tokenLockingAddress; - - before(async () => { - // We use our own providers for these test(s) so we can really get in to it... - - const cnAddress = (await EtherRouter.deployed()).address; - const etherRouter = await EtherRouter.at(cnAddress); - colonyNetwork = await IColonyNetwork.at(etherRouter.address); - const metaColonyAddress = await colonyNetwork.getMetaColony(); - metaColony = await IMetaColony.at(metaColonyAddress); - - token = await Token.new("name", "symbol", 18); - await token.unlock(); - - colony = await setupColony(colonyNetwork, token.address); - - await colony.addLocalSkill(); - localSkillId = await colonyNetwork.getSkillCount(); - - tokenLockingAddress = await colonyNetwork.getTokenLocking(); - const tokenAuthority = await TokenAuthority.new(token.address, colony.address, [tokenLockingAddress]); - await token.setAuthority(tokenAuthority.address); - - await colony.setRewardInverse(100); - await colony.setAdministrationRole(1, UINT256_MAX, ADMIN, 1, true); - await colony.setArbitrationRole(1, UINT256_MAX, ARBITRATOR, 1, true); - await fundColonyWithTokens(colony, token, UINT256_MAX); - domain1 = await colony.getDomain(1); - - otherToken = await Token.new("otherName", "otherSymbol", 18); - await otherToken.unlock(); - await fundColonyWithTokens(colony, otherToken, UINT256_MAX); - }); - - function getAddressStateHash(address) { - return new Promise((resolve, reject) => { - web3.currentProvider - .request({ method: "eth_getProof", params: [address, [], "latest"] }) - .then((result) => { - return resolve(result.storageHash); - }) - .catch((e) => { - reject(e); - }); - }); - } - - describe("Smoke tests to check our storage layout does not change", () => { - // There are many things you could do that one would expect to change these hashes. If you've made changes that change the contents of storage of a - // contract, then these hashes will change. This could include adding an extra transaction somewhere, which could cause the address a contract is - // deployed to change, which if it is stored somewhere would cause the state hash of the storage to change. - - // If you haven't touched the contracts, however, and this test fails, then something is afoot. - // In theory, the storage slots used by solidity could change in an upgrade, - // which this test was written with in mind to try and detect. They don't guarantee this hasn't happened if they pass, but if they fail without just - // cause then we need to think very carefully about what's going on. - - it("storage contents should be as expected", async () => { - await colony.makeExpenditure(1, UINT256_MAX, 1, { from: ADMIN }); - const expenditureId = await colony.getExpenditureCount(); - - await colony.setExpenditureRecipient(expenditureId, SLOT0, RECIPIENT, { from: ADMIN }); - await colony.setExpenditurePayout(expenditureId, SLOT0, token.address, WAD, { from: ADMIN }); - await colony.setExpenditureSkills(expenditureId, [SLOT0], [localSkillId], { from: ADMIN }); - - const expenditure = await colony.getExpenditure(expenditureId); - await colony.moveFundsBetweenPots(1, UINT256_MAX, UINT256_MAX, domain1.fundingPotId, expenditure.fundingPotId, WAD, token.address); - await colony.finalizeExpenditure(expenditureId, { from: ADMIN }); - await colony.claimExpenditurePayout(expenditureId, SLOT0, token.address); - - const miningCycleAddress = await colonyNetwork.getReputationMiningCycle(false); - const miningCycleStateHash = await getAddressStateHash(miningCycleAddress); - - // For this test to be reproducible, have to zero timestamps / time depenedent things - // For colonyNetwork, that means the mining staking timestamp - - // Following - // https://solidity.readthedocs.io/en/v0.6.8/internals/layout_in_storage.html#mappings-and-dynamic-arrays - // This is the hash of the key (the address) and the storage slot containing the mapping (33) - let hashable = `0x000000000000000000000000${accounts[5].slice(2)}${new BN(33).toString(16, 64)}`; - let hashed = web3.utils.soliditySha3(hashable); - let slot = new BN(hashed.slice(2), 16); - - // To get the slot containing the timestamp of the miner submission, we add one to where the struct starts - // (see ColonyNetworkDataTypes) - slot = slot.addn(1); - await setStorageSlot(colonyNetwork, slot, ethers.constants.HashZero); - - // Also zero out the slot containing the current colony version - await setStorageSlot(colonyNetwork, 7, ethers.constants.HashZero); - - const colonyNetworkStateHash = await getAddressStateHash(colonyNetwork.address); - - // We did a whole expenditure above, so let's take out the finalized timestamp - // This is the hash of the expenditure id (1) with the storage slot (25) to find the location of the struct - hashable = `0x${new BN(1).toString(16, 64)}${new BN(25).toString(16, 64)}`; - hashed = web3.utils.soliditySha3(hashable); - slot = new BN(hashed.slice(2), 16); - // To find the slot storing the timestamp, we add three to where the struct starts (see ColonyDataTypes). - slot = slot.addn(3); - - await setStorageSlot(colony, slot, ethers.constants.HashZero); - - const colonyStateHash = await getAddressStateHash(colony.address); - const metaColonyStateHash = await getAddressStateHash(metaColony.address); - const tokenLockingStateHash = await getAddressStateHash(tokenLockingAddress); - - console.log("colonyNetworkStateHash:", colonyNetworkStateHash); - console.log("colonyStateHash:", colonyStateHash); - console.log("metaColonyStateHash:", metaColonyStateHash); - console.log("miningCycleStateHash:", miningCycleStateHash); - console.log("tokenLockingStateHash:", tokenLockingStateHash); - - expect(colonyNetworkStateHash).to.equal("0x66b279547b6eab5c688ac6b6a6bd7dedc0849a9e9d2218e5a1dcf0eeac8847f8"); - expect(colonyStateHash).to.equal("0x156061470e5ed4c0f091adb726dbb819692d23bc8338bd06a660a9a4cc48eea6"); - expect(metaColonyStateHash).to.equal("0x4c2b0dba6abe7feee2c052e3a5f07ccb71adb5d0bd5c32d21b16559b313ecf82"); - expect(miningCycleStateHash).to.equal("0x179caec9074f4db8b06afcb6dad20c8091b31d7b483bd1c6cb469d79d1bc3649"); - expect(tokenLockingStateHash).to.equal("0xd128da36044b6c399c522f379a78591a572394423814b8aeb511cf2a3a07701f"); - }); - }); -}); diff --git a/test-chainid/chainid-dependent-behaviour.js b/test/misc/chainid.js similarity index 97% rename from test-chainid/chainid-dependent-behaviour.js rename to test/misc/chainid.js index aac1b53085..d539e707ee 100644 --- a/test-chainid/chainid-dependent-behaviour.js +++ b/test/misc/chainid.js @@ -4,14 +4,14 @@ const bnChai = require("bn-chai"); const BN = require("bn.js"); const ethers = require("ethers"); -const { setupENSRegistrar } = require("../helpers/upgradable-contracts"); +const { setupENSRegistrar } = require("../../helpers/upgradable-contracts"); const { setupColonyNetwork, setupMetaColonyWithLockedCLNYToken, giveUserCLNYTokens, giveUserCLNYTokensAndStake, unlockCLNYToken, -} = require("../helpers/test-data-generator"); +} = require("../../helpers/test-data-generator"); const { forwardTime, getActiveRepCycle, @@ -23,8 +23,8 @@ const { isMainnet, isXdai, getChainId, -} = require("../helpers/test-helper"); -const { MINING_CYCLE_DURATION, MIN_STAKE, CHALLENGE_RESPONSE_WINDOW_DURATION, WAD, DEFAULT_STAKE, XDAI_CHAINID } = require("../helpers/constants"); +} = require("../../helpers/test-helper"); +const { MINING_CYCLE_DURATION, MIN_STAKE, CHALLENGE_RESPONSE_WINDOW_DURATION, WAD, DEFAULT_STAKE, XDAI_CHAINID } = require("../../helpers/constants"); const { expect } = chai; const ENSRegistry = artifacts.require("ENSRegistry"); diff --git a/test-system/end-to-end.js b/test/misc/end-to-end.js similarity index 97% rename from test-system/end-to-end.js rename to test/misc/end-to-end.js index e73da0188d..70843aaf9b 100644 --- a/test-system/end-to-end.js +++ b/test/misc/end-to-end.js @@ -6,7 +6,7 @@ const chai = require("chai"); const bnChai = require("bn-chai"); const ethers = require("ethers"); -const { TruffleLoader } = require("../packages/package-utils"); +const { TruffleLoader } = require("../../packages/package-utils"); const { submitAndForwardTimeToDispute, getActiveRepCycle, @@ -16,7 +16,7 @@ const { makeReputationValue, removeSubdomainLimit, getChainId, -} = require("../helpers/test-helper"); +} = require("../../helpers/test-helper"); const { giveUserCLNYTokensAndStake, @@ -25,12 +25,12 @@ const { setupColonyNetwork, setupMetaColonyWithLockedCLNYToken, setupClaimedExpenditure, -} = require("../helpers/test-data-generator"); +} = require("../../helpers/test-data-generator"); -const { DEFAULT_STAKE, INITIAL_FUNDING } = require("../helpers/constants"); +const { DEFAULT_STAKE, INITIAL_FUNDING } = require("../../helpers/constants"); -const ReputationMinerTestWrapper = require("../packages/reputation-miner/test/ReputationMinerTestWrapper"); -const MaliciousReputationMinerExtraRep = require("../packages/reputation-miner/test/MaliciousReputationMinerExtraRep"); +const ReputationMinerTestWrapper = require("../../packages/reputation-miner/test/ReputationMinerTestWrapper"); +const MaliciousReputationMinerExtraRep = require("../../packages/reputation-miner/test/MaliciousReputationMinerExtraRep"); const { expect } = chai; chai.use(bnChai(web3.utils.BN)); diff --git a/test-gas-costs/gasCosts.js b/test/misc/gas-costs.js similarity index 97% rename from test-gas-costs/gasCosts.js rename to test/misc/gas-costs.js index 9f7bb3f519..f6d90d31ff 100644 --- a/test-gas-costs/gasCosts.js +++ b/test/misc/gas-costs.js @@ -14,7 +14,7 @@ const { INITIAL_FUNDING, MINING_CYCLE_DURATION, CHALLENGE_RESPONSE_WINDOW_DURATION, -} = require("../helpers/constants"); +} = require("../../helpers/constants"); const { getTokenArgs, @@ -27,14 +27,14 @@ const { advanceMiningCycleNoContest, submitAndForwardTimeToDispute, accommodateChallengeAndInvalidateHash, -} = require("../helpers/test-helper"); +} = require("../../helpers/test-helper"); -const { giveUserCLNYTokensAndStake, fundColonyWithTokens, setupRandomColony } = require("../helpers/test-data-generator"); +const { giveUserCLNYTokensAndStake, fundColonyWithTokens, setupRandomColony } = require("../../helpers/test-data-generator"); -const { TruffleLoader } = require("../packages/package-utils"); -const PatriciaTree = require("../packages/reputation-miner/patricia"); -const ReputationMinerTestWrapper = require("../packages/reputation-miner/test/ReputationMinerTestWrapper"); -const MaliciousReputationMinerExtraRep = require("../packages/reputation-miner/test/MaliciousReputationMinerExtraRep"); +const { TruffleLoader } = require("../../packages/package-utils"); +const PatriciaTree = require("../../packages/reputation-miner/patricia"); +const ReputationMinerTestWrapper = require("../../packages/reputation-miner/test/ReputationMinerTestWrapper"); +const MaliciousReputationMinerExtraRep = require("../../packages/reputation-miner/test/MaliciousReputationMinerExtraRep"); const Token = artifacts.require("Token"); const IColony = artifacts.require("IColony"); @@ -50,7 +50,7 @@ const IVotingReputation = artifacts.require("IVotingReputation"); const REAL_PROVIDER_PORT = 8545; const contractLoader = new TruffleLoader({ - contractRoot: path.resolve(__dirname, "..", "artifacts", "contracts"), + contractRoot: path.resolve(__dirname, "..", "..", "artifacts", "contracts"), }); contract("All", function (accounts) { diff --git a/test-upgrade/colony-network-upgrade.js b/test/upgrade/colony-network-upgrade.js similarity index 95% rename from test-upgrade/colony-network-upgrade.js rename to test/upgrade/colony-network-upgrade.js index e375e075aa..864c0bf24c 100644 --- a/test-upgrade/colony-network-upgrade.js +++ b/test/upgrade/colony-network-upgrade.js @@ -1,5 +1,5 @@ /* globals artifacts */ -const { setupRandomColony } = require("../helpers/test-data-generator"); +const { setupRandomColony } = require("../../helpers/test-data-generator"); const IColonyNetwork = artifacts.require("IColonyNetwork"); const EtherRouter = artifacts.require("EtherRouter"); diff --git a/test-upgrade/colony-upgrade.js b/test/upgrade/colony-upgrade.js similarity index 95% rename from test-upgrade/colony-upgrade.js rename to test/upgrade/colony-upgrade.js index 1fa33d5fdf..a26201f66f 100644 --- a/test-upgrade/colony-upgrade.js +++ b/test/upgrade/colony-upgrade.js @@ -1,9 +1,9 @@ /* globals artifacts */ const { ethers } = require("ethers"); -const { setupColonyVersionResolver } = require("../helpers/upgradable-contracts"); -const { ROOT_ROLE } = require("../helpers/constants"); -const { makeExpenditure, setupRandomColony } = require("../helpers/test-data-generator"); +const { setupColonyVersionResolver } = require("../../helpers/upgradable-contracts"); +const { ROOT_ROLE } = require("../../helpers/constants"); +const { makeExpenditure, setupRandomColony } = require("../../helpers/test-data-generator"); const IColonyNetwork = artifacts.require("IColonyNetwork"); const IMetaColony = artifacts.require("IMetaColony"); diff --git a/test-upgrade/reputation-mining-cycle-upgrade.js b/test/upgrade/reputation-mining-cycle-upgrade.js similarity index 93% rename from test-upgrade/reputation-mining-cycle-upgrade.js rename to test/upgrade/reputation-mining-cycle-upgrade.js index f85df2d4d2..af4649c4d3 100644 --- a/test-upgrade/reputation-mining-cycle-upgrade.js +++ b/test/upgrade/reputation-mining-cycle-upgrade.js @@ -1,6 +1,6 @@ /* globals artifacts */ -const { setupReputationMiningCycleResolver } = require("../helpers/upgradable-contracts"); -const { advanceMiningCycleNoContest } = require("../helpers/test-helper"); +const { setupReputationMiningCycleResolver } = require("../../helpers/upgradable-contracts"); +const { advanceMiningCycleNoContest } = require("../../helpers/test-helper"); const IColonyNetwork = artifacts.require("IColonyNetwork"); const EtherRouter = artifacts.require("EtherRouter"); From 1c948314bc448529bbfc85f12fccbe6fce5a300e Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jun 2024 11:48:13 -0400 Subject: [PATCH 7/9] Consolidate .solcover config files --- .solcover.extensions.js | 5 ----- .solcover.reputation.js | 5 ----- .solcover.chainid.js => .solcover/chainid.js | 4 ++-- .solcover.crosschain.js => .solcover/crosschain.js | 5 ++--- .solcover/extensions.js | 5 +++++ .solcover/reputation.js | 5 +++++ .solcover.js => .solcover/solcover.js | 2 +- .solcover.upgrade.js => .solcover/upgrade.js | 5 +++-- package.json | 14 +++++++------- 9 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 .solcover.extensions.js delete mode 100644 .solcover.reputation.js rename .solcover.chainid.js => .solcover/chainid.js (81%) rename .solcover.crosschain.js => .solcover/crosschain.js (84%) create mode 100644 .solcover/extensions.js create mode 100644 .solcover/reputation.js rename .solcover.js => .solcover/solcover.js (98%) rename .solcover.upgrade.js => .solcover/upgrade.js (87%) diff --git a/.solcover.extensions.js b/.solcover.extensions.js deleted file mode 100644 index 35f997a4ff..0000000000 --- a/.solcover.extensions.js +++ /dev/null @@ -1,5 +0,0 @@ -const config = require("./.solcover.js") - -config.istanbulFolder = "./coverage-extensions" - -module.exports = config \ No newline at end of file diff --git a/.solcover.reputation.js b/.solcover.reputation.js deleted file mode 100644 index 158f59bcd5..0000000000 --- a/.solcover.reputation.js +++ /dev/null @@ -1,5 +0,0 @@ -const config = require("./.solcover.js") - -config.istanbulFolder = "./coverage-reputation" - -module.exports = config \ No newline at end of file diff --git a/.solcover.chainid.js b/.solcover/chainid.js similarity index 81% rename from .solcover.chainid.js rename to .solcover/chainid.js index 9faaa4e163..415cbfef9b 100644 --- a/.solcover.chainid.js +++ b/.solcover/chainid.js @@ -1,7 +1,7 @@ -const config = require("./.solcover.js") +const config = require("./solcover.js") config.providerOptions.network_id = parseInt(process.env.CHAIN_ID, 10); config.providerOptions._chainId = parseInt(process.env.CHAIN_ID, 10); config.providerOptions._chainIdRpc = parseInt(process.env.CHAIN_ID, 10); config.istanbulFolder = `./coverage-chainid-${process.env.CHAIN_ID}` -module.exports = config \ No newline at end of file +module.exports = config diff --git a/.solcover.crosschain.js b/.solcover/crosschain.js similarity index 84% rename from .solcover.crosschain.js rename to .solcover/crosschain.js index 0fbeca72ee..64d60fd407 100644 --- a/.solcover.crosschain.js +++ b/.solcover/crosschain.js @@ -1,7 +1,6 @@ -const config = require("./.solcover.js") -const ethers = require("ethers"); +const config = require("./solcover.js") -const { FORKED_XDAI_CHAINID } = require("./helpers/constants"); +const { FORKED_XDAI_CHAINID } = require("./../helpers/constants"); config.istanbulFolder = `./coverage-cross-chain-${process.env.HARDHAT_FOREIGN === "true" ? "foreign" : "home"}` console.log(`Coverage folder: ${config.istanbulFolder}`) diff --git a/.solcover/extensions.js b/.solcover/extensions.js new file mode 100644 index 0000000000..3023341960 --- /dev/null +++ b/.solcover/extensions.js @@ -0,0 +1,5 @@ +const config = require("./solcover.js") + +config.istanbulFolder = "./coverage-extensions" + +module.exports = config diff --git a/.solcover/reputation.js b/.solcover/reputation.js new file mode 100644 index 0000000000..cb6e10fc74 --- /dev/null +++ b/.solcover/reputation.js @@ -0,0 +1,5 @@ +const config = require("./solcover.js") + +config.istanbulFolder = "./coverage-reputation" + +module.exports = config diff --git a/.solcover.js b/.solcover/solcover.js similarity index 98% rename from .solcover.js rename to .solcover/solcover.js index 112603ae7c..ced5468603 100644 --- a/.solcover.js +++ b/.solcover/solcover.js @@ -13,7 +13,7 @@ module.exports = { }, providerOptions: { network_id: 1999, - account_keys_path: "./ganache-accounts.json", + account_keys_path: "./../ganache-accounts.json", vmErrorsOnRPCResponse: false, total_accounts: 18, _chainId: 265669100, diff --git a/.solcover.upgrade.js b/.solcover/upgrade.js similarity index 87% rename from .solcover.upgrade.js rename to .solcover/upgrade.js index a13d501321..64ddb8a39d 100644 --- a/.solcover.upgrade.js +++ b/.solcover/upgrade.js @@ -1,5 +1,6 @@ +const config = require("./solcover.js") + const { execSync } = require("child_process"); -const config = require("./.solcover.js") function getFilesToSkip(){ const array = [ @@ -16,4 +17,4 @@ function getFilesToSkip(){ config.istanbulFolder = "./coverage-upgrade" config.skipFiles = getFilesToSkip(); -module.exports = config \ No newline at end of file +module.exports = config diff --git a/package.json b/package.json index 97b2b94eaf..35274c34ac 100644 --- a/package.json +++ b/package.json @@ -48,17 +48,17 @@ "test:contracts:bridging:2": "CHAIN_ID_1=265669101 CHAIN_ID_2=265669100 pnpm run start:blockchain:client:both && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat test ./test/cross-chain/* --network development", "test:contracts:chainid": "pnpm run start:blockchain:client && npx hardhat test ./test/misc/chainid.js", "test:contracts:e2e": "pnpm run start:blockchain:client && npx hardhat test test/misc/end-to-end.js --network development", - "test:contracts:coverage": "npx hardhat coverage --temp build-coverage --testfiles './test/contracts-network/*'", - "test:contracts:extensions:coverage": "npx hardhat compile && NODE_OPTIONS='--max-old-space-size=6144' npx hardhat coverage --solcoverjs ./.solcover.extensions.js --temp build-coverage --testfiles './test/extensions/*'", - "test:contracts:bridging:1:coverage": "CHAIN_ID=265669101 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat --show-stack-traces coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", - "test:contracts:bridging:2:coverage": "CHAIN_ID=265669100 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat coverage --solcoverjs ./.solcover.crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", - "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover.chainid.js --temp build-coverage --testfiles './test/misc/chainid.js'", - "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover.upgrade.js --temp build-coverage --testfiles './test/upgrade/*'", + "test:contracts:coverage": "npx hardhat coverage --solcoverjs ./.solcover/solcover.js --temp build-coverage --testfiles './test/contracts-network/*'", + "test:contracts:extensions:coverage": "npx hardhat compile && NODE_OPTIONS='--max-old-space-size=6144' npx hardhat coverage --solcoverjs ./.solcover/extensions.js --temp build-coverage --testfiles './test/extensions/*'", + "test:contracts:bridging:1:coverage": "CHAIN_ID=265669101 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=false MINING_CHAIN_ID=265669100 npx hardhat --show-stack-traces coverage --solcoverjs ./.solcover/crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", + "test:contracts:bridging:2:coverage": "CHAIN_ID=265669100 pnpm run start:blockchain:client:2 && HARDHAT_FOREIGN=true MINING_CHAIN_ID=265669100 CHAIN_ID=265669101 npx hardhat coverage --solcoverjs ./.solcover/crosschain.js --temp build-coverage --testfiles './test/cross-chain/**/*'", + "test:contracts:chainid:coverage": "npx hardhat coverage --solcoverjs ./.solcover/chainid.js --temp build-coverage --testfiles './test/misc/chainid.js'", + "test:contracts:upgrade:coverage": "pnpm run generate:test:contracts && npx hardhat coverage --solcoverjs ./.solcover/upgrade.js --temp build-coverage --testfiles './test/upgrade/*'", "test:reputation:1": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/*.js --network development", "test:reputation:2": "pnpm run start:blockchain:client && npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", "test:reputation:1:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/*.js --network development", "test:reputation:2:anotherChain": "CHAIN_ID=101010101 pnpm run start:blockchain:client && MINING_CHAIN_ID=101010101 CHAIN_ID=101010101 npx hardhat test ./test/reputation-system/reputation-mining-client/* --network development", - "test:reputation:coverage": "npx hardhat coverage --solcoverjs ./.solcover.reputation.js --temp build-coverage --testfiles './test/reputation-system/**/*'", + "test:reputation:coverage": "npx hardhat coverage --solcoverjs ./.solcover/reputation.js --temp build-coverage --testfiles './test/reputation-system/**/*'", "test:security:slither": "slither . --solc-disable-warnings --exclude-low --exclude-informational --exclude-optimization --filter-paths 'lib|contracts/testHelpers|@openzeppelin'", "posttest:contracts": "pnpm run stop:blockchain:client", "posttest:contracts:extensions": "pnpm run stop:blockchain:client", From e61c9f6ec32b9aeb91f8a5810beaeef3d26a4f95 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jun 2024 13:09:21 -0400 Subject: [PATCH 8/9] Tweak .circleci/config.yml --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 96ca02836d..5f5fc21986 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -241,7 +241,7 @@ jobs: root: ./ paths: - coverage-contracts - coverage-test/upgrade: + coverage-test-upgrade: <<: *job_common steps: - checkout @@ -506,7 +506,7 @@ workflows: context: dockerhub-credentials - coverage-test-chainid: context: dockerhub-credentials - - coverage-test/upgrade: + - coverage-test-upgrade: context: dockerhub-credentials - coverage-test-bridging: context: dockerhub-credentials @@ -517,5 +517,5 @@ workflows: - coverage-test-extensions - coverage-test-reputation - coverage-test-chainid - - coverage-test/upgrade + - coverage-test-upgrade - coverage-test-bridging From e559f951273ec528f7a52864dcf5519ed2c1ee78 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Wed, 26 Jun 2024 09:58:03 +0100 Subject: [PATCH 9/9] Delete obselete commands --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 35274c34ac..f20ae44d1f 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,6 @@ "start:blockchain:client:both": "CHAIN_ID=$CHAIN_ID_1 pnpm run start:blockchain:client & sleep 1 && CHAIN_ID=$CHAIN_ID_2 pnpm run start:blockchain:client:2", "start:reputation:oracle": "./scripts/start-reputation-oracle.js", "stop:blockchain:client": "bash ./scripts/stop-blockchain-client.sh", - "fork:goerli": "ganache --fork https://goerli.infura.io/v3/e21146aa267845a2b7b4da025178196d --port 8605", - "fork:mainnet": "ganache --fork https://mainnet.infura.io/v3/e21146aa267845a2b7b4da025178196d --port 8601", "pretest:contracts": "pnpm run stop:blockchain:client", "pretest:contracts:extensions": "pnpm run stop:blockchain:client", "test:contracts": "pnpm run start:blockchain:client && npx hardhat test ./test/contracts-network/* ./test/packages/* --network development",