Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/starknet_os/src/io/os_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ pub fn message_l1_from_output_iter<It: Iterator<Item = Felt>>(
// An L1 to L2 message header, the message payload is concatenated to the end of the header.
pub struct MessageToL2 {
// The L1 address of the contract sending the message.
pub(crate) from_address: EthAddress,
pub from_address: EthAddress,
// The L2 address of the contract receiving the message.
pub(crate) to_address: ContractAddress,
pub(crate) nonce: Nonce,
pub(crate) selector: EntryPointSelector,
pub(crate) payload: L1ToL2Payload,
pub to_address: ContractAddress,
pub nonce: Nonce,
pub selector: EntryPointSelector,
pub payload: L1ToL2Payload,
}

impl TryFromOutputIter for MessageToL2 {
Expand Down
30 changes: 23 additions & 7 deletions crates/starknet_os_flow_tests/src/initial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,28 @@ pub(crate) fn get_deploy_contract_tx_and_address(
nonce: Nonce,
resource_bounds: ValidResourceBounds,
) -> (Transaction, ContractAddress) {
let contract_address_salt = Felt::ONE;
let (deploy_contract_tx, contract_address) = get_deploy_contract_tx_and_address_with_salt(
class_hash,
ctor_calldata,
nonce,
resource_bounds,
Felt::ONE,
);
(
Transaction::new_for_sequencing(StarknetAPITransaction::Account(
AccountTransaction::Invoke(deploy_contract_tx),
)),
contract_address,
)
}

pub(crate) fn get_deploy_contract_tx_and_address_with_salt(
class_hash: ClassHash,
ctor_calldata: Calldata,
nonce: Nonce,
resource_bounds: ValidResourceBounds,
contract_address_salt: Felt,
) -> (InvokeTransaction, ContractAddress) {
let calldata = [class_hash.0, contract_address_salt, ctor_calldata.0.len().into()]
.iter()
.chain(ctor_calldata.0.iter())
Expand Down Expand Up @@ -329,12 +350,7 @@ pub(crate) fn get_deploy_contract_tx_and_address(
*FUNDED_ACCOUNT_ADDRESS,
)
.unwrap();
(
Transaction::new_for_sequencing(StarknetAPITransaction::Account(
AccountTransaction::Invoke(deploy_contract_tx),
)),
contract_address,
)
(deploy_contract_tx, contract_address)
}

pub(crate) fn get_deploy_fee_token_tx_and_address(nonce: Nonce) -> (Transaction, ContractAddress) {
Expand Down
25 changes: 18 additions & 7 deletions crates/starknet_os_flow_tests/src/test_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ impl<S: FlowTestState> TestManager<S> {
self.per_block_transactions.push(vec![]);
}

pub(crate) fn total_txs(&self) -> usize {
self.per_block_transactions.iter().map(|block| block.len()).sum()
}

fn last_block_txs_mut(&mut self) -> &mut Vec<FlowTestTx> {
self.per_block_transactions
.last_mut()
Expand Down Expand Up @@ -441,22 +445,29 @@ impl<S: FlowTestState> TestManager<S> {

/// Verifies all the execution outputs are as expected w.r.t. revert reasons.
fn verify_execution_outputs(
block_index: usize,
revert_reasons: &[Option<String>],
execution_outputs: &[(TransactionExecutionInfo, StateMaps)],
) {
assert_eq!(revert_reasons.len(), execution_outputs.len());
for (revert_reason, (execution_info, _)) in
revert_reasons.iter().zip(execution_outputs.iter())
for ((i, revert_reason), (execution_info, _)) in
revert_reasons.iter().enumerate().zip(execution_outputs.iter())
{
let preamble = format!("Block {block_index}, transaction {i}:");
if let Some(revert_reason) = revert_reason {
let actual_revert_reason =
execution_info.revert_error.as_ref().unwrap().to_string();
assert!(
actual_revert_reason.contains(revert_reason),
"Expected '{revert_reason}' to be in revert string:\n'{actual_revert_reason}'"
"{preamble} Expected '{revert_reason}' to be in revert \
string:\n'{actual_revert_reason}'"
);
} else {
assert!(execution_info.revert_error.is_none());
assert!(
execution_info.revert_error.is_none(),
"{preamble} Expected no revert error, got: {}.",
execution_info.revert_error.as_ref().unwrap()
);
}
}
}
Expand Down Expand Up @@ -520,8 +531,8 @@ impl<S: FlowTestState> TestManager<S> {
"use_kzg_da flag in block contexts must match the test parameter."
);
let mut alias_keys = HashSet::new();
for (block_txs_with_reason, block_context) in
per_block_txs.into_iter().zip(block_contexts.into_iter())
for ((block_index, block_txs_with_reason), block_context) in
per_block_txs.into_iter().enumerate().zip(block_contexts.into_iter())
{
let (block_txs, revert_reasons): (Vec<_>, Vec<_>) = block_txs_with_reason
.into_iter()
Expand All @@ -532,7 +543,7 @@ impl<S: FlowTestState> TestManager<S> {
// Execute the transactions.
let ExecutionOutput { execution_outputs, block_summary, mut final_state } =
execute_transactions(state, &block_txs, block_context);
Self::verify_execution_outputs(&revert_reasons, &execution_outputs);
Self::verify_execution_outputs(block_index, &revert_reasons, &execution_outputs);
let extended_state_diff = final_state.cache.borrow().extended_state_diff();
// Update the wrapped state.
let state_diff = final_state.to_state_diff().unwrap();
Expand Down
Loading
Loading