Skip to content

Commit a4b41f9

Browse files
blockifier: update test contract for test_new_contract_flow (#9514)
1 parent 73a1808 commit a4b41f9

File tree

11 files changed

+20581
-13715
lines changed

11 files changed

+20581
-13715
lines changed

crates/apollo_integration_tests/tests/common/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,22 @@ fn get_total_batched_txs_count(recorder_handle: &PrometheusHandle) -> usize {
142142
}
143143

144144
fn assert_full_blocks_flow(recorder_handle: &PrometheusHandle, expecting_full_blocks: bool) {
145-
let metrics = recorder_handle.render();
146-
let full_blocks_metric = apollo_batcher::metrics::BLOCK_CLOSE_REASON
147-
.parse_numeric_metric::<u64>(
148-
&metrics,
149-
&[(
150-
apollo_batcher::metrics::LABEL_NAME_BLOCK_CLOSE_REASON,
151-
apollo_batcher::metrics::BlockCloseReason::FullBlock.into(),
152-
)],
153-
)
154-
.unwrap();
155145
if expecting_full_blocks {
146+
let metrics = recorder_handle.render();
147+
let full_blocks_metric = apollo_batcher::metrics::BLOCK_CLOSE_REASON
148+
.parse_numeric_metric::<u64>(
149+
&metrics,
150+
&[(
151+
apollo_batcher::metrics::LABEL_NAME_BLOCK_CLOSE_REASON,
152+
apollo_batcher::metrics::BlockCloseReason::FullBlock.into(),
153+
)],
154+
)
155+
.unwrap();
156156
assert!(full_blocks_metric > 0);
157-
} else {
158-
assert_eq!(full_blocks_metric, 0);
159157
}
158+
// Just because we don't expect full blocks, doesn't mean we should assert that the metric is 0.
159+
// It is possible that a block is filled, no need to assert that this is not the case.
160+
// TODO(AlonH): In the `else` case, assert that some block closed due to time.
160161
}
161162

162163
fn assert_no_reverted_transactions_flow(recorder_handle: &PrometheusHandle) {

crates/blockifier/src/bouncer_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,11 @@ fn class_hash_migration_data_from_state(
744744

745745
if should_migrate {
746746
expect![[r#"
747-
90624924
747+
102613834
748748
"#]]
749749
.assert_debug_eq(&migration_sierra_gas.0);
750750
expect![[r#"
751-
219546600
751+
249398680
752752
"#]]
753753
.assert_debug_eq(&migration_proving_gas.0);
754754
} else {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub const REQUIRED_GAS_GET_BLOCK_HASH_TEST: u64 = 14920;
1+
pub const REQUIRED_GAS_GET_BLOCK_HASH_TEST: u64 = 16220;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn positive_flow(runnable_version: RunnableCairo1) {
4848
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
4949
let (mut state, block_number, block_hash) = initialize_state(test_contract);
5050

51-
let calldata = calldata![block_number];
51+
let calldata = calldata![block_number, block_hash];
5252
let entry_point_call = CallEntryPoint {
5353
entry_point_selector: selector_from_name("test_get_block_hash"),
5454
calldata,
@@ -83,7 +83,7 @@ fn positive_flow(runnable_version: RunnableCairo1) {
8383
l2_to_l1_messages: [],
8484
cairo_native: false,
8585
failed: false,
86-
gas_consumed: 14920,
86+
gas_consumed: 15620,
8787
}
8888
"#]]
8989
.assert_debug_eq(&call_info.execution);
@@ -98,7 +98,8 @@ fn negative_flow_block_number_out_of_range(runnable_version: RunnableCairo1) {
9898

9999
let requested_block_number = CURRENT_BLOCK_NUMBER - constants::STORED_BLOCK_HASH_BUFFER + 1;
100100
let block_number = felt!(requested_block_number);
101-
let calldata = calldata![block_number];
101+
let dummy_block_hash = felt!(66_u64);
102+
let calldata = calldata![block_number, dummy_block_hash];
102103
let entry_point_call = CallEntryPoint {
103104
entry_point_selector: selector_from_name("test_get_block_hash"),
104105
calldata,

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ fn test_get_class_hash_at(runnable_version: RunnableCairo1) {
2525
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);
2626
let address = contract_address!("0x111");
2727
let class_hash = class_hash!("0x222");
28+
let class_hash_of_undeployed_contract = felt!("0x0");
29+
let non_existing_address = felt!("0x333");
2830
state.state.address_to_class_hash.insert(address, class_hash);
2931

3032
// Test deployed contract.
3133
let positive_entry_point_call = CallEntryPoint {
32-
calldata: calldata![address.into(), class_hash.0],
34+
calldata: calldata![address.into(), class_hash.0, non_existing_address],
3335
entry_point_selector: selector_from_name("test_get_class_hash_at"),
3436
..trivial_external_entry_point_new(test_contract)
3537
};
@@ -51,18 +53,20 @@ fn test_get_class_hash_at(runnable_version: RunnableCairo1) {
5153
l2_to_l1_messages: [],
5254
cairo_native: false,
5355
failed: false,
54-
gas_consumed: 15960,
56+
gas_consumed: 28370,
5557
}
5658
"#]]
5759
.assert_debug_eq(&positive_call_info.execution);
5860
assert!(!positive_call_info.execution.failed);
5961
assert_eq!(positive_call_info.execution.retdata, retdata![]);
60-
// Test undeployed contract - should return class_hash = 0 and succeed.
61-
let non_existing_address = felt!("0x333");
62-
let class_hash_of_undeployed_contract = felt!("0x0");
6362

63+
// Test undeployed contract - should return class_hash = 0 and succeed.
6464
let negative_entry_point_call = CallEntryPoint {
65-
calldata: calldata![non_existing_address, class_hash_of_undeployed_contract],
65+
calldata: calldata![
66+
non_existing_address,
67+
class_hash_of_undeployed_contract,
68+
non_existing_address
69+
],
6670
entry_point_selector: selector_from_name("test_get_class_hash_at"),
6771
..trivial_external_entry_point_new(test_contract)
6872
};
@@ -71,7 +75,7 @@ fn test_get_class_hash_at(runnable_version: RunnableCairo1) {
7175
// Sanity check: giving the wrong expected class hash to the test should make it fail.
7276
let different_class_hash = class_hash!("0x444");
7377
let different_class_hash_entry_point_call = CallEntryPoint {
74-
calldata: calldata![address.into(), different_class_hash.0],
78+
calldata: calldata![address.into(), different_class_hash.0, non_existing_address],
7579
entry_point_selector: selector_from_name("test_get_class_hash_at"),
7680
..trivial_external_entry_point_new(test_contract)
7781
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::test_utils::trivial_external_entry_point_new;
1818
#[test_case(RunnableCairo1::Casm; "VM")]
1919
fn test_out_of_gas(runnable_version: RunnableCairo1) {
2020
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
21-
let (mut state, block_number, _block_hash) = initialize_state(test_contract);
21+
let (mut state, block_number, block_hash) = initialize_state(test_contract);
2222

23-
let calldata = calldata![block_number];
23+
let calldata = calldata![block_number, block_hash];
2424
let entry_point_call = CallEntryPoint {
2525
entry_point_selector: selector_from_name("test_get_block_hash"),
2626
calldata,

0 commit comments

Comments
 (0)