Skip to content

Commit b9563a5

Browse files
committed
Fix rejecedWithCustomError tests, round 1
1 parent 58643e8 commit b9563a5

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

packages/hardhat-chai-matchers/test/events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe(".to.emit (contract events)", () => {
2222
runTests();
2323
});
2424

25-
describe.only("connected to a hardhat node", function () {
25+
describe("connected to a hardhat node", function () {
2626
useEnvironmentWithNode("hardhat-project");
2727

2828
runTests();

packages/hardhat-chai-matchers/test/reverted/revertedWithCustomError.ts

+51-43
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("INTEGRATION: Reverted with custom error", function () {
2222
runTests();
2323
});
2424

25-
describe("connected to a hardhat node", function () {
25+
describe.only("connected to a hardhat node", function () {
2626
useEnvironmentWithNode("hardhat-project");
2727

2828
runTests();
@@ -273,30 +273,34 @@ describe("INTEGRATION: Reverted with custom error", function () {
273273
).to.be.rejectedWith(Error, "user-defined error");
274274
});
275275

276-
it("should check the length of the args", async function () {
277-
await expect(
278-
expect(matchers.revertWithCustomErrorWithUintAndString(1, "s"))
279-
.to.be.revertedWithCustomError(
280-
matchers,
281-
"CustomErrorWithUintAndString"
282-
)
283-
.withArgs(1)
284-
).to.be.rejectedWith(
285-
AssertionError,
286-
'Expected "CustomErrorWithUintAndString" custom error to have 1 argument(s), but it has 2'
287-
);
276+
describe("different number of arguments", function () {
277+
it("Should reject if expected less arguments", async function () {
278+
await expect(
279+
expect(matchers.revertWithCustomErrorWithUintAndString(1, "s"))
280+
.to.be.revertedWithCustomError(
281+
matchers,
282+
"CustomErrorWithUintAndString"
283+
)
284+
.withArgs(1)
285+
).to.be.rejectedWith(
286+
AssertionError,
287+
'Error in "CustomErrorWithUintAndString" custom error: Expected arguments array to have length 1, but it has 2'
288+
);
289+
});
288290

289-
await expect(
290-
expect(matchers.revertWithCustomErrorWithUintAndString(1, "s"))
291-
.to.be.revertedWithCustomError(
292-
matchers,
293-
"CustomErrorWithUintAndString"
294-
)
295-
.withArgs(1, "s", 3)
296-
).to.be.rejectedWith(
297-
AssertionError,
298-
'Expected "CustomErrorWithUintAndString" custom error to have 3 argument(s), but it has 2'
299-
);
291+
it("Should reject if expected more arguments", async function () {
292+
await expect(
293+
expect(matchers.revertWithCustomErrorWithUintAndString(1, "s"))
294+
.to.be.revertedWithCustomError(
295+
matchers,
296+
"CustomErrorWithUintAndString"
297+
)
298+
.withArgs(1, "s", 3)
299+
).to.be.rejectedWith(
300+
AssertionError,
301+
'Error in "CustomErrorWithUintAndString" custom error: Expected arguments array to have length 3, but it has 2'
302+
);
303+
});
300304
});
301305

302306
describe("nested arguments", function () {
@@ -318,24 +322,28 @@ describe("INTEGRATION: Reverted with custom error", function () {
318322
});
319323
});
320324

321-
it("should fail when the arrays don't have the same length", async function () {
322-
await expect(
323-
expect(matchers.revertWithCustomErrorWithPair(1, 2))
324-
.to.be.revertedWithCustomError(matchers, "CustomErrorWithPair")
325-
.withArgs([1])
326-
).to.be.rejectedWith(
327-
AssertionError,
328-
'Expected the 1st argument of the "CustomErrorWithPair" custom error to have 1 element, but it has 2'
329-
);
325+
describe("array of different lengths", async function () {
326+
it("Should fail if the expected array is bigger", async function () {
327+
await expect(
328+
expect(matchers.revertWithCustomErrorWithPair(1, 2))
329+
.to.be.revertedWithCustomError(matchers, "CustomErrorWithPair")
330+
.withArgs([1])
331+
).to.be.rejectedWith(
332+
AssertionError,
333+
'Error in "CustomErrorWithPair" custom error: Error in the 1st argument assertion: Expected arguments array to have length 1, but it has 2'
334+
);
335+
});
330336

331-
await expect(
332-
expect(matchers.revertWithCustomErrorWithPair(1, 2))
333-
.to.be.revertedWithCustomError(matchers, "CustomErrorWithPair")
334-
.withArgs([1, 2, 3])
335-
).to.be.rejectedWith(
336-
AssertionError,
337-
'Expected the 1st argument of the "CustomErrorWithPair" custom error to have 3 elements, but it has 2'
338-
);
337+
it("Should fail if the expected array is smaller", async function () {
338+
await expect(
339+
expect(matchers.revertWithCustomErrorWithPair(1, 2))
340+
.to.be.revertedWithCustomError(matchers, "CustomErrorWithPair")
341+
.withArgs([1, 2, 3])
342+
).to.be.rejectedWith(
343+
AssertionError,
344+
'Error in "CustomErrorWithPair" custom error: Error in the 1st argument assertion: Expected arguments array to have length 3, but it has 2'
345+
);
346+
});
339347
});
340348

341349
it("Should fail when used with .not.", async function () {
@@ -388,7 +396,7 @@ describe("INTEGRATION: Reverted with custom error", function () {
388396
.withArgs(() => false)
389397
).to.be.rejectedWith(
390398
AssertionError,
391-
"The predicate for the 1st custom error argument did not return true"
399+
'Error in "CustomErrorWithUint" custom error: Error in the 1st argument assertion: The predicate did not return true'
392400
);
393401
});
394402

@@ -399,7 +407,7 @@ describe("INTEGRATION: Reverted with custom error", function () {
399407
.withArgs(anyUint)
400408
).to.be.rejectedWith(
401409
AssertionError,
402-
"The predicate for the 1st custom error argument threw when called: anyUint expected its argument to be an unsigned integer, but it was negative, with value -1"
410+
'Error in "CustomErrorWithInt" custom error: Error in the 1st argument assertion: The predicate threw when called: anyUint expected its argument to be an unsigned integer, but it was negative, with value -1'
403411
);
404412
});
405413
});

0 commit comments

Comments
 (0)