@nomicfoundation/hardhat-ethers-chai-matchers 3.0.0-next.3 → 3.0.0-next.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -26
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/add-chai-matchers.d.ts.map +1 -1
- package/dist/src/internal/add-chai-matchers.js +4 -2
- package/dist/src/internal/add-chai-matchers.js.map +1 -1
- package/dist/src/internal/constants.d.ts +2 -1
- package/dist/src/internal/constants.d.ts.map +1 -1
- package/dist/src/internal/constants.js +2 -1
- package/dist/src/internal/constants.js.map +1 -1
- package/dist/src/internal/matchers/big-number.js +2 -2
- package/dist/src/internal/matchers/big-number.js.map +1 -1
- package/dist/src/internal/matchers/changeEtherBalance.d.ts +2 -2
- package/dist/src/internal/matchers/changeEtherBalance.d.ts.map +1 -1
- package/dist/src/internal/matchers/changeEtherBalance.js +7 -16
- package/dist/src/internal/matchers/changeEtherBalance.js.map +1 -1
- package/dist/src/internal/matchers/changeEtherBalances.d.ts +2 -2
- package/dist/src/internal/matchers/changeEtherBalances.d.ts.map +1 -1
- package/dist/src/internal/matchers/changeEtherBalances.js +6 -6
- package/dist/src/internal/matchers/changeEtherBalances.js.map +1 -1
- package/dist/src/internal/matchers/changeTokenBalance.d.ts +2 -2
- package/dist/src/internal/matchers/changeTokenBalance.d.ts.map +1 -1
- package/dist/src/internal/matchers/changeTokenBalance.js +13 -17
- package/dist/src/internal/matchers/changeTokenBalance.js.map +1 -1
- package/dist/src/internal/matchers/emit.js +4 -4
- package/dist/src/internal/matchers/emit.js.map +1 -1
- package/dist/src/internal/matchers/reverted/legacyReverted.d.ts +2 -0
- package/dist/src/internal/matchers/reverted/legacyReverted.d.ts.map +1 -0
- package/dist/src/internal/matchers/reverted/legacyReverted.js +12 -0
- package/dist/src/internal/matchers/reverted/legacyReverted.js.map +1 -0
- package/dist/src/internal/matchers/reverted/revert.d.ts +2 -0
- package/dist/src/internal/matchers/reverted/revert.d.ts.map +1 -0
- package/dist/src/internal/matchers/reverted/{reverted.js → revert.js} +9 -9
- package/dist/src/internal/matchers/reverted/revert.js.map +1 -0
- package/dist/src/internal/matchers/reverted/revertedWith.js +1 -1
- package/dist/src/internal/matchers/reverted/revertedWith.js.map +1 -1
- package/dist/src/internal/matchers/reverted/revertedWithCustomError.js +5 -5
- package/dist/src/internal/matchers/reverted/revertedWithCustomError.js.map +1 -1
- package/dist/src/internal/matchers/reverted/revertedWithPanic.js +1 -1
- package/dist/src/internal/matchers/reverted/revertedWithPanic.js.map +1 -1
- package/dist/src/internal/matchers/reverted/utils.d.ts.map +1 -1
- package/dist/src/internal/matchers/reverted/utils.js +2 -2
- package/dist/src/internal/matchers/reverted/utils.js.map +1 -1
- package/dist/src/internal/matchers/withArgs.js +3 -3
- package/dist/src/internal/matchers/withArgs.js.map +1 -1
- package/dist/src/internal/utils/account.js +1 -1
- package/dist/src/internal/utils/account.js.map +1 -1
- package/dist/src/internal/utils/asserts.js +1 -1
- package/dist/src/internal/utils/asserts.js.map +1 -1
- package/dist/src/internal/utils/balance.d.ts +2 -2
- package/dist/src/internal/utils/balance.d.ts.map +1 -1
- package/dist/src/internal/utils/balance.js +2 -6
- package/dist/src/internal/utils/balance.js.map +1 -1
- package/dist/src/internal/utils/build-assert.d.ts.map +1 -1
- package/dist/src/internal/utils/build-assert.js +2 -2
- package/dist/src/internal/utils/build-assert.js.map +1 -1
- package/dist/src/internal/utils/prevent-chaining.js +1 -1
- package/dist/src/internal/utils/prevent-chaining.js.map +1 -1
- package/dist/src/type-extensions.d.ts +6 -6
- package/dist/src/type-extensions.d.ts.map +1 -1
- package/package.json +12 -20
- package/src/index.ts +2 -9
- package/src/internal/add-chai-matchers.ts +4 -2
- package/src/internal/constants.ts +2 -1
- package/src/internal/matchers/big-number.ts +2 -2
- package/src/internal/matchers/changeEtherBalance.ts +15 -17
- package/src/internal/matchers/changeEtherBalances.ts +7 -11
- package/src/internal/matchers/changeTokenBalance.ts +15 -18
- package/src/internal/matchers/emit.ts +4 -4
- package/src/internal/matchers/reverted/legacyReverted.ts +19 -0
- package/src/internal/matchers/reverted/{reverted.ts → revert.ts} +8 -8
- package/src/internal/matchers/reverted/revertedWith.ts +1 -1
- package/src/internal/matchers/reverted/revertedWithCustomError.ts +5 -5
- package/src/internal/matchers/reverted/revertedWithPanic.ts +1 -1
- package/src/internal/matchers/reverted/utils.ts +16 -10
- package/src/internal/matchers/withArgs.ts +3 -3
- package/src/internal/utils/account.ts +1 -1
- package/src/internal/utils/asserts.ts +1 -1
- package/src/internal/utils/balance.ts +4 -9
- package/src/internal/utils/build-assert.ts +2 -2
- package/src/internal/utils/prevent-chaining.ts +1 -1
- package/src/type-extensions.ts +6 -7
- package/dist/src/internal/matchers/reverted/reverted.d.ts +0 -2
- package/dist/src/internal/matchers/reverted/reverted.d.ts.map +0 -1
- package/dist/src/internal/matchers/reverted/reverted.js.map +0 -1
package/src/index.ts
CHANGED
@@ -5,17 +5,10 @@ import "./type-extensions.js";
|
|
5
5
|
const hardhatChaiMatchersPlugin: HardhatPlugin = {
|
6
6
|
id: "hardhat-ethers-chai-matchers",
|
7
7
|
hookHandlers: {
|
8
|
-
network: import
|
8
|
+
network: () => import("./internal/hook-handlers/network.js"),
|
9
9
|
},
|
10
10
|
npmPackage: "@nomicfoundation/hardhat-ethers-chai-matchers",
|
11
|
-
dependencies: [
|
12
|
-
async () => {
|
13
|
-
const { default: hardhatEthersPlugin } = await import(
|
14
|
-
"@nomicfoundation/hardhat-ethers"
|
15
|
-
);
|
16
|
-
return hardhatEthersPlugin;
|
17
|
-
},
|
18
|
-
],
|
11
|
+
dependencies: () => [import("@nomicfoundation/hardhat-ethers")],
|
19
12
|
};
|
20
13
|
|
21
14
|
export default hardhatChaiMatchersPlugin;
|
@@ -11,7 +11,8 @@ import { supportHexEqual } from "./matchers/hexEqual.js";
|
|
11
11
|
import { supportProperAddress } from "./matchers/properAddress.js";
|
12
12
|
import { supportProperHex } from "./matchers/properHex.js";
|
13
13
|
import { supportProperPrivateKey } from "./matchers/properPrivateKey.js";
|
14
|
-
import {
|
14
|
+
import { supportLegacyReverted } from "./matchers/reverted/legacyReverted.js";
|
15
|
+
import { supportRevert } from "./matchers/reverted/revert.js";
|
15
16
|
import { supportRevertedWith } from "./matchers/reverted/revertedWith.js";
|
16
17
|
import { supportRevertedWithCustomError } from "./matchers/reverted/revertedWithCustomError.js";
|
17
18
|
import { supportRevertedWithPanic } from "./matchers/reverted/revertedWithPanic.js";
|
@@ -37,7 +38,8 @@ function hardhatChaiMatchers(
|
|
37
38
|
supportChangeEtherBalance(chai.Assertion, chaiUtils);
|
38
39
|
supportChangeEtherBalances(chai.Assertion, chaiUtils);
|
39
40
|
supportChangeTokenBalance(chai.Assertion, chaiUtils);
|
40
|
-
|
41
|
+
supportLegacyReverted(chai.Assertion, chaiUtils);
|
42
|
+
supportRevert(chai.Assertion, chaiUtils);
|
41
43
|
supportRevertedWith(chai.Assertion, chaiUtils);
|
42
44
|
supportRevertedWithCustomError(chai.Assertion, chaiUtils);
|
43
45
|
supportRevertedWithPanic(chai.Assertion, chaiUtils);
|
@@ -6,7 +6,8 @@ export const CHANGE_ETHER_BALANCES_MATCHER = "changeEtherBalances";
|
|
6
6
|
export const CHANGE_TOKEN_BALANCE_MATCHER = "changeTokenBalance";
|
7
7
|
export const CHANGE_TOKEN_BALANCES_MATCHER = "changeTokenBalances";
|
8
8
|
export const EMIT_MATCHER = "emit";
|
9
|
-
export const
|
9
|
+
export const LEGACY_REVERTED_MATCHER = "reverted";
|
10
|
+
export const REVERT_MATCHER = "revert";
|
10
11
|
export const REVERTED_WITH_MATCHER = "revertedWith";
|
11
12
|
export const REVERTED_WITH_CUSTOM_ERROR_MATCHER = "revertedWithCustomError";
|
12
13
|
export const REVERTED_WITH_PANIC_MATCHER = "revertedWithPanic";
|
@@ -121,7 +121,7 @@ function overwriteBigNumberFunction(
|
|
121
121
|
return lhs <= rhs;
|
122
122
|
} else {
|
123
123
|
throw new HardhatError(
|
124
|
-
HardhatError.ERRORS.CHAI_MATCHERS.UNKNOWN_COMPARISON_OPERATION,
|
124
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.UNKNOWN_COMPARISON_OPERATION,
|
125
125
|
{
|
126
126
|
method,
|
127
127
|
},
|
@@ -272,7 +272,7 @@ function deepEqualComparator(a: any, b: any): boolean | null {
|
|
272
272
|
const normalizedA = toBigInt(a);
|
273
273
|
const normalizedB = toBigInt(b);
|
274
274
|
return normalizedA === normalizedB;
|
275
|
-
} catch (
|
275
|
+
} catch (_error) {
|
276
276
|
// use default comparator
|
277
277
|
return null;
|
278
278
|
}
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import type { BalanceChangeOptions } from "../utils/balance.js";
|
2
|
+
import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
2
3
|
import type { Addressable } from "ethers/address";
|
3
4
|
import type { TransactionResponse } from "ethers/providers";
|
4
5
|
import type { BigNumberish } from "ethers/utils";
|
5
|
-
import type { EthereumProvider } from "hardhat/types/providers";
|
6
6
|
|
7
7
|
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
|
8
|
-
import { numberToHexString } from "@nomicfoundation/hardhat-utils/hex";
|
9
8
|
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
|
10
9
|
import { toBigInt } from "ethers/utils";
|
11
10
|
|
@@ -26,7 +25,7 @@ export function supportChangeEtherBalance(
|
|
26
25
|
CHANGE_ETHER_BALANCE_MATCHER,
|
27
26
|
function (
|
28
27
|
this: any,
|
29
|
-
|
28
|
+
ethers: HardhatEthers,
|
30
29
|
account: Addressable | string,
|
31
30
|
balanceChange: BigNumberish | ((change: bigint) => boolean),
|
32
31
|
options?: BalanceChangeOptions,
|
@@ -64,7 +63,7 @@ export function supportChangeEtherBalance(
|
|
64
63
|
};
|
65
64
|
|
66
65
|
const derivedPromise = Promise.all([
|
67
|
-
getBalanceChange(
|
66
|
+
getBalanceChange(ethers, subject, account, options),
|
68
67
|
getAddressOf(account),
|
69
68
|
]).then(checkBalanceChange);
|
70
69
|
this.then = derivedPromise.then.bind(derivedPromise);
|
@@ -76,7 +75,7 @@ export function supportChangeEtherBalance(
|
|
76
75
|
}
|
77
76
|
|
78
77
|
export async function getBalanceChange(
|
79
|
-
|
78
|
+
ethers: HardhatEthers,
|
80
79
|
transaction:
|
81
80
|
| TransactionResponse
|
82
81
|
| Promise<TransactionResponse>
|
@@ -96,10 +95,9 @@ export async function getBalanceChange(
|
|
96
95
|
assertIsNotNull(txReceipt, "txReceipt");
|
97
96
|
const txBlockNumber = txReceipt.blockNumber;
|
98
97
|
|
99
|
-
const block = await provider.
|
100
|
-
|
101
|
-
|
102
|
-
});
|
98
|
+
const block = await ethers.provider.getBlock(txReceipt.blockHash, false);
|
99
|
+
|
100
|
+
assertHardhatInvariant(block !== null, "The block doesn't exist");
|
103
101
|
|
104
102
|
assertHardhatInvariant(
|
105
103
|
isObject(block) &&
|
@@ -110,15 +108,15 @@ export async function getBalanceChange(
|
|
110
108
|
|
111
109
|
const address = await getAddressOf(account);
|
112
110
|
|
113
|
-
const balanceAfterHex = await provider.
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
const balanceAfterHex = await ethers.provider.getBalance(
|
112
|
+
address,
|
113
|
+
txBlockNumber,
|
114
|
+
);
|
117
115
|
|
118
|
-
const balanceBeforeHex = await provider.
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
const balanceBeforeHex = await ethers.provider.getBalance(
|
117
|
+
address,
|
118
|
+
txBlockNumber - 1,
|
119
|
+
);
|
122
120
|
|
123
121
|
assertCanBeConvertedToBigint(balanceAfterHex);
|
124
122
|
assertCanBeConvertedToBigint(balanceBeforeHex);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { BalanceChangeOptions } from "../utils/balance.js";
|
2
|
+
import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
2
3
|
import type { Addressable } from "ethers/address";
|
3
4
|
import type { TransactionResponse } from "ethers/providers";
|
4
|
-
import type { EthereumProvider } from "hardhat/types/providers";
|
5
5
|
|
6
6
|
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
7
7
|
import { toBigInt } from "ethers/utils";
|
@@ -22,7 +22,7 @@ export function supportChangeEtherBalances(
|
|
22
22
|
CHANGE_ETHER_BALANCES_MATCHER,
|
23
23
|
function (
|
24
24
|
this: any,
|
25
|
-
|
25
|
+
ethers: HardhatEthers,
|
26
26
|
accounts: Array<Addressable | string>,
|
27
27
|
balanceChanges: bigint[] | ((changes: bigint[]) => boolean),
|
28
28
|
options?: BalanceChangeOptions,
|
@@ -99,7 +99,7 @@ export function supportChangeEtherBalances(
|
|
99
99
|
};
|
100
100
|
|
101
101
|
const derivedPromise = Promise.all([
|
102
|
-
getBalanceChanges(
|
102
|
+
getBalanceChanges(ethers, subject, accounts, options),
|
103
103
|
getAddresses(accounts),
|
104
104
|
]).then(checkBalanceChanges);
|
105
105
|
this.then = derivedPromise.then.bind(derivedPromise);
|
@@ -121,7 +121,7 @@ function validateInput(
|
|
121
121
|
accounts.length !== balanceChanges.length
|
122
122
|
) {
|
123
123
|
throw new HardhatError(
|
124
|
-
HardhatError.ERRORS.CHAI_MATCHERS.ACCOUNTS_NUMBER_DIFFERENT_FROM_BALANCE_CHANGES,
|
124
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.ACCOUNTS_NUMBER_DIFFERENT_FROM_BALANCE_CHANGES,
|
125
125
|
{
|
126
126
|
accounts: accounts.length,
|
127
127
|
balanceChanges: balanceChanges.length,
|
@@ -137,7 +137,7 @@ function validateInput(
|
|
137
137
|
}
|
138
138
|
|
139
139
|
export async function getBalanceChanges(
|
140
|
-
|
140
|
+
ethers: HardhatEthers,
|
141
141
|
transaction: TransactionResponse | Promise<TransactionResponse>,
|
142
142
|
accounts: Array<Addressable | string>,
|
143
143
|
options?: BalanceChangeOptions,
|
@@ -148,12 +148,8 @@ export async function getBalanceChanges(
|
|
148
148
|
assertIsNotNull(txReceipt, "txReceipt");
|
149
149
|
const txBlockNumber = txReceipt.blockNumber;
|
150
150
|
|
151
|
-
const balancesAfter = await getBalances(
|
152
|
-
const balancesBefore = await getBalances(
|
153
|
-
provider,
|
154
|
-
accounts,
|
155
|
-
txBlockNumber - 1,
|
156
|
-
);
|
151
|
+
const balancesAfter = await getBalances(ethers, accounts, txBlockNumber);
|
152
|
+
const balancesBefore = await getBalances(ethers, accounts, txBlockNumber - 1);
|
157
153
|
|
158
154
|
const txFees = await getTxFees(accounts, txResponse, options);
|
159
155
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
1
2
|
import type {
|
2
3
|
Addressable,
|
3
4
|
BaseContract,
|
@@ -6,7 +7,6 @@ import type {
|
|
6
7
|
ContractTransactionResponse,
|
7
8
|
} from "ethers";
|
8
9
|
import type { TransactionResponse } from "ethers/providers";
|
9
|
-
import type { EthereumProvider } from "hardhat/types/providers";
|
10
10
|
|
11
11
|
import {
|
12
12
|
assertHardhatInvariant,
|
@@ -43,7 +43,7 @@ export function supportChangeTokenBalance(
|
|
43
43
|
CHANGE_TOKEN_BALANCE_MATCHER,
|
44
44
|
function (
|
45
45
|
this: any,
|
46
|
-
|
46
|
+
ethers: HardhatEthers,
|
47
47
|
token: Token,
|
48
48
|
account: Addressable | string,
|
49
49
|
balanceChange: bigint | ((change: bigint) => boolean),
|
@@ -87,7 +87,7 @@ export function supportChangeTokenBalance(
|
|
87
87
|
};
|
88
88
|
|
89
89
|
const derivedPromise = Promise.all([
|
90
|
-
getBalanceChange(
|
90
|
+
getBalanceChange(ethers, subject, token, account),
|
91
91
|
getAddressOf(account),
|
92
92
|
getTokenDescription(token),
|
93
93
|
]).then(checkBalanceChange);
|
@@ -103,7 +103,7 @@ export function supportChangeTokenBalance(
|
|
103
103
|
CHANGE_TOKEN_BALANCES_MATCHER,
|
104
104
|
function (
|
105
105
|
this: any,
|
106
|
-
|
106
|
+
ethers: HardhatEthers,
|
107
107
|
token: Token,
|
108
108
|
accounts: Array<Addressable | string>,
|
109
109
|
balanceChanges: bigint[] | ((changes: bigint[]) => boolean),
|
@@ -126,7 +126,7 @@ export function supportChangeTokenBalance(
|
|
126
126
|
|
127
127
|
const balanceChangesPromise = Promise.all(
|
128
128
|
accounts.map((account) =>
|
129
|
-
getBalanceChange(
|
129
|
+
getBalanceChange(ethers, subject, token, account),
|
130
130
|
),
|
131
131
|
);
|
132
132
|
const addressesPromise = Promise.all(accounts.map(getAddressOf));
|
@@ -191,7 +191,7 @@ function validateInput(
|
|
191
191
|
accounts.length !== balanceChanges.length
|
192
192
|
) {
|
193
193
|
throw new HardhatError(
|
194
|
-
HardhatError.ERRORS.CHAI_MATCHERS.ACCOUNTS_NUMBER_DIFFERENT_FROM_BALANCE_CHANGES,
|
194
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.ACCOUNTS_NUMBER_DIFFERENT_FROM_BALANCE_CHANGES,
|
195
195
|
{
|
196
196
|
accounts: accounts.length,
|
197
197
|
balanceChanges: balanceChanges.length,
|
@@ -209,7 +209,7 @@ function validateInput(
|
|
209
209
|
function checkToken(token: unknown, method: string) {
|
210
210
|
if (!isObject(token) || token === null || !("interface" in token)) {
|
211
211
|
throw new HardhatError(
|
212
|
-
HardhatError.ERRORS.CHAI_MATCHERS.FIRST_ARGUMENT_MUST_BE_A_CONTRACT_INSTANCE,
|
212
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.FIRST_ARGUMENT_MUST_BE_A_CONTRACT_INSTANCE,
|
213
213
|
{
|
214
214
|
method,
|
215
215
|
},
|
@@ -223,13 +223,13 @@ function checkToken(token: unknown, method: string) {
|
|
223
223
|
token.interface.getFunction("balanceOf") === null
|
224
224
|
) {
|
225
225
|
throw new HardhatError(
|
226
|
-
HardhatError.ERRORS.CHAI_MATCHERS.CONTRACT_IS_NOT_AN_ERC20_TOKEN,
|
226
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.CONTRACT_IS_NOT_AN_ERC20_TOKEN,
|
227
227
|
);
|
228
228
|
}
|
229
229
|
}
|
230
230
|
|
231
231
|
export async function getBalanceChange(
|
232
|
-
|
232
|
+
ethers: HardhatEthers,
|
233
233
|
transaction: TransactionResponse | Promise<TransactionResponse>,
|
234
234
|
token: Token,
|
235
235
|
account: Addressable | string,
|
@@ -240,15 +240,12 @@ export async function getBalanceChange(
|
|
240
240
|
assertIsNotNull(txReceipt, "txReceipt");
|
241
241
|
const txBlockNumber = txReceipt.blockNumber;
|
242
242
|
|
243
|
-
const block = await provider.
|
244
|
-
|
245
|
-
|
246
|
-
});
|
243
|
+
const block = await ethers.provider.getBlock(txReceipt.blockHash, false);
|
244
|
+
|
245
|
+
assertHardhatInvariant(block !== null, "The block doesn't exist");
|
247
246
|
|
248
247
|
assertHardhatInvariant(
|
249
|
-
|
250
|
-
Array.isArray(block.transactions) &&
|
251
|
-
block.transactions.length === 1,
|
248
|
+
Array.isArray(block.transactions) && block.transactions.length === 1,
|
252
249
|
"There should be only 1 transaction in the block",
|
253
250
|
);
|
254
251
|
|
@@ -277,10 +274,10 @@ async function getTokenDescription(token: Token): Promise<string> {
|
|
277
274
|
let tokenDescription = `<token at ${tokenAddress}>`;
|
278
275
|
try {
|
279
276
|
tokenDescription = await token.symbol();
|
280
|
-
} catch (
|
277
|
+
} catch (_error) {
|
281
278
|
try {
|
282
279
|
tokenDescription = await token.name();
|
283
|
-
} catch (
|
280
|
+
} catch (_error2) {}
|
284
281
|
}
|
285
282
|
|
286
283
|
tokenDescriptionsCache[tokenAddress] = tokenDescription;
|
@@ -31,7 +31,7 @@ async function waitForPendingTransaction(
|
|
31
31
|
|
32
32
|
if (hash === null) {
|
33
33
|
throw new HardhatError(
|
34
|
-
HardhatError.ERRORS.CHAI_MATCHERS.INVALID_TRANSACTION,
|
34
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.INVALID_TRANSACTION,
|
35
35
|
{ transaction: JSON.stringify(tx) },
|
36
36
|
);
|
37
37
|
}
|
@@ -90,13 +90,13 @@ export function supportEmit(
|
|
90
90
|
const contractAddress = contract.target;
|
91
91
|
if (typeof contractAddress !== "string") {
|
92
92
|
throw new HardhatError(
|
93
|
-
HardhatError.ERRORS.CHAI_MATCHERS.CONTRACT_TARGET_MUST_BE_A_STRING,
|
93
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.CONTRACT_TARGET_MUST_BE_A_STRING,
|
94
94
|
);
|
95
95
|
}
|
96
96
|
|
97
97
|
if (args.length > 0) {
|
98
98
|
throw new HardhatError(
|
99
|
-
HardhatError.ERRORS.CHAI_MATCHERS.EMIT_EXPECTS_TWO_ARGUMENTS,
|
99
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.EMIT_EXPECTS_TWO_ARGUMENTS,
|
100
100
|
);
|
101
101
|
}
|
102
102
|
|
@@ -125,7 +125,7 @@ export function supportEmit(
|
|
125
125
|
|
126
126
|
if (contract.runner === null || contract.runner.provider === null) {
|
127
127
|
throw new HardhatError(
|
128
|
-
HardhatError.ERRORS.CHAI_MATCHERS.CONTRACT_RUNNER_PROVIDER_NOT_NULL,
|
128
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.CONTRACT_RUNNER_PROVIDER_NOT_NULL,
|
129
129
|
);
|
130
130
|
}
|
131
131
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
2
|
+
|
3
|
+
import { LEGACY_REVERTED_MATCHER } from "../../constants.js";
|
4
|
+
|
5
|
+
export function supportLegacyReverted(
|
6
|
+
Assertion: Chai.AssertionStatic,
|
7
|
+
_chaiUtils: Chai.ChaiUtils,
|
8
|
+
): void {
|
9
|
+
Assertion.addProperty(LEGACY_REVERTED_MATCHER, function () {
|
10
|
+
// We handle the promise rejection, if any
|
11
|
+
if (this._obj instanceof Promise) {
|
12
|
+
this._obj.catch(() => {});
|
13
|
+
}
|
14
|
+
|
15
|
+
throw new HardhatError(
|
16
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.DEPRECATED_REVERTED_MATCHER,
|
17
|
+
);
|
18
|
+
});
|
19
|
+
}
|
@@ -3,7 +3,7 @@ import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
|
3
3
|
import { HardhatError } from "@nomicfoundation/hardhat-errors";
|
4
4
|
import { numberToHexString } from "@nomicfoundation/hardhat-utils/hex";
|
5
5
|
|
6
|
-
import {
|
6
|
+
import { REVERT_MATCHER } from "../../constants.js";
|
7
7
|
import { assertIsNotNull } from "../../utils/asserts.js";
|
8
8
|
import { buildAssert } from "../../utils/build-assert.js";
|
9
9
|
import { preventAsyncMatcherChaining } from "../../utils/prevent-chaining.js";
|
@@ -14,24 +14,24 @@ import {
|
|
14
14
|
parseBytes32String,
|
15
15
|
} from "./utils.js";
|
16
16
|
|
17
|
-
export function
|
17
|
+
export function supportRevert(
|
18
18
|
Assertion: Chai.AssertionStatic,
|
19
19
|
chaiUtils: Chai.ChaiUtils,
|
20
20
|
): void {
|
21
21
|
Assertion.addMethod(
|
22
|
-
|
22
|
+
REVERT_MATCHER,
|
23
23
|
function (this: any, ethers: HardhatEthers) {
|
24
24
|
// capture negated flag before async code executes; see buildAssert's jsdoc
|
25
25
|
const negated = this.__flags.negate;
|
26
26
|
|
27
27
|
const subject: unknown = this._obj;
|
28
28
|
|
29
|
-
preventAsyncMatcherChaining(this,
|
29
|
+
preventAsyncMatcherChaining(this, REVERT_MATCHER, chaiUtils);
|
30
30
|
|
31
31
|
// Check if the received value can be linked to a transaction, and then
|
32
32
|
// get the receipt of that transaction and check its status.
|
33
33
|
//
|
34
|
-
// If the value doesn't correspond to a transaction, then the `
|
34
|
+
// If the value doesn't correspond to a transaction, then the `revert`
|
35
35
|
// assertion is false.
|
36
36
|
const onSuccess = async (value: unknown) => {
|
37
37
|
const assert = buildAssert(negated, onSuccess);
|
@@ -41,7 +41,7 @@ export function supportReverted(
|
|
41
41
|
|
42
42
|
if (!isValidTransactionHash(hash)) {
|
43
43
|
throw new HardhatError(
|
44
|
-
HardhatError.ERRORS.CHAI_MATCHERS.EXPECTED_VALID_TRANSACTION_HASH,
|
44
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.EXPECTED_VALID_TRANSACTION_HASH,
|
45
45
|
{
|
46
46
|
hash,
|
47
47
|
},
|
@@ -75,10 +75,10 @@ export function supportReverted(
|
|
75
75
|
} else {
|
76
76
|
// If the subject of the assertion is not connected to a transaction
|
77
77
|
// (hash, receipt, etc.), then the assertion fails.
|
78
|
-
// Since we use `false` here, this means that `.not.to.be.
|
78
|
+
// Since we use `false` here, this means that `.not.to.be.revert`
|
79
79
|
// assertions will pass instead of always throwing a validation error.
|
80
80
|
// This allows users to do things like:
|
81
|
-
// `expect(c.callStatic.f()).to.not.be.
|
81
|
+
// `expect(c.callStatic.f()).to.not.be.revert`
|
82
82
|
assert(false, "Expected transaction to be reverted");
|
83
83
|
}
|
84
84
|
};
|
@@ -27,7 +27,7 @@ export function supportRevertedWith(
|
|
27
27
|
Promise.resolve(this._obj).catch(() => {});
|
28
28
|
|
29
29
|
throw new HardhatError(
|
30
|
-
HardhatError.ERRORS.CHAI_MATCHERS.EXPECT_STRING_OR_REGEX_AS_REVERT_REASON,
|
30
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.EXPECT_STRING_OR_REGEX_AS_REVERT_REASON,
|
31
31
|
);
|
32
32
|
}
|
33
33
|
|
@@ -161,14 +161,14 @@ function validateInput(
|
|
161
161
|
if (typeof contract === "string" || contract?.interface === undefined) {
|
162
162
|
// discard subject since it could potentially be a rejected promise
|
163
163
|
throw new HardhatError(
|
164
|
-
HardhatError.ERRORS.CHAI_MATCHERS.FIRST_ARGUMENT_MUST_BE_A_CONTRACT,
|
164
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.FIRST_ARGUMENT_MUST_BE_A_CONTRACT,
|
165
165
|
);
|
166
166
|
}
|
167
167
|
|
168
168
|
// validate custom error name
|
169
169
|
if (typeof expectedCustomErrorName !== "string") {
|
170
170
|
throw new HardhatError(
|
171
|
-
HardhatError.ERRORS.CHAI_MATCHERS.STRING_EXPECTED_AS_CUSTOM_ERROR_NAME,
|
171
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.STRING_EXPECTED_AS_CUSTOM_ERROR_NAME,
|
172
172
|
);
|
173
173
|
}
|
174
174
|
|
@@ -178,7 +178,7 @@ function validateInput(
|
|
178
178
|
// check that interface contains the given custom error
|
179
179
|
if (expectedCustomError === null) {
|
180
180
|
throw new HardhatError(
|
181
|
-
HardhatError.ERRORS.CHAI_MATCHERS.CONTRACT_DOES_NOT_HAVE_CUSTOM_ERROR,
|
181
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.CONTRACT_DOES_NOT_HAVE_CUSTOM_ERROR,
|
182
182
|
{
|
183
183
|
customErrorName: expectedCustomErrorName,
|
184
184
|
},
|
@@ -187,7 +187,7 @@ function validateInput(
|
|
187
187
|
|
188
188
|
if (args.length > 0) {
|
189
189
|
throw new HardhatError(
|
190
|
-
HardhatError.ERRORS.CHAI_MATCHERS.REVERT_INVALID_ARGUMENTS_LENGTH,
|
190
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.REVERT_INVALID_ARGUMENTS_LENGTH,
|
191
191
|
);
|
192
192
|
}
|
193
193
|
|
@@ -215,7 +215,7 @@ export async function revertedWithCustomErrorWithArgs(
|
|
215
215
|
|
216
216
|
if (customErrorAssertionData === undefined) {
|
217
217
|
throw new HardhatError(
|
218
|
-
HardhatError.ERRORS.CHAI_MATCHERS.WITH_ARGS_FORBIDDEN,
|
218
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.WITH_ARGS_FORBIDDEN,
|
219
219
|
);
|
220
220
|
}
|
221
221
|
|
@@ -30,7 +30,7 @@ export function supportRevertedWithPanic(
|
|
30
30
|
Promise.resolve(this._obj).catch(() => {});
|
31
31
|
|
32
32
|
throw new HardhatError(
|
33
|
-
HardhatError.ERRORS.CHAI_MATCHERS.PANIC_CODE_EXPECTED,
|
33
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.PANIC_CODE_EXPECTED,
|
34
34
|
{
|
35
35
|
panicCode: expectedCodeArg,
|
36
36
|
},
|
@@ -78,11 +78,14 @@ export function decodeReturnData(returnData: string): DecodedReturnData {
|
|
78
78
|
} catch (e) {
|
79
79
|
ensureError(e);
|
80
80
|
|
81
|
-
throw new HardhatError(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
throw new HardhatError(
|
82
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.DECODING_ERROR,
|
83
|
+
{
|
84
|
+
encodedData: encodedReason,
|
85
|
+
type: "string",
|
86
|
+
reason: e.message,
|
87
|
+
},
|
88
|
+
);
|
86
89
|
}
|
87
90
|
|
88
91
|
return {
|
@@ -97,11 +100,14 @@ export function decodeReturnData(returnData: string): DecodedReturnData {
|
|
97
100
|
} catch (e) {
|
98
101
|
ensureError(e);
|
99
102
|
|
100
|
-
throw new HardhatError(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
throw new HardhatError(
|
104
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.DECODING_ERROR,
|
105
|
+
{
|
106
|
+
encodedData: encodedReason,
|
107
|
+
type: "uint256",
|
108
|
+
reason: e.message,
|
109
|
+
},
|
110
|
+
);
|
105
111
|
}
|
106
112
|
|
107
113
|
const description = panicErrorCodeToReason(code) ?? "unknown panic code";
|
@@ -105,7 +105,7 @@ function validateInput(
|
|
105
105
|
try {
|
106
106
|
if (Boolean(this.__flags.negate)) {
|
107
107
|
throw new HardhatError(
|
108
|
-
HardhatError.ERRORS.CHAI_MATCHERS.WITH_ARGS_CANNOT_BE_COMBINED_WITH_NOT,
|
108
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.WITH_ARGS_CANNOT_BE_COMBINED_WITH_NOT,
|
109
109
|
);
|
110
110
|
}
|
111
111
|
|
@@ -116,13 +116,13 @@ function validateInput(
|
|
116
116
|
|
117
117
|
if (!emitCalled && !revertedWithCustomErrorCalled) {
|
118
118
|
throw new HardhatError(
|
119
|
-
HardhatError.ERRORS.CHAI_MATCHERS.WITH_ARGS_WRONG_COMBINATION,
|
119
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.WITH_ARGS_WRONG_COMBINATION,
|
120
120
|
);
|
121
121
|
}
|
122
122
|
|
123
123
|
if (emitCalled && revertedWithCustomErrorCalled) {
|
124
124
|
throw new HardhatError(
|
125
|
-
HardhatError.ERRORS.CHAI_MATCHERS.WITH_ARGS_COMBINED_WITH_INCOMPATIBLE_ASSERTIONS,
|
125
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.WITH_ARGS_COMBINED_WITH_INCOMPATIBLE_ASSERTIONS,
|
126
126
|
);
|
127
127
|
}
|
128
128
|
|
@@ -119,7 +119,7 @@ function innerAssertArgEqual(
|
|
119
119
|
if (actualArg.hash !== undefined && actualArg._isIndexed === true) {
|
120
120
|
if (assertionType !== "event") {
|
121
121
|
throw new HardhatError(
|
122
|
-
HardhatError.ERRORS.CHAI_MATCHERS.INDEXED_EVENT_FORBIDDEN,
|
122
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.INDEXED_EVENT_FORBIDDEN,
|
123
123
|
);
|
124
124
|
}
|
125
125
|
|
@@ -1,8 +1,7 @@
|
|
1
|
+
import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
1
2
|
import type { Addressable } from "ethers";
|
2
|
-
import type { EthereumProvider } from "hardhat/types/providers";
|
3
3
|
|
4
4
|
import { toBigInt } from "@nomicfoundation/hardhat-utils/bigint";
|
5
|
-
import { numberToHexString } from "@nomicfoundation/hardhat-utils/hex";
|
6
5
|
|
7
6
|
import { getAddressOf } from "./account.js";
|
8
7
|
import { assertCanBeConvertedToBigint } from "./asserts.js";
|
@@ -18,19 +17,15 @@ export function getAddresses(
|
|
18
17
|
}
|
19
18
|
|
20
19
|
export async function getBalances(
|
21
|
-
|
20
|
+
ethers: HardhatEthers,
|
22
21
|
accounts: Array<Addressable | string>,
|
23
|
-
blockNumber
|
22
|
+
blockNumber: number,
|
24
23
|
): Promise<bigint[]> {
|
25
24
|
return Promise.all(
|
26
25
|
accounts.map(async (account) => {
|
27
26
|
const address = await getAddressOf(account);
|
28
27
|
|
29
|
-
const result = await provider.
|
30
|
-
method: "eth_getBalance",
|
31
|
-
params: [address, numberToHexString(blockNumber ?? 0)],
|
32
|
-
});
|
33
|
-
|
28
|
+
const result = await ethers.provider.getBalance(address, blockNumber);
|
34
29
|
assertCanBeConvertedToBigint(result);
|
35
30
|
|
36
31
|
return toBigInt(result);
|
@@ -28,7 +28,7 @@ export function buildAssert(negated: boolean, ssfi: Ssfi) {
|
|
28
28
|
if (!negated && !condition) {
|
29
29
|
if (messageFalse === undefined) {
|
30
30
|
throw new HardhatError(
|
31
|
-
HardhatError.ERRORS.CHAI_MATCHERS.ASSERTION_WITHOUT_ERROR_MESSAGE,
|
31
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.ASSERTION_WITHOUT_ERROR_MESSAGE,
|
32
32
|
);
|
33
33
|
}
|
34
34
|
|
@@ -41,7 +41,7 @@ export function buildAssert(negated: boolean, ssfi: Ssfi) {
|
|
41
41
|
if (negated && condition) {
|
42
42
|
if (messageTrue === undefined) {
|
43
43
|
throw new HardhatError(
|
44
|
-
HardhatError.ERRORS.CHAI_MATCHERS.ASSERTION_WITHOUT_ERROR_MESSAGE,
|
44
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.ASSERTION_WITHOUT_ERROR_MESSAGE,
|
45
45
|
);
|
46
46
|
}
|
47
47
|
|
@@ -24,7 +24,7 @@ export function preventAsyncMatcherChaining(
|
|
24
24
|
}
|
25
25
|
|
26
26
|
throw new HardhatError(
|
27
|
-
HardhatError.ERRORS.CHAI_MATCHERS.MATCHER_CANNOT_BE_CHAINED_AFTER,
|
27
|
+
HardhatError.ERRORS.CHAI_MATCHERS.GENERAL.MATCHER_CANNOT_BE_CHAINED_AFTER,
|
28
28
|
{
|
29
29
|
matcher: matcherName,
|
30
30
|
previousMatcher: previousMatcherName,
|