Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit ae4aa9b

Browse files
author
fannyguthmann
committed
added comments to src/transaction/deploy_account.rs
1 parent 120e55a commit ae4aa9b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/transaction/deploy_account.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ use cairo_vm::felt::Felt252;
3535
use getset::Getters;
3636
use num_traits::Zero;
3737

38+
/// Struct representing the state selector, containing contract addresses and class hashes.
3839
#[derive(Clone, Debug, PartialEq, Eq)]
3940
pub struct StateSelector {
4041
pub contract_addresses: Vec<Address>,
4142
pub class_hashes: Vec<ClassHash>,
4243
}
43-
44+
/// Struct representing the deploy account, containing various fields related to the deployment.
4445
#[derive(Clone, Debug, Getters)]
4546
pub struct DeployAccount {
4647
#[getset(get = "pub")]
@@ -65,6 +66,7 @@ pub struct DeployAccount {
6566

6667
impl DeployAccount {
6768
#[allow(clippy::too_many_arguments)]
69+
/// Constructor creatte a new DeployAccount.
6870
pub fn new(
6971
class_hash: ClassHash,
7072
max_fee: u128,
@@ -109,6 +111,7 @@ impl DeployAccount {
109111
})
110112
}
111113

114+
/// Creates a new L1Handler instance with a specified transaction hash.
112115
#[allow(clippy::too_many_arguments)]
113116
pub fn new_with_tx_hash(
114117
class_hash: ClassHash,
@@ -143,13 +146,15 @@ impl DeployAccount {
143146
})
144147
}
145148

149+
/// Get the state selector based on the contract address and class hash.
146150
pub fn get_state_selector(&self, _block_context: BlockContext) -> StateSelector {
147151
StateSelector {
148152
contract_addresses: vec![self.contract_address.clone()],
149153
class_hashes: vec![self.class_hash],
150154
}
151155
}
152156

157+
/// Execute a deployment transaction.
153158
pub fn execute<S: StateReader>(
154159
&self,
155160
state: &mut CachedState<S>,
@@ -174,6 +179,7 @@ impl DeployAccount {
174179
Ok(tx_info)
175180
}
176181

182+
/// Check if the constructor entry points are empty.
177183
fn constructor_entry_points_empty(
178184
&self,
179185
contract_class: CompiledClass,
@@ -228,6 +234,7 @@ impl DeployAccount {
228234
))
229235
}
230236

237+
/// Handles the constructor of a contract, executes it if necessary.
231238
pub fn handle_constructor<S: StateReader>(
232239
&self,
233240
contract_class: CompiledClass,
@@ -250,6 +257,7 @@ impl DeployAccount {
250257
}
251258
}
252259

260+
/// Handles the nonce of a transaction, verifies if it is valid.
253261
fn handle_nonce<S: State + StateReader>(&self, state: &mut S) -> Result<(), TransactionError> {
254262
if self.version.is_zero() || self.version == *QUERY_VERSION_BASE {
255263
return Ok(());
@@ -267,6 +275,7 @@ impl DeployAccount {
267275
Ok(())
268276
}
269277

278+
/// Executes the constructor entry point.
270279
pub fn run_constructor_entrypoint<S: StateReader>(
271280
&self,
272281
state: &mut CachedState<S>,
@@ -302,6 +311,7 @@ impl DeployAccount {
302311
Ok(call_info)
303312
}
304313

314+
/// Get the transaction execution context.
305315
pub fn get_execution_context(&self, n_steps: u64) -> TransactionExecutionContext {
306316
TransactionExecutionContext::new(
307317
self.contract_address.clone(),
@@ -314,6 +324,7 @@ impl DeployAccount {
314324
)
315325
}
316326

327+
/// Executes a validation entry point for a contract.
317328
pub fn run_validate_entrypoint<S: StateReader>(
318329
&self,
319330
state: &mut CachedState<S>,
@@ -360,6 +371,7 @@ impl DeployAccount {
360371
Ok(call_info)
361372
}
362373

374+
/// Creates a transaction for simulation.
363375
pub(crate) fn create_for_simulation(
364376
&self,
365377
skip_validate: bool,
@@ -397,6 +409,7 @@ mod tests {
397409
utils::felt_to_hash,
398410
};
399411

412+
/// Tests that for a given contract we get the correct state selector.
400413
#[test]
401414
fn get_state_selector() {
402415
let path = PathBuf::from("starknet_programs/constructor.json");
@@ -433,6 +446,7 @@ mod tests {
433446
assert_eq!(state_selector.class_hashes, vec![class_hash]);
434447
}
435448

449+
/// Tests that deploying the same contract twice should fail with a ContractAddressUnavailable error.
436450
#[test]
437451
fn deploy_account_twice_should_fail() {
438452
let path = PathBuf::from("starknet_programs/constructor.json");
@@ -483,6 +497,7 @@ mod tests {
483497
)
484498
}
485499

500+
/// Tests that deploying an account without calldata for the constructor should panic.
486501
#[test]
487502
#[should_panic]
488503
// Should panic at no calldata for constructor. Error managment not implemented yet.

0 commit comments

Comments
 (0)