@@ -9,7 +9,9 @@ use anvil::{spawn, NodeConfig};
99use foundry_compilers:: artifacts:: { remappings:: Remapping , BytecodeHash } ;
1010use foundry_config:: Config ;
1111use foundry_test_utils:: {
12- forgetest, forgetest_async, str,
12+ forgetest, forgetest_async,
13+ snapbox:: IntoData ,
14+ str,
1315 util:: { OutputExt , TestCommand , TestProject } ,
1416} ;
1517use std:: str:: FromStr ;
@@ -145,6 +147,7 @@ forgetest_async!(can_create_template_contract, |prj, cmd| {
145147 let config = Config { bytecode_hash: BytecodeHash :: None , ..Default :: default ( ) } ;
146148 prj. write_config( config) ;
147149
150+ // Dry-run without the `--broadcast` flag
148151 cmd. forge_fuse( ) . args( [
149152 "create" ,
150153 format!( "./src/{TEMPLATE_CONTRACT}.sol:{TEMPLATE_CONTRACT}" ) . as_str( ) ,
@@ -154,20 +157,131 @@ forgetest_async!(can_create_template_contract, |prj, cmd| {
154157 pk. as_str( ) ,
155158 ] ) ;
156159
160+ // Dry-run
157161 cmd. assert( ) . stdout_eq( str ![ [ r#"
158162[COMPILING_FILES] with [SOLC_VERSION]
159163[SOLC_VERSION] [ELAPSED]
160164Compiler run successful!
161- Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
162- Deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
163- [TX_HASH]
165+ Contract: Counter
166+ Transaction: {
167+ "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
168+ "to": null,
169+ "maxFeePerGas": "0x77359401",
170+ "maxPriorityFeePerGas": "0x1",
171+ "gas": "0x17575",
172+ "input": "[..]",
173+ "nonce": "0x0",
174+ "chainId": "0x7a69"
175+ }
176+ ABI: [
177+ {
178+ "type": "function",
179+ "name": "increment",
180+ "inputs": [],
181+ "outputs": [],
182+ "stateMutability": "nonpayable"
183+ },
184+ {
185+ "type": "function",
186+ "name": "number",
187+ "inputs": [],
188+ "outputs": [
189+ {
190+ "name": "",
191+ "type": "uint256",
192+ "internalType": "uint256"
193+ }
194+ ],
195+ "stateMutability": "view"
196+ },
197+ {
198+ "type": "function",
199+ "name": "setNumber",
200+ "inputs": [
201+ {
202+ "name": "newNumber",
203+ "type": "uint256",
204+ "internalType": "uint256"
205+ }
206+ ],
207+ "outputs": [],
208+ "stateMutability": "nonpayable"
209+ }
210+ ]
211+
164212
165213"# ] ] ) ;
166214
215+ // Dry-run with `--json` flag
216+ cmd. arg( "--json" ) . assert( ) . stdout_eq(
217+ str ![ [ r#"
218+ {
219+ "contract": "Counter",
220+ "transaction": {
221+ "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
222+ "to": null,
223+ "maxFeePerGas": "0x77359401",
224+ "maxPriorityFeePerGas": "0x1",
225+ "gas": "0x17575",
226+ "input": "[..]",
227+ "nonce": "0x0",
228+ "chainId": "0x7a69"
229+ },
230+ "abi": [
231+ {
232+ "type": "function",
233+ "name": "increment",
234+ "inputs": [],
235+ "outputs": [],
236+ "stateMutability": "nonpayable"
237+ },
238+ {
239+ "type": "function",
240+ "name": "number",
241+ "inputs": [],
242+ "outputs": [
243+ {
244+ "name": "",
245+ "type": "uint256",
246+ "internalType": "uint256"
247+ }
248+ ],
249+ "stateMutability": "view"
250+ },
251+ {
252+ "type": "function",
253+ "name": "setNumber",
254+ "inputs": [
255+ {
256+ "name": "newNumber",
257+ "type": "uint256",
258+ "internalType": "uint256"
259+ }
260+ ],
261+ "outputs": [],
262+ "stateMutability": "nonpayable"
263+ }
264+ ]
265+ }
266+
267+ "# ] ]
268+ . is_json( ) ,
269+ ) ;
270+
271+ cmd. forge_fuse( ) . args( [
272+ "create" ,
273+ format!( "./src/{TEMPLATE_CONTRACT}.sol:{TEMPLATE_CONTRACT}" ) . as_str( ) ,
274+ "--rpc-url" ,
275+ rpc. as_str( ) ,
276+ "--private-key" ,
277+ pk. as_str( ) ,
278+ "--broadcast" ,
279+ ] ) ;
280+
167281 cmd. assert( ) . stdout_eq( str ![ [ r#"
168282No files changed, compilation skipped
169283Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
170- Deployed to: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
284+ Deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
171285[TX_HASH]
172286
173287"# ] ] ) ;
@@ -193,6 +307,7 @@ forgetest_async!(can_create_using_unlocked, |prj, cmd| {
193307 "--from" ,
194308 format!( "{dev:?}" ) . as_str( ) ,
195309 "--unlocked" ,
310+ "--broadcast" ,
196311 ] ) ;
197312
198313 cmd. assert( ) . stdout_eq( str ![ [ r#"
@@ -204,6 +319,7 @@ Deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
204319[TX_HASH]
205320
206321"# ] ] ) ;
322+
207323 cmd. assert( ) . stdout_eq( str ![ [ r#"
208324No files changed, compilation skipped
209325Deployer: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
@@ -248,6 +364,7 @@ contract ConstructorContract {
248364 rpc. as_str( ) ,
249365 "--private-key" ,
250366 pk. as_str( ) ,
367+ "--broadcast" ,
251368 "--constructor-args" ,
252369 "My Constructor" ,
253370 ] )
@@ -285,6 +402,7 @@ contract TupleArrayConstructorContract {
285402 rpc. as_str( ) ,
286403 "--private-key" ,
287404 pk. as_str( ) ,
405+ "--broadcast" ,
288406 "--constructor-args" ,
289407 "[(1,2), (2,3), (3,4)]" ,
290408 ] )
@@ -335,6 +453,7 @@ contract UniswapV2Swap {
335453 rpc. as_str( ) ,
336454 "--private-key" ,
337455 pk. as_str( ) ,
456+ "--broadcast" ,
338457 ] )
339458 . assert_success( )
340459 . stdout_eq( str ![ [ r#"
0 commit comments