From 9602243ca93cb015baa81c00f06d95d612b73b9f Mon Sep 17 00:00:00 2001 From: Przemyslaw Rzad Date: Mon, 31 Oct 2022 15:28:36 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94=20Handle=20bignumber=20in=20revert?= =?UTF-8?q?edWith.withArgs()=20(#786)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/polite-fans-arrive.md | 6 + pnpm-lock.yaml | 170 +++++++++++++++-------- waffle-chai/package.json | 10 +- waffle-chai/src/matchers/revertedWith.ts | 12 +- waffle-hardhat/contracts/CustomError.sol | 4 + waffle-hardhat/test/reverted.test.ts | 33 ++++- 6 files changed, 168 insertions(+), 67 deletions(-) create mode 100644 .changeset/polite-fans-arrive.md diff --git a/.changeset/polite-fans-arrive.md b/.changeset/polite-fans-arrive.md new file mode 100644 index 000000000..1a0542548 --- /dev/null +++ b/.changeset/polite-fans-arrive.md @@ -0,0 +1,6 @@ +--- +"@ethereum-waffle/chai": patch +"@ethereum-waffle/hardhat": patch +--- + +👔 revertedWith().withArgs no longer fails for uint values exceeding JavaScript's max int limit diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2eb418c9e..1a17ca9b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,12 +36,12 @@ importers: '@types/rimraf': 3.0.0 '@types/sinon': 9.0.10 '@types/sinon-chai': 3.2.5 - '@typescript-eslint/eslint-plugin': 5.15.0_5xebumbela46o2i2wjf3q6khoq - '@typescript-eslint/parser': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/eslint-plugin': 5.15.0_3idpik77dtp2p37mwvxiru2mra + '@typescript-eslint/parser': 5.15.0 chai: 4.2.0 chai-as-promised: 7.1.1_chai@4.2.0 chai-string: 1.5.0_chai@4.2.0 - eslint-plugin-import: 2.22.1_x76hk6kpvj4wcg2rfkjxf5ikka + eslint-plugin-import: 2.22.1_3idpik77dtp2p37mwvxiru2mra eslint-plugin-no-only-tests: 2.6.0 sinon: 9.2.4 sinon-chai: 3.5.0_chai@4.2.0+sinon@9.2.4 @@ -216,17 +216,21 @@ importers: specifiers: '@ethereum-waffle/provider': workspace:* '@types/debug': ^4.1.7 + '@types/json-bigint': ^1.0.1 debug: ^4.3.4 eslint: ^7.14.0 ethers: 5.6.2 + json-bigint: ^1.0.0 mocha: ^8.2.1 rimraf: ^3.0.2 typescript: ^4.6.2 dependencies: '@ethereum-waffle/provider': link:../waffle-provider debug: 4.3.4 + json-bigint: 1.0.0 devDependencies: '@types/debug': 4.1.7 + '@types/json-bigint': 1.0.1 eslint: 7.18.0 ethers: 5.6.2 mocha: 8.2.1 @@ -289,7 +293,7 @@ importers: dependencies: '@resolver-engine/imports': 0.3.3 '@resolver-engine/imports-fs': 0.3.3 - '@typechain/ethers-v5': 10.0.0_6dxoac5aapbom64r54k4um366m + '@typechain/ethers-v5': 10.0.0_75qa7wxcw3bgzsbibxcrrwvlx4 '@types/mkdirp': 0.5.2 '@types/node-fetch': 2.6.1 mkdirp: 0.5.5 @@ -328,8 +332,8 @@ importers: ethers: 5.6.2 mocha: 8.2.1 solc: 0.8.15 - ts-node: 9.1.1_typescript@4.6.2 - typechain: 8.0.0_typescript@4.6.2 + ts-node: 9.1.1 + typechain: 8.0.0 waffle-ens: specifiers: @@ -1450,7 +1454,7 @@ packages: dev: false optional: true - /@typechain/ethers-v5/10.0.0_6dxoac5aapbom64r54k4um366m: + /@typechain/ethers-v5/10.0.0_75qa7wxcw3bgzsbibxcrrwvlx4: resolution: {integrity: sha512-Kot7fwAqnH96ZbI8xrRgj5Kpv9yCEdjo7mxRqrH7bYpEgijT5MmuOo8IVsdhOu7Uog4ONg7k/d5UdbAtTKUgsA==} peerDependencies: '@ethersproject/abi': ^5.0.0 @@ -1460,9 +1464,6 @@ packages: typechain: ^8.0.0 typescript: '>=4.3.0' dependencies: - '@ethersproject/abi': 5.6.1 - '@ethersproject/bytes': 5.6.1 - '@ethersproject/providers': 5.6.2 ethers: 5.6.2 lodash: 4.17.21 ts-essentials: 7.0.3_typescript@4.6.2 @@ -1524,6 +1525,10 @@ packages: ci-info: 3.3.0 dev: false + /@types/json-bigint/1.0.1: + resolution: {integrity: sha512-zpchZLNsNuzJHi6v64UBoFWAvQlPhch7XAi36FkH6tL1bbbmimIF+cS7vwkzY4u5RaSWMoflQfu+TshMPPw8uw==} + dev: true + /@types/json-schema/7.0.10: resolution: {integrity: sha512-BLO9bBq59vW3fxCpD4o0N4U+DXsvwvIcl+jofw0frQo/GrBFC+/jRZj1E7kgp6dvTyNmA4y6JCV5Id/r3mNP5A==} dev: true @@ -1651,7 +1656,7 @@ packages: '@types/underscore': 1.11.4 dev: true - /@typescript-eslint/eslint-plugin/5.15.0_5xebumbela46o2i2wjf3q6khoq: + /@typescript-eslint/eslint-plugin/5.15.0_3idpik77dtp2p37mwvxiru2mra: resolution: {integrity: sha512-u6Db5JfF0Esn3tiAKELvoU5TpXVSkOpZ78cEGn/wXtT2RVqs2vkt4ge6N8cRCyw7YVKhmmLDbwI2pg92mlv7cA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1662,23 +1667,21 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/parser': 5.15.0 '@typescript-eslint/scope-manager': 5.15.0 - '@typescript-eslint/type-utils': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm - '@typescript-eslint/utils': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/type-utils': 5.15.0 + '@typescript-eslint/utils': 5.15.0 debug: 4.3.4 - eslint: 7.18.0 functional-red-black-tree: 1.0.1 ignore: 5.1.8 regexpp: 3.2.0 semver: 7.3.5 - tsutils: 3.21.0_typescript@4.6.2 - typescript: 4.6.2 + tsutils: 3.21.0 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser/5.15.0_c6rgizndxqcplp6oy5ayxlzjgm: + /@typescript-eslint/parser/5.15.0: resolution: {integrity: sha512-NGAYP/+RDM2sVfmKiKOCgJYPstAO40vPAgACoWPO/+yoYKSgAXIFaBKsV8P0Cc7fwKgvj27SjRNX4L7f4/jCKQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1690,10 +1693,8 @@ packages: dependencies: '@typescript-eslint/scope-manager': 5.15.0 '@typescript-eslint/types': 5.15.0 - '@typescript-eslint/typescript-estree': 5.15.0_typescript@4.6.2 + '@typescript-eslint/typescript-estree': 5.15.0 debug: 4.3.4 - eslint: 7.18.0 - typescript: 4.6.2 transitivePeerDependencies: - supports-color dev: true @@ -1706,7 +1707,7 @@ packages: '@typescript-eslint/visitor-keys': 5.15.0 dev: true - /@typescript-eslint/type-utils/5.15.0_c6rgizndxqcplp6oy5ayxlzjgm: + /@typescript-eslint/type-utils/5.15.0: resolution: {integrity: sha512-KGeDoEQ7gHieLydujGEFLyLofipe9PIzfvA/41urz4hv+xVxPEbmMQonKSynZ0Ks2xDhJQ4VYjB3DnRiywvKDA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1716,11 +1717,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/utils': 5.15.0 debug: 4.3.4 - eslint: 7.18.0 - tsutils: 3.21.0_typescript@4.6.2 - typescript: 4.6.2 + tsutils: 3.21.0 transitivePeerDependencies: - supports-color dev: true @@ -1730,7 +1729,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.15.0_typescript@4.6.2: + /@typescript-eslint/typescript-estree/5.15.0: resolution: {integrity: sha512-Hb0e3dGc35b75xLzixM3cSbG1sSbrTBQDfIScqdyvrfJZVEi4XWAT+UL/HMxEdrJNB8Yk28SKxPLtAhfCbBInA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1745,13 +1744,12 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.3.5 - tsutils: 3.21.0_typescript@4.6.2 - typescript: 4.6.2 + tsutils: 3.21.0 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils/5.15.0_c6rgizndxqcplp6oy5ayxlzjgm: + /@typescript-eslint/utils/5.15.0: resolution: {integrity: sha512-081rWu2IPKOgTOhHUk/QfxuFog8m4wxW43sXNOMSCdh578tGJ1PAaWPsj42LOa7pguh173tNlMigsbrHvh/mtA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1760,10 +1758,9 @@ packages: '@types/json-schema': 7.0.10 '@typescript-eslint/scope-manager': 5.15.0 '@typescript-eslint/types': 5.15.0 - '@typescript-eslint/typescript-estree': 5.15.0_typescript@4.6.2 - eslint: 7.18.0 + '@typescript-eslint/typescript-estree': 5.15.0 eslint-scope: 5.1.1 - eslint-utils: 3.0.0_eslint@7.18.0 + eslint-utils: 3.0.0 transitivePeerDependencies: - supports-color - typescript @@ -2048,6 +2045,10 @@ packages: is-windows: 1.0.2 dev: false + /bignumber.js/9.1.0: + resolution: {integrity: sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A==} + dev: false + /binary-extensions/2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} @@ -2168,6 +2169,13 @@ packages: node-gyp-build: 4.4.0 optional: true + /busboy/1.6.0: + resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} + engines: {node: '>=10.16.0'} + dependencies: + streamsearch: 1.1.0 + dev: true + /bytes/3.1.2: resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==} engines: {node: '>= 0.8'} @@ -2865,7 +2873,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/parser': 5.15.0 debug: 2.6.9 eslint-import-resolver-node: 0.3.4 pkg-dir: 2.0.0 @@ -2873,7 +2881,7 @@ packages: - supports-color dev: true - /eslint-plugin-import/2.22.1_x76hk6kpvj4wcg2rfkjxf5ikka: + /eslint-plugin-import/2.22.1_3idpik77dtp2p37mwvxiru2mra: resolution: {integrity: sha512-8K7JjINHOpH64ozkAhpT3sd+FswIZTfMZTjdx052pnWrgRCVfp8op9tbjpAk3DdUeI/Ba4C8OjdC0r90erHEOw==} engines: {node: '>=4'} peerDependencies: @@ -2883,13 +2891,12 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.15.0_c6rgizndxqcplp6oy5ayxlzjgm + '@typescript-eslint/parser': 5.15.0 array-includes: 3.1.2 array.prototype.flat: 1.2.4 contains-path: 0.1.0 debug: 2.6.9 doctrine: 1.5.0 - eslint: 7.18.0 eslint-import-resolver-node: 0.3.4 eslint-module-utils: 2.6.0_i6ewxqunfsnauarvu3h4jo73fi has: 1.0.3 @@ -2924,13 +2931,12 @@ packages: eslint-visitor-keys: 1.3.0 dev: true - /eslint-utils/3.0.0_eslint@7.18.0: + /eslint-utils/3.0.0: resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} peerDependencies: eslint: '>=5' dependencies: - eslint: 7.18.0 eslint-visitor-keys: 2.0.0 dev: true @@ -3070,12 +3076,12 @@ packages: create-hash: 1.2.0 create-hmac: 1.1.7 hash.js: 1.1.7 - keccak: 3.0.1 + keccak: 3.0.2 pbkdf2: 3.1.2 randombytes: 2.1.0 safe-buffer: 5.2.1 scrypt-js: 3.0.1 - secp256k1: 4.0.2 + secp256k1: 4.0.3 setimmediate: 1.0.5 /ethereum-cryptography/1.1.2: @@ -3644,7 +3650,7 @@ packages: lodash: 4.17.21 merkle-patricia-tree: 4.2.4 mnemonist: 0.38.5 - mocha: 10.0.0 + mocha: 10.1.0 p-map: 4.0.0 qs: 6.10.3 raw-body: 2.5.1 @@ -3656,7 +3662,7 @@ packages: stacktrace-parser: 0.1.10 true-case-path: 2.2.1 tsort: 0.0.1 - undici: 5.8.0 + undici: 5.12.0 uuid: 8.3.2 ws: 7.4.6 transitivePeerDependencies: @@ -4069,6 +4075,12 @@ packages: resolution: {integrity: sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==} dev: false + /json-bigint/1.0.0: + resolution: {integrity: sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==} + dependencies: + bignumber.js: 9.1.0 + dev: false + /json-parse-even-better-errors/2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} dev: false @@ -4139,6 +4151,7 @@ packages: dependencies: node-addon-api: 2.0.2 node-gyp-build: 4.4.0 + dev: false /keccak/3.0.2: resolution: {integrity: sha512-PyKKjkH53wDMLGrvmRGSNWgmSxZOUqbnXwKL9tmgbFYA1iAYqW21kfR7mZXV0MlESiefxQQE9X9fTa3X+2MPDQ==} @@ -4555,12 +4568,11 @@ packages: obliterator: 2.0.2 dev: true - /mocha/10.0.0: - resolution: {integrity: sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA==} + /mocha/10.1.0: + resolution: {integrity: sha512-vUF7IYxEoN7XhQpFLxQAEMtE4W91acW4B6En9l97MwE9stL1A9gusXfoHZCLVHDUJ/7V5+lbCM6yMqzo5vNymg==} engines: {node: '>= 14.0.0'} hasBin: true dependencies: - '@ungap/promise-all-settled': 1.1.2 ansi-colors: 4.1.1 browser-stdout: 1.3.1 chokidar: 3.5.3 @@ -5421,15 +5433,6 @@ packages: /scrypt-js/3.0.1: resolution: {integrity: sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==} - /secp256k1/4.0.2: - resolution: {integrity: sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==} - engines: {node: '>=10.0.0'} - requiresBuild: true - dependencies: - elliptic: 6.5.4 - node-addon-api: 2.0.2 - node-gyp-build: 4.4.0 - /secp256k1/4.0.3: resolution: {integrity: sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA==} engines: {node: '>=10.0.0'} @@ -5705,6 +5708,11 @@ packages: mixme: 0.5.4 dev: false + /streamsearch/1.1.0: + resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} + engines: {node: '>=10.0.0'} + dev: true + /strict-uri-encode/1.1.0: resolution: {integrity: sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=} engines: {node: '>=0.10.0'} @@ -5942,6 +5950,12 @@ packages: command-line-usage: 6.1.1 string-format: 2.0.0 + /ts-essentials/7.0.3: + resolution: {integrity: sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==} + peerDependencies: + typescript: '>=3.7.0' + dev: true + /ts-essentials/7.0.3_typescript@4.6.2: resolution: {integrity: sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==} peerDependencies: @@ -5964,6 +5978,21 @@ packages: yn: 3.1.1 dev: true + /ts-node/9.1.1: + resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==} + engines: {node: '>=10.0.0'} + hasBin: true + peerDependencies: + typescript: '>=2.7' + dependencies: + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + source-map-support: 0.5.19 + yn: 3.1.1 + dev: true + /ts-node/9.1.1_typescript@4.6.2: resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==} engines: {node: '>=10.0.0'} @@ -5997,14 +6026,13 @@ packages: resolution: {integrity: sha1-4igPXoF/i/QnVlf9D5rr1E9aJ4Y=} dev: true - /tsutils/3.21.0_typescript@4.6.2: + /tsutils/3.21.0: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 4.6.2 dev: true /tty-table/2.8.13: @@ -6074,6 +6102,26 @@ packages: resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==} engines: {node: '>=8'} + /typechain/8.0.0: + resolution: {integrity: sha512-rqDfDYc9voVAhmfVfAwzg3VYFvhvs5ck1X9T/iWkX745Cul4t+V/smjnyqrbDzWDbzD93xfld1epg7Y/uFAesQ==} + hasBin: true + peerDependencies: + typescript: '>=4.3.0' + dependencies: + '@types/prettier': 2.3.0 + debug: 4.3.4 + fs-extra: 7.0.1 + glob: 7.1.7 + js-sha3: 0.8.0 + lodash: 4.17.21 + mkdirp: 1.0.4 + prettier: 2.3.1 + ts-command-line-args: 2.2.1 + ts-essentials: 7.0.3 + transitivePeerDependencies: + - supports-color + dev: true + /typechain/8.0.0_typescript@4.6.2: resolution: {integrity: sha512-rqDfDYc9voVAhmfVfAwzg3VYFvhvs5ck1X9T/iWkX745Cul4t+V/smjnyqrbDzWDbzD93xfld1epg7Y/uFAesQ==} hasBin: true @@ -6120,9 +6168,11 @@ packages: resolution: {integrity: sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==} dev: true - /undici/5.8.0: - resolution: {integrity: sha512-1F7Vtcez5w/LwH2G2tGnFIihuWUlc58YidwLiCv+jR2Z50x0tNXpRRw7eOIJ+GvqCqIkg9SB7NWAJ/T9TLfv8Q==} + /undici/5.12.0: + resolution: {integrity: sha512-zMLamCG62PGjd9HHMpo05bSLvvwWOZgGeiWlN/vlqu3+lRo3elxktVGEyLMX+IO7c2eflLjcW74AlkhEZm15mg==} engines: {node: '>=12.18'} + dependencies: + busboy: 1.6.0 dev: true /universalify/0.1.2: @@ -6135,7 +6185,7 @@ packages: dev: true /unpipe/1.0.0: - resolution: {integrity: sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=} + resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} dev: true diff --git a/waffle-chai/package.json b/waffle-chai/package.json index 52cf68ce7..b1eb21643 100644 --- a/waffle-chai/package.json +++ b/waffle-chai/package.json @@ -43,15 +43,17 @@ }, "dependencies": { "@ethereum-waffle/provider": "workspace:*", - "debug": "^4.3.4" + "debug": "^4.3.4", + "json-bigint": "^1.0.0" }, "devDependencies": { - "ethers": "5.6.2", "@types/debug": "^4.1.7", + "@types/json-bigint": "^1.0.1", + "eslint": "^7.14.0", + "ethers": "5.6.2", "mocha": "^8.2.1", "rimraf": "^3.0.2", - "typescript": "^4.6.2", - "eslint": "^7.14.0" + "typescript": "^4.6.2" }, "peerDependencies": { "ethers": "*" diff --git a/waffle-chai/src/matchers/revertedWith.ts b/waffle-chai/src/matchers/revertedWith.ts index d6aabebbd..7e5b9ee95 100644 --- a/waffle-chai/src/matchers/revertedWith.ts +++ b/waffle-chai/src/matchers/revertedWith.ts @@ -1,5 +1,6 @@ import {decodeRevertString} from '@ethereum-waffle/provider'; import {callPromise} from '../call-promise'; +import JSONbig from 'json-bigint'; export function supportRevertedWith(Assertion: Chai.AssertionStatic) { Assertion.addMethod('revertedWith', function (this: any, revertReason: string | RegExp) { @@ -65,8 +66,15 @@ const decodeHardhatError = (error: any, context: any) => { const regexp = /VM Exception while processing transaction: reverted with custom error '([a-zA-Z0-9$_]+)\((.*)\)'/g; const matches = regexp.exec(errorString); if (matches && matches.length >= 1) { - // needs to be wrapped in list to be consistent with the emit matcher - context.args = [JSON.parse(`[${matches[2]}]`)]; + // Matches is in a format of string: "arg1, arg2, arg3, ..." + // So it only makes sense in an array: + const matchesList = `[${matches[2]}]`; + // Next, it needs to be wrapped in a list to be consistent with the emit matcher: + context.args = [ + // Additionally, we preserve numbers as strings, + // otherwise we face an overflow of bignumber. + JSONbig({storeAsString: true}).parse(matchesList) + ]; const errorName = matches[1]; context.txErrorName = errorName; return errorName; diff --git a/waffle-hardhat/contracts/CustomError.sol b/waffle-hardhat/contracts/CustomError.sol index 2b9e2456a..4dd4ae2a2 100644 --- a/waffle-hardhat/contracts/CustomError.sol +++ b/waffle-hardhat/contracts/CustomError.sol @@ -9,6 +9,10 @@ contract Matchers { revert One(0, 'message', 0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162123); } + function doRevertWithBigNumber() public pure { + revert One(9007199254740991000000, 'message', 0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162123); + } + function doRevertWithTwo() public pure { revert Two( [ diff --git a/waffle-hardhat/test/reverted.test.ts b/waffle-hardhat/test/reverted.test.ts index aec61525f..7c33315ac 100644 --- a/waffle-hardhat/test/reverted.test.ts +++ b/waffle-hardhat/test/reverted.test.ts @@ -2,7 +2,7 @@ import {waffle} from 'hardhat'; import {expect} from 'chai'; import {MockProvider} from 'ethereum-waffle'; import {revertedTest, revertedWithTest} from '@ethereum-waffle/chai/test'; -import {ContractFactory} from 'ethers'; +import {BigNumber, ContractFactory} from 'ethers'; import CustomError from '../build/contracts/CustomError.sol/Matchers.json'; describe('INTEGRATION: Matchers: reverted', () => { @@ -58,6 +58,37 @@ describe('INTEGRATION: Matchers: revertedWith', () => { 'message', '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123' ); + + await expect(matchers.doRevertWithOne()) + .to.be.revertedWith('One') + .withArgs( + BigNumber.from('0'), // Check BigNumber instance as well. + 'message', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123' + ); + }); + + it('With args and big number success', async () => { + const matchers = await deploy(); + await expect(matchers.doRevertWithBigNumber()) + .to.be.revertedWith('One') + .withArgs( + BigNumber.from('9007199254740991000000'), + 'message', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123' + ); + }); + + it('With args and big number failure', async () => { + const matchers = await deploy(); + await expect(expect(matchers.doRevertWithBigNumber()) + .to.be.revertedWith('One') + .withArgs( + BigNumber.from('9007199254740991000001'), // different + 'message', + '0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123' + ) + ).to.be.eventually.rejectedWith('Expected "9007199254740991000000" to be equal 9007199254740991000001'); }); it('With args failure', async () => {