Improve custom error helper when there is no match (#4437)

pull/4436/head
Francisco 2 years ago committed by GitHub
parent e47b53bce4
commit 4bac6fa310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      test/helpers/customError.js

@ -13,13 +13,10 @@ async function expectRevertCustomError(promise, expectedErrorName, args) {
// VM Exception while processing transaction:
// reverted with custom error 'InvalidAccountNonce("0x70997970C51812dc3A010C7d01b50e0d17dc79C8", 0)'
// We trim out anything inside the single quotes as comma-separated values
const [, error] = message.match(/'(.*)'/);
// Attempt to parse as an error
const match = error.match(/(?<name>\w+)\((?<args>.*)\)/);
// Attempt to parse as a custom error
const match = message.match(/custom error '(?<name>\w+)\((?<args>.*)\)'/);
if (!match) {
expect.fail(`Couldn't parse "${error}" as a custom error`);
expect.fail(`Could not parse as custom error. ${message}`);
}
// Extract the error name and parameters
const errorName = match.groups.name;

Loading…
Cancel
Save