@@ -35,12 +35,13 @@ use cairo_vm::felt::Felt252;
35
35
use getset:: Getters ;
36
36
use num_traits:: Zero ;
37
37
38
+ /// Struct representing the state selector, containing contract addresses and class hashes.
38
39
#[ derive( Clone , Debug , PartialEq , Eq ) ]
39
40
pub struct StateSelector {
40
41
pub contract_addresses : Vec < Address > ,
41
42
pub class_hashes : Vec < ClassHash > ,
42
43
}
43
-
44
+ /// Struct representing the deploy account, containing various fields related to the deployment.
44
45
#[ derive( Clone , Debug , Getters ) ]
45
46
pub struct DeployAccount {
46
47
#[ getset( get = "pub" ) ]
@@ -65,6 +66,7 @@ pub struct DeployAccount {
65
66
66
67
impl DeployAccount {
67
68
#[ allow( clippy:: too_many_arguments) ]
69
+ /// Constructor creatte a new DeployAccount.
68
70
pub fn new (
69
71
class_hash : ClassHash ,
70
72
max_fee : u128 ,
@@ -109,6 +111,7 @@ impl DeployAccount {
109
111
} )
110
112
}
111
113
114
+ /// Creates a new L1Handler instance with a specified transaction hash.
112
115
#[ allow( clippy:: too_many_arguments) ]
113
116
pub fn new_with_tx_hash (
114
117
class_hash : ClassHash ,
@@ -143,13 +146,15 @@ impl DeployAccount {
143
146
} )
144
147
}
145
148
149
+ /// Get the state selector based on the contract address and class hash.
146
150
pub fn get_state_selector ( & self , _block_context : BlockContext ) -> StateSelector {
147
151
StateSelector {
148
152
contract_addresses : vec ! [ self . contract_address. clone( ) ] ,
149
153
class_hashes : vec ! [ self . class_hash] ,
150
154
}
151
155
}
152
156
157
+ /// Execute a deployment transaction.
153
158
pub fn execute < S : StateReader > (
154
159
& self ,
155
160
state : & mut CachedState < S > ,
@@ -174,6 +179,7 @@ impl DeployAccount {
174
179
Ok ( tx_info)
175
180
}
176
181
182
+ /// Check if the constructor entry points are empty.
177
183
fn constructor_entry_points_empty (
178
184
& self ,
179
185
contract_class : CompiledClass ,
@@ -228,6 +234,7 @@ impl DeployAccount {
228
234
) )
229
235
}
230
236
237
+ /// Handles the constructor of a contract, executes it if necessary.
231
238
pub fn handle_constructor < S : StateReader > (
232
239
& self ,
233
240
contract_class : CompiledClass ,
@@ -250,6 +257,7 @@ impl DeployAccount {
250
257
}
251
258
}
252
259
260
+ /// Handles the nonce of a transaction, verifies if it is valid.
253
261
fn handle_nonce < S : State + StateReader > ( & self , state : & mut S ) -> Result < ( ) , TransactionError > {
254
262
if self . version . is_zero ( ) || self . version == * QUERY_VERSION_BASE {
255
263
return Ok ( ( ) ) ;
@@ -267,6 +275,7 @@ impl DeployAccount {
267
275
Ok ( ( ) )
268
276
}
269
277
278
+ /// Executes the constructor entry point.
270
279
pub fn run_constructor_entrypoint < S : StateReader > (
271
280
& self ,
272
281
state : & mut CachedState < S > ,
@@ -302,6 +311,7 @@ impl DeployAccount {
302
311
Ok ( call_info)
303
312
}
304
313
314
+ /// Get the transaction execution context.
305
315
pub fn get_execution_context ( & self , n_steps : u64 ) -> TransactionExecutionContext {
306
316
TransactionExecutionContext :: new (
307
317
self . contract_address . clone ( ) ,
@@ -314,6 +324,7 @@ impl DeployAccount {
314
324
)
315
325
}
316
326
327
+ /// Executes a validation entry point for a contract.
317
328
pub fn run_validate_entrypoint < S : StateReader > (
318
329
& self ,
319
330
state : & mut CachedState < S > ,
@@ -360,6 +371,7 @@ impl DeployAccount {
360
371
Ok ( call_info)
361
372
}
362
373
374
+ /// Creates a transaction for simulation.
363
375
pub ( crate ) fn create_for_simulation (
364
376
& self ,
365
377
skip_validate : bool ,
@@ -397,6 +409,7 @@ mod tests {
397
409
utils:: felt_to_hash,
398
410
} ;
399
411
412
+ /// Tests that for a given contract we get the correct state selector.
400
413
#[ test]
401
414
fn get_state_selector ( ) {
402
415
let path = PathBuf :: from ( "starknet_programs/constructor.json" ) ;
@@ -433,6 +446,7 @@ mod tests {
433
446
assert_eq ! ( state_selector. class_hashes, vec![ class_hash] ) ;
434
447
}
435
448
449
+ /// Tests that deploying the same contract twice should fail with a ContractAddressUnavailable error.
436
450
#[ test]
437
451
fn deploy_account_twice_should_fail ( ) {
438
452
let path = PathBuf :: from ( "starknet_programs/constructor.json" ) ;
@@ -483,6 +497,7 @@ mod tests {
483
497
)
484
498
}
485
499
500
+ /// Tests that deploying an account without calldata for the constructor should panic.
486
501
#[ test]
487
502
#[ should_panic]
488
503
// Should panic at no calldata for constructor. Error managment not implemented yet.
0 commit comments