Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
test(fee): test get_message_segment_length function
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Feb 12, 2024
1 parent 06ceabe commit 93b4b1c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/blockifier/src/fee/gas_usage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use starknet_api::hash::StarkFelt;
use starknet_api::stark_felt;
use starknet_api::transaction::{EventContent, EventData, EventKey, L2ToL1Payload};

use crate::abi::constants;
use crate::execution::call_info::{
CallExecution, CallInfo, MessageToL1, OrderedEvent, OrderedL2ToL1Message,
};
Expand Down Expand Up @@ -432,3 +433,26 @@ fn test_onchain_data_discount() {
assert!(cost_ratio <= 0.9);
assert!(cost_ratio >= 0.88);
}

#[rstest]
#[case(vec![10, 20, 30], Some(50))]
#[case(vec![10, 20, 30], None)]
#[case(vec![], Some(50))]
#[case(vec![], None)]
fn test_get_message_segment_length(
#[case] l2_to_l1_payload_lengths: Vec<usize>,
#[case] l1_handler_payload_size: Option<usize>,
) {
let result = get_message_segment_length(&l2_to_l1_payload_lengths, l1_handler_payload_size);

let expected_result: usize = l2_to_l1_payload_lengths.len()
* constants::L2_TO_L1_MSG_HEADER_SIZE
+ l2_to_l1_payload_lengths.iter().sum::<usize>()
+ if let Some(size) = l1_handler_payload_size {
constants::L1_TO_L2_MSG_HEADER_SIZE + size
} else {
0
};

assert_eq!(result, expected_result);
}

0 comments on commit 93b4b1c

Please sign in to comment.