This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle
eth_gasEstimate
reverts correctly to prevent potential …
…process crash (#4056) Co-authored-by: Jeff Smale <6363749+jeffsmale90@users.noreply.github.com>
- Loading branch information
1 parent
788c656
commit e71c184
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/chains/ethereum/ethereum/tests/api/eth/estimateGas.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import assert from "assert"; | ||
import getProvider from "../../helpers/getProvider"; | ||
|
||
describe("api", () => { | ||
describe("eth", () => { | ||
describe("estimateGas", () => { | ||
it("shouldn't raise an unhandled rejection when the transaction fails", async () => { | ||
// see https://github.com/trufflesuite/ganache/pull/4056 | ||
const provider = await getProvider(); | ||
const [from] = await provider.request({ | ||
method: "eth_accounts", | ||
params: [] | ||
}); | ||
|
||
const transaction = { | ||
from, | ||
// invalid bytecode | ||
input: "0x1234" | ||
}; | ||
|
||
let didRaiseUnhandledRejection = false; | ||
const unhandledRejectionHandler = () => | ||
(didRaiseUnhandledRejection = true); | ||
process.once("unhandledRejection", unhandledRejectionHandler); | ||
|
||
try { | ||
const estimatingGas = provider.request({ | ||
method: "eth_estimateGas", | ||
params: [transaction] | ||
}); | ||
|
||
await assert.rejects(estimatingGas); | ||
await new Promise(resolve => setImmediate(resolve)); | ||
|
||
assert( | ||
didRaiseUnhandledRejection === false, | ||
"Shouldn't have raised an unhandledRejection" | ||
); | ||
} finally { | ||
process.off("unhandledRejection", unhandledRejectionHandler); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |