diff --git a/helpers/test-helper.js b/helpers/test-helper.js index e8da629d79..8553b16e67 100644 --- a/helpers/test-helper.js +++ b/helpers/test-helper.js @@ -621,7 +621,7 @@ export async function advanceMiningCycleNoContest({ colonyNetwork, client, miner if (client !== undefined) { await client.addLogContentsToReputationTree(); await client.submitRootHash(); - await client.confirmEntry(); + await client.confirmNewHash(); } else { const accounts = await web3GetAccounts(); minerAddress = minerAddress || accounts[5]; // eslint-disable-line no-param-reassign diff --git a/packages/reputation-miner/ReputationMiner.js b/packages/reputation-miner/ReputationMiner.js index 22ffca0331..f7fac9d851 100644 --- a/packages/reputation-miner/ReputationMiner.js +++ b/packages/reputation-miner/ReputationMiner.js @@ -1070,6 +1070,24 @@ class ReputationMiner { ); } + /** + * Confirm the new reputation hash after all dispute resolution (if any) has occurred. + * @return {Promise} Resolves to tx hash of the response + */ + async confirmNewHash() { + const repCycle = await this.getActiveRepCycle(); + const [round] = await this.getMySubmissionRoundAndIndex(); + + let gasEstimate = ethers.BigNumber.from(4000000); + try { + gasEstimate = await repCycle.estimateGas.confirmNewHash(round); + } catch (err){ // eslint-disable-line no-empty + + } + return repCycle.confirmNewHash(round, { gasLimit: gasEstimate, gasPrice: this.gasPrice }); + } + + async updatePeriodLength(repCycle) { const { numerator, denominator } = await repCycle.getDecayConstant(); diff --git a/packages/reputation-miner/ReputationMinerClient.js b/packages/reputation-miner/ReputationMinerClient.js index d77de49130..9ef7713184 100644 --- a/packages/reputation-miner/ReputationMinerClient.js +++ b/packages/reputation-miner/ReputationMinerClient.js @@ -612,16 +612,11 @@ class ReputationMinerClient { } async confirmEntry() { - const addr = await this._miner.colonyNetwork.getReputationMiningCycle(true); - const repCycle = new ethers.Contract(addr, this._miner.repCycleContractDef.abi, this._miner.realWallet); - this._adapter.log("⏰ Looks like it's time to confirm the new hash"); - // Confirm hash + // Confirm hash if possible const [round] = await this._miner.getMySubmissionRoundAndIndex(); if (round && round.gte(0)) { - const gasEstimate = await repCycle.estimateGas.confirmNewHash(round); - - const confirmNewHashTx = await repCycle.confirmNewHash(round, { gasLimit: gasEstimate, gasPrice: this._miner.gasPrice }); + const confirmNewHashTx = await this._miner.confirmNewHash(); this._adapter.log(`⛏️ Transaction waiting to be mined ${confirmNewHashTx.hash}`); await confirmNewHashTx.wait(); this._adapter.log("✅ New reputation hash confirmed"); diff --git a/packages/reputation-miner/test/ReputationMinerTestWrapper.js b/packages/reputation-miner/test/ReputationMinerTestWrapper.js index 1959a7196a..d9c4292c36 100644 --- a/packages/reputation-miner/test/ReputationMinerTestWrapper.js +++ b/packages/reputation-miner/test/ReputationMinerTestWrapper.js @@ -25,6 +25,11 @@ class ReputationMinerTestWrapper extends ReputationMiner { const tx = await super.respondToChallenge(); return tx.wait(); } + + async confirmNewHash() { + const tx = await super.confirmNewHash(); + return tx.wait(); + } } export default ReputationMinerTestWrapper; diff --git a/test/contracts-network/reputation-basic-functionality.js b/test/contracts-network/reputation-basic-functionality.js index de053461d9..c0df314d4e 100644 --- a/test/contracts-network/reputation-basic-functionality.js +++ b/test/contracts-network/reputation-basic-functionality.js @@ -126,7 +126,22 @@ contract("Reputation mining - basic functionality", (accounts) => { const repCycle = await getActiveRepCycle(colonyNetwork); await forwardTime(MINING_CYCLE_DURATION, this); - await checkErrorRevert(repCycle.submitRootHash("0x12345678", 10, "0x00", 0), "colony-reputation-mining-zero-entry-index-passed"); + await checkErrorRevert(repCycle.submitRootHash("0x12345678", 10, "0x00", 0), "colony-reputation-mining-no-stake-or-delegator"); + + const nUniqueSubmittedHashes = await repCycle.getNUniqueSubmittedHashes(); + expect(nUniqueSubmittedHashes).to.be.zero; + }); + + it("should not allow someone to submit a new reputation hash with an entry index of 0, even if they're mining", async () => { + await giveUserCLNYTokensAndStake(colonyNetwork, MINER2, 9000); + + const repCycle = await getActiveRepCycle(colonyNetwork); + await forwardTime(MINING_CYCLE_DURATION, this); + + await checkErrorRevert( + repCycle.submitRootHash("0x12345678", 10, "0x00", 0, { from: MINER2 }), + "colony-reputation-mining-zero-entry-index-passed" + ); const nUniqueSubmittedHashes = await repCycle.getNUniqueSubmittedHashes(); expect(nUniqueSubmittedHashes).to.be.zero;