@@ -18,11 +18,6 @@ describe("hardhat-typechain", () => {
18
18
19
19
before ( async ( ) => {
20
20
await remove ( `${ process . cwd ( ) } /types` ) ;
21
- } ) ;
22
-
23
- it ( "should generate the types" , async ( ) => {
24
- // Check that the types are generated with the expected addition of the "/index.js" extensions
25
- // and the v3 modules
26
21
27
22
const hardhatConfig = await import (
28
23
// eslint-disable-next-line import/no-relative-packages -- allow for fixture projects
@@ -36,6 +31,11 @@ describe("hardhat-typechain", () => {
36
31
await hre . tasks . getTask ( "clean" ) . run ( ) ;
37
32
38
33
await hre . tasks . getTask ( "compile" ) . run ( ) ;
34
+ } ) ;
35
+
36
+ it ( "should generate the types for the `hardhat.d.ts` file" , async ( ) => {
37
+ // Check that the types are generated with the expected addition of the "/index.js" extensions
38
+ // and the v3 modules
39
39
40
40
const content = await readUtf8File (
41
41
path . join ( process . cwd ( ) , "types" , "ethers-contracts" , "hardhat.d.ts" ) ,
@@ -63,12 +63,28 @@ describe("hardhat-typechain", () => {
63
63
64
64
// The import from a npm package should have ".js" extensions
65
65
assert . equal ( content . includes ( `import { ethers } from 'ethers'` ) , true ) ;
66
+ } ) ;
66
67
67
- // Check that the types for the contract are generated
68
- assert . equal (
69
- await exists (
70
- `${ process . cwd ( ) } /types/ethers-contracts/factories/A__factory.ts` ,
68
+ it ( "should generated types for the contracts and add the support for the `attach` method" , async ( ) => {
69
+ const content = await readUtf8File (
70
+ path . join (
71
+ process . cwd ( ) ,
72
+ "types" ,
73
+ "ethers-contracts" ,
74
+ "factories" ,
75
+ "A__factory.ts" ,
71
76
) ,
77
+ ) ;
78
+
79
+ // The "Addressable" type should be imported
80
+ assert . equal (
81
+ content . includes ( `import type { Addressable } from "ethers";` ) ,
82
+ true ,
83
+ ) ;
84
+
85
+ // The "attach" method should be added to the factory
86
+ assert . equal (
87
+ content . includes ( `override attach(address: string | Addressable): A {` ) ,
72
88
true ,
73
89
) ;
74
90
} ) ;
0 commit comments