Skip to content

Commit 8d27358

Browse files
committed
some adjustments
1 parent cdab64a commit 8d27358

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

packages/hardhat-chai-matchers/src/internal/emit.ts

+7-18
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,11 @@ function assertArgsArraysEqual(
166166
actualArgs.length === expectedArgs.length,
167167
`Expected "${eventName}" event to have ${expectedArgs.length} argument(s), but it has ${actualArgs.length}`
168168
);
169-
for (const index in expectedArgs) {
170-
const expectedArg = expectedArgs[index];
169+
for (const [index, expectedArg] of expectedArgs.entries()) {
171170
const actualArg = actualArgs[index];
172171
if (typeof expectedArg === "function") {
173172
const errorPrefix = `The predicate for the ${ordinal(
174-
parseInt(index) + 1
173+
index + 1
175174
)} event argument`;
176175
try {
177176
if (expectedArg(actualArg) === true) continue;
@@ -185,7 +184,7 @@ function assertArgsArraysEqual(
185184
}
186185
assert(
187186
false,
188-
`${errorPrefix} returned false`
187+
`${errorPrefix} did not return true `
189188
// no need for a negated message, since we disallow mixing .not. with
190189
// .withArgs
191190
);
@@ -202,7 +201,7 @@ function assertArgsArraysEqual(
202201
assert(
203202
expectedLength === actualLength,
204203
`Expected the ${ordinal(
205-
parseInt(index) + 1
204+
index + 1
206205
)} argument of the "${eventName}" event to have ${expectedLength} ${
207206
expectedLength === 1 ? "element" : "elements"
208207
}, but it has ${actualLength}`
@@ -214,16 +213,8 @@ function assertArgsArraysEqual(
214213
);
215214
}
216215
} else {
217-
if (
218-
actualArg.hash !== undefined &&
219-
actualArg._isIndexed === true
220-
) {
221-
new Assertion(
222-
actualArg.hash,
223-
undefined,
224-
ssfi,
225-
true
226-
).to.not.equal(
216+
if (actualArg.hash !== undefined && actualArg._isIndexed === true) {
217+
new Assertion(actualArg.hash, undefined, ssfi, true).to.not.equal(
227218
expectedArg,
228219
"The actual value was an indexed and hashed value of the event argument. The expected value provided to the assertion should be the actual event argument (the pre-image of the hash). You provided the hash itself. Please supply the actual event argument (the pre-image of the hash) instead."
229220
);
@@ -236,9 +227,7 @@ function assertArgsArraysEqual(
236227
`The actual value was an indexed and hashed value of the event argument. The expected value provided to the assertion was hashed to produce ${expectedHash}. The actual hash and the expected hash did not match`
237228
);
238229
} else {
239-
new Assertion(actualArg, undefined, ssfi, true).equal(
240-
expectedArg
241-
);
230+
new Assertion(actualArg, undefined, ssfi, true).equal(expectedArg);
242231
}
243232
}
244233
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ describe(".to.emit (contract events)", () => {
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();
2929
});
3030

3131
function runTests() {
3232
beforeEach(async function () {
33-
otherContract = await (
34-
await this.hre.ethers.getContractFactory("AnotherContract")
35-
).deploy();
33+
otherContract = await this.hre.ethers.deployContract("AnotherContract");
3634

3735
contract = await (
3836
await this.hre.ethers.getContractFactory<[string], EventsContract>(
@@ -66,7 +64,9 @@ describe(".to.emit (contract events)", () => {
6664
});
6765

6866
it("Should detect events without arguments", async function () {
69-
await expect(contract.emitWithoutArgs()).to.emit(contract, "WithoutArgs");
67+
await expect(contract.emitWithoutArgs())
68+
.to.emit(contract, "WithoutArgs")
69+
.withArgs();
7070
});
7171

7272
it("Should fail when expecting an event that wasn't emitted", async function () {
@@ -538,7 +538,7 @@ describe(".to.emit (contract events)", () => {
538538
.withArgs(1, () => false)
539539
).to.be.eventually.rejectedWith(
540540
AssertionError,
541-
"The predicate for the 2nd event argument returned false"
541+
"The predicate for the 2nd event argument did not return true"
542542
);
543543
});
544544

0 commit comments

Comments
 (0)