Skip to content

Commit 3348213

Browse files
blockifier_test_utils: put tx hash in signature for exec info tests
1 parent 0c893d7 commit 3348213

File tree

6 files changed

+9676
-9526
lines changed

6 files changed

+9676
-9526
lines changed

crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
24
use blockifier_test_utils::contracts::FeatureContract;
35
use starknet_api::abi::abi_utils::selector_from_name;
@@ -23,6 +25,7 @@ use starknet_api::transaction::fields::{
2325
Resource,
2426
ResourceBounds,
2527
Tip,
28+
TransactionSignature,
2629
ValidResourceBounds,
2730
};
2831
use starknet_api::transaction::{TransactionVersion, QUERY_VERSION_BASE};
@@ -352,7 +355,9 @@ fn test_get_execution_info(
352355
+ if high_tip { 1 } else { 0 });
353356
let expected_tip = if version == TransactionVersion::THREE { tip } else { Tip(0) };
354357

355-
let expected_unsupported_fields = match test_contract {
358+
let tx_hash = tx_hash!(1991);
359+
360+
let (expected_unsupported_fields, expected_signature) = match test_contract {
356361
FeatureContract::LegacyTestContract => {
357362
// Read and parse file content.
358363
let raw_contract: serde_json::Value =
@@ -363,20 +368,23 @@ fn test_get_execution_info(
363368
} else {
364369
panic!("'compiler_version' not found or not a valid string in JSON.");
365370
};
366-
vec![]
371+
(vec![], vec![])
367372
}
368373
#[cfg(feature = "cairo_native")]
369374
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native) => {
370-
vec![]
375+
(vec![], vec![tx_hash.0])
371376
}
372377
_ => {
373-
vec![
374-
expected_tip.into(), // Tip.
375-
Felt::ZERO, // Paymaster data.
376-
Felt::ZERO, // Nonce DA.
377-
Felt::ZERO, // Fee DA.
378-
Felt::ZERO, // Account data.
379-
]
378+
(
379+
vec![
380+
expected_tip.into(), // Tip.
381+
Felt::ZERO, // Paymaster data.
382+
Felt::ZERO, // Nonce DA.
383+
Felt::ZERO, // Fee DA.
384+
Felt::ZERO, // Account data.
385+
],
386+
vec![tx_hash.0],
387+
)
380388
}
381389
};
382390

@@ -388,10 +396,10 @@ fn test_get_execution_info(
388396
expected_version += simulate_version_base;
389397
}
390398

391-
let tx_hash = tx_hash!(1991);
392399
let max_fee = Fee(42);
393400
let nonce = nonce!(3_u16);
394401
let sender_address = test_contract_address;
402+
let signature = TransactionSignature(Arc::new(expected_signature));
395403

396404
let resource_bounds =
397405
ResourceBounds { max_amount: GasAmount(13), max_price_per_unit: GasPrice(61) };
@@ -438,10 +446,10 @@ fn test_get_execution_info(
438446
common_fields: CommonAccountFields {
439447
transaction_hash: tx_hash,
440448
version: TransactionVersion::ONE,
449+
signature,
441450
nonce,
442451
sender_address,
443452
only_query,
444-
..Default::default()
445453
},
446454
max_fee,
447455
});
@@ -460,10 +468,10 @@ fn test_get_execution_info(
460468
common_fields: CommonAccountFields {
461469
transaction_hash: tx_hash,
462470
version: TransactionVersion::THREE,
471+
signature,
463472
nonce,
464473
sender_address,
465474
only_query,
466-
..Default::default()
467475
},
468476
resource_bounds: all_resource_bounds,
469477
tip,

crates/blockifier/src/transaction/transactions_test.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use starknet_api::core::{ascii_as_felt, ClassHash, ContractAddress, Nonce};
2525
use starknet_api::executable_transaction::{
2626
AccountTransaction as ApiExecutableTransaction,
2727
DeployAccountTransaction,
28+
InvokeTransaction,
2829
TransactionType,
2930
};
3031
use starknet_api::execution_resources::{GasAmount, GasVector};
@@ -35,7 +36,7 @@ use starknet_api::test_utils::deploy_account::{
3536
executable_deploy_account_tx,
3637
DeployAccountTxArgs,
3738
};
38-
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};
39+
use starknet_api::test_utils::invoke::{executable_invoke_tx, invoke_tx, InvokeTxArgs};
3940
use starknet_api::test_utils::{
4041
NonceManager,
4142
CHAIN_ID_FOR_TESTS,
@@ -66,6 +67,7 @@ use starknet_api::transaction::{
6667
EventContent,
6768
EventData,
6869
EventKey,
70+
InvokeTransaction as ApiInvokeTransaction,
6971
L2ToL1Payload,
7072
TransactionVersion,
7173
};
@@ -2606,13 +2608,23 @@ fn test_only_query_flag(
26062608
), // Calldata length.
26072609
];
26082610
let execute_calldata = Calldata([execute_calldata, expected_execution_info].concat().into());
2609-
let tx = executable_invoke_tx(invoke_tx_args! {
2611+
let invoke_args = invoke_tx_args! {
26102612
calldata: execute_calldata,
26112613
resource_bounds: default_all_resource_bounds,
26122614
sender_address: account_address,
2613-
});
2615+
};
2616+
let invoke_tx =
2617+
InvokeTransaction::create(invoke_tx(invoke_args), &block_context.chain_info.chain_id)
2618+
.unwrap();
2619+
let tx_hash = invoke_tx.tx_hash;
2620+
let ApiInvokeTransaction::V3(mut tx) = invoke_tx.tx else {
2621+
panic!("Expected V3 transaction");
2622+
};
2623+
tx.signature = TransactionSignature(Arc::new(vec![tx_hash.0]));
2624+
let invoke_tx = InvokeTransaction { tx: ApiInvokeTransaction::V3(tx), tx_hash };
26142625
let execution_flags = ExecutionFlags { only_query, ..Default::default() };
2615-
let invoke_tx = AccountTransaction { tx, execution_flags };
2626+
let invoke_tx =
2627+
AccountTransaction { tx: ApiExecutableTransaction::Invoke(invoke_tx), execution_flags };
26162628

26172629
let tx_execution_info = invoke_tx.execute(&mut state, &block_context).unwrap();
26182630
assert_eq!(tx_execution_info.revert_error, None);

0 commit comments

Comments
 (0)