@@ -47,7 +47,7 @@ test.serial('erc20 full', async t => {
47
47
flashmint : true ,
48
48
} ;
49
49
const c = buildERC20 ( opts ) ;
50
- await runTest ( c , t , opts ) ;
50
+ await runIgnitionTest ( c , t , opts ) ;
51
51
} ) ;
52
52
53
53
test . serial ( 'erc721 upgradeable' , async t => {
@@ -58,7 +58,7 @@ test.serial('erc721 upgradeable', async t => {
58
58
upgradeable : 'uups' ,
59
59
} ;
60
60
const c = buildERC721 ( opts ) ;
61
- await runTest ( c , t , opts ) ;
61
+ await runDeployScriptTest ( c , t , opts ) ;
62
62
} ) ;
63
63
64
64
test . serial ( 'erc1155 basic' , async t => {
@@ -68,13 +68,13 @@ test.serial('erc1155 basic', async t => {
68
68
uri : 'https://myuri/{id}' ,
69
69
} ;
70
70
const c = buildERC1155 ( opts ) ;
71
- await runTest ( c , t , opts ) ;
71
+ await runIgnitionTest ( c , t , opts ) ;
72
72
} ) ;
73
73
74
74
test . serial ( 'custom basic' , async t => {
75
75
const opts : GenericOptions = { kind : 'Custom' , name : 'My Contract' } ;
76
76
const c = buildCustom ( opts ) ;
77
- await runTest ( c , t , opts ) ;
77
+ await runIgnitionTest ( c , t , opts ) ;
78
78
} ) ;
79
79
80
80
test . serial ( 'custom upgradeable' , async t => {
@@ -84,18 +84,26 @@ test.serial('custom upgradeable', async t => {
84
84
upgradeable : 'transparent' ,
85
85
} ;
86
86
const c = buildCustom ( opts ) ;
87
- await runTest ( c , t , opts ) ;
87
+ await runDeployScriptTest ( c , t , opts ) ;
88
88
} ) ;
89
89
90
- async function runTest ( c : Contract , t : ExecutionContext < Context > , opts : GenericOptions ) {
90
+ async function runDeployScriptTest ( c : Contract , t : ExecutionContext < Context > , opts : GenericOptions ) {
91
91
const zip = await zipHardhat ( c , opts ) ;
92
92
93
- assertLayout ( zip , c , t ) ;
94
- await extractAndRunPackage ( zip , c , t ) ;
95
- await assertContents ( zip , c , t ) ;
93
+ assertDeployScriptLayout ( zip , c , t ) ;
94
+ await extractAndRunDeployScriptPackage ( zip , c , t ) ;
95
+ await assertDeployScriptContents ( zip , c , t ) ;
96
96
}
97
97
98
- function assertLayout ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
98
+ async function runIgnitionTest ( c : Contract , t : ExecutionContext < Context > , opts : GenericOptions ) {
99
+ const zip = await zipHardhat ( c , opts ) ;
100
+
101
+ assertIgnitionLayout ( zip , c , t ) ;
102
+ await extractAndRunIgnitionPackage ( zip , c , t ) ;
103
+ await assertIgnitionContents ( zip , c , t ) ;
104
+ }
105
+
106
+ function assertDeployScriptLayout ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
99
107
const sorted = Object . values ( zip . files )
100
108
. map ( f => f . name )
101
109
. sort ( ) ;
@@ -115,36 +123,62 @@ function assertLayout(zip: JSZip, c: Contract, t: ExecutionContext<Context>) {
115
123
] ) ;
116
124
}
117
125
118
- async function extractAndRunPackage ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
119
- const files = Object . values ( zip . files ) ;
126
+ function assertIgnitionLayout ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
127
+ const sorted = Object . values ( zip . files )
128
+ . map ( f => f . name )
129
+ . sort ( ) ;
130
+ t . deepEqual ( sorted , [
131
+ '.gitignore' ,
132
+ 'README.md' ,
133
+ 'contracts/' ,
134
+ `contracts/${ c . name } .sol` ,
135
+ 'hardhat.config.ts' ,
136
+ 'ignition/' ,
137
+ 'ignition/modules/' ,
138
+ `ignition/modules/${ c . name } .ts` ,
139
+ 'package-lock.json' ,
140
+ 'package.json' ,
141
+ 'test/' ,
142
+ 'test/test.ts' ,
143
+ 'tsconfig.json' ,
144
+ ] ) ;
145
+ }
146
+
147
+ function extractAndRun ( makeDeployCommand : ( c : Contract ) => string | null ) {
148
+ return async ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) => {
149
+ const files = Object . values ( zip . files ) ;
120
150
121
- const tempFolder = t . context . tempFolder ;
151
+ const tempFolder = t . context . tempFolder ;
122
152
123
- const items = Object . values ( files ) ;
124
- for ( const item of items ) {
125
- if ( item . dir ) {
126
- await fs . mkdir ( path . join ( tempFolder , item . name ) ) ;
127
- } else {
128
- await fs . writeFile ( path . join ( tempFolder , item . name ) , await asString ( item ) ) ;
153
+ const items = Object . values ( files ) ;
154
+ for ( const item of items ) {
155
+ if ( item . dir ) {
156
+ await fs . mkdir ( path . join ( tempFolder , item . name ) ) ;
157
+ } else {
158
+ await fs . writeFile ( path . join ( tempFolder , item . name ) , await asString ( item ) ) ;
159
+ }
129
160
}
130
- }
131
161
132
- let command = `cd "${ tempFolder } " && npm install && npm test` ;
133
- if ( c . constructorArgs === undefined ) {
134
- // only test deploying the contract if there are no constructor args needed
135
- command += ' && npx hardhat run scripts/deploy.ts' ;
136
- }
162
+ let command = `cd "${ tempFolder } " && npm install && npm test` ;
163
+ if ( c . constructorArgs === undefined ) {
164
+ // only test deploying the contract if there are no constructor args needed
165
+ command += ` && ${ makeDeployCommand ( c ) } ` ;
166
+ }
137
167
138
- const exec = util . promisify ( child . exec ) ;
139
- const result = await exec ( command ) ;
168
+ const exec = util . promisify ( child . exec ) ;
169
+ const result = await exec ( command ) ;
140
170
141
- t . regex ( result . stdout , / 1 p a s s i n g / ) ;
142
- if ( c . constructorArgs === undefined ) {
143
- t . regex ( result . stdout , / d e p l o y e d t o / ) ;
144
- }
171
+ t . regex ( result . stdout , / 1 p a s s i n g / ) ;
172
+ if ( c . constructorArgs === undefined ) {
173
+ t . regex ( result . stdout , / d e p l o y e d t o / ) ;
174
+ }
175
+ } ;
145
176
}
146
177
147
- async function assertContents ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
178
+ const extractAndRunDeployScriptPackage = extractAndRun ( ( ) => 'npx hardhat run scripts/deploy.ts' ) ;
179
+ const extractAndRunIgnitionPackage = extractAndRun ( c => `npx hardhat ignition deploy ignition/modules/${ c . name } .ts` ) ;
180
+
181
+ async function assertDeployScriptContents ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
148
182
const contentComparison = [
149
183
await getItemString ( zip , `contracts/${ c . name } .sol` ) ,
150
184
await getItemString ( zip , 'hardhat.config.ts' ) ,
@@ -156,6 +190,18 @@ async function assertContents(zip: JSZip, c: Contract, t: ExecutionContext<Conte
156
190
t . snapshot ( contentComparison ) ;
157
191
}
158
192
193
+ async function assertIgnitionContents ( zip : JSZip , c : Contract , t : ExecutionContext < Context > ) {
194
+ const contentComparison = [
195
+ await getItemString ( zip , `contracts/${ c . name } .sol` ) ,
196
+ await getItemString ( zip , 'hardhat.config.ts' ) ,
197
+ await getItemString ( zip , 'package.json' ) ,
198
+ await getItemString ( zip , `ignition/modules/${ c . name } .ts` ) ,
199
+ await getItemString ( zip , 'test/test.ts' ) ,
200
+ ] ;
201
+
202
+ t . snapshot ( contentComparison ) ;
203
+ }
204
+
159
205
async function getItemString ( zip : JSZip , key : string ) {
160
206
const obj = zip . files [ key ] ;
161
207
if ( obj === undefined ) {
0 commit comments