From 5179de150046ec5d441163fa2065c6f18ad66845 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Wed, 24 Nov 2021 18:44:15 -0500 Subject: [PATCH] fix: don't return an error from miner_start if aleady started --- src/chains/ethereum/ethereum/src/api.ts | 11 ++++++++--- .../ethereum/ethereum/tests/api/miner/miner.test.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/chains/ethereum/ethereum/src/api.ts b/src/chains/ethereum/ethereum/src/api.ts index 59b91880aa..58ae4cda06 100644 --- a/src/chains/ethereum/ethereum/src/api.ts +++ b/src/chains/ethereum/ethereum/src/api.ts @@ -592,9 +592,14 @@ export default class EthereumApi implements Api { @assertArgLength(0, 1) async miner_start(threads: number = 1) { if (this.#options.miner.legacyInstamine === true) { - const { transactions } = await this.#blockchain.resume(threads); - if (transactions != null && this.#options.chain.vmErrorsOnRPCResponse) { - assertExceptionalTransactions(transactions); + const resumption = await this.#blockchain.resume(threads); + // resumption can be undefined if the blockchain isn't currently paused + if ( + resumption && + resumption.transactions != null && + this.#options.chain.vmErrorsOnRPCResponse + ) { + assertExceptionalTransactions(resumption.transactions); } } else { this.#blockchain.resume(threads); diff --git a/src/chains/ethereum/ethereum/tests/api/miner/miner.test.ts b/src/chains/ethereum/ethereum/tests/api/miner/miner.test.ts index f72caf104d..2f274ff128 100644 --- a/src/chains/ethereum/ethereum/tests/api/miner/miner.test.ts +++ b/src/chains/ethereum/ethereum/tests/api/miner/miner.test.ts @@ -67,6 +67,14 @@ describe("api", () => { const provider = await getProvider({ miner: { blockTime: 1 } }); await testStopStartMining(provider); }).timeout(4000); + + it("should not throw an error when miner was already started when calling miner_start", async () => { + const provider = await getProvider({ + miner: { blockTime: 1, legacyInstamine: true } + }); + await assert.doesNotReject(provider.send("miner_start")); + await assert.doesNotReject(provider.send("miner_start")); + }).timeout(4000); }); describe("miner_setEtherbase", () => {