Skip to content

Commit 6e93d14

Browse files
committed
fix dereference error
1 parent 062b898 commit 6e93d14

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { isAddress, isAddressable, Typed } from "ethers";
1+
import { isAddress, isAddressable } from "ethers";
2+
import { tryDereference } from "./typed";
23

34
export function supportAddressable(
45
Assertion: Chai.AssertionStatic,
@@ -26,7 +27,7 @@ function override(
2627
// so we are looking for a sync way of getting the address. If an address was recovered, it is returned as a string,
2728
// otherwise undefined is returned.
2829
function tryGetAddressSync(value: any): string | undefined {
29-
value = Typed.dereference(value, "address");
30+
value = tryDereference(value, "address");
3031
if (isAddress(value)) {
3132
return value;
3233
} else if (isAddressable(value)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Typed } from "ethers";
2+
3+
export function tryDereference(value: any, type: string) {
4+
try {
5+
return Typed.dereference(value, type);
6+
} catch {
7+
return undefined;
8+
}
9+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ describe("Addressable matcher", () => {
8181
}
8282

8383
it("should accept other typed objects", async function () {
84-
expect(2).to.equal(ethers.Typed.uint256(2));
84+
expect(() => {
85+
expect(2).to.equal(ethers.Typed.uint256(2));
86+
}).to.throw("expected 2 to equal");
8587
});
8688
});

0 commit comments

Comments
 (0)