Skip to content

Commit 6d1de2a

Browse files
starknet_os_flow_tests: migrate test_initial_sierra_gas
1 parent b1c83fc commit 6d1de2a

File tree

1 file changed

+104
-1
lines changed
  • crates/starknet_os_flow_tests/src

1 file changed

+104
-1
lines changed

crates/starknet_os_flow_tests/src/tests.rs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use cairo_vm::types::builtin_name::BuiltinName;
1313
use expect_test::expect;
1414
use rstest::rstest;
1515
use starknet_api::abi::abi_utils::{get_storage_var_address, selector_from_name};
16-
use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp};
16+
use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp, GasPrice};
1717
use starknet_api::contract_class::compiled_class_hash::{HashVersion, HashableCompiledClass};
1818
use starknet_api::contract_class::{ClassInfo, ContractClass};
1919
use starknet_api::core::{
@@ -1872,3 +1872,106 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) {
18721872
test_manager.execute_test_with_default_block_contexts(&TestParameters::default()).await;
18731873
test_output.perform_default_validations();
18741874
}
1875+
1876+
#[rstest]
1877+
#[tokio::test]
1878+
async fn test_initial_sierra_gas() {
1879+
let account_contract = FeatureContract::Experimental;
1880+
let (mut test_manager, [account_address]) =
1881+
TestManager::<DictStateReader>::new_with_default_initial_state([(
1882+
account_contract,
1883+
calldata![],
1884+
)])
1885+
.await;
1886+
1887+
// Fund the account.
1888+
test_manager.add_fund_address_tx_with_default_amount(account_address);
1889+
1890+
// Test invoke gas limits.
1891+
let os_constants = &VersionedConstants::latest_constants().os_constants;
1892+
let validate_max_sierra_gas = os_constants.validate_max_sierra_gas.0;
1893+
let execute_max_sierra_gas = os_constants.execute_max_sierra_gas.0;
1894+
for l2_gas_amount in [
1895+
validate_max_sierra_gas - 123456,
1896+
validate_max_sierra_gas + 123456,
1897+
10 * execute_max_sierra_gas,
1898+
] {
1899+
// Set up gas parameters.
1900+
let resource_bounds = match *NON_TRIVIAL_RESOURCE_BOUNDS {
1901+
ValidResourceBounds::AllResources(all_resource_bounds) => {
1902+
ValidResourceBounds::AllResources(AllResourceBounds {
1903+
l2_gas: ResourceBounds {
1904+
max_amount: GasAmount(l2_gas_amount),
1905+
max_price_per_unit: GasPrice(1 << 40),
1906+
},
1907+
..all_resource_bounds
1908+
})
1909+
}
1910+
_ => panic!("Resource bounds are not all resources"),
1911+
};
1912+
let expected_validate_gas_upper_limit = u64::min(l2_gas_amount, validate_max_sierra_gas);
1913+
let expected_validate_gas_lower_limit = expected_validate_gas_upper_limit - 50000;
1914+
let expected_execute_gas_upper_limit =
1915+
u64::min(l2_gas_amount - 50000, execute_max_sierra_gas);
1916+
let expected_execute_gas_lower_limit = expected_execute_gas_upper_limit - 150000;
1917+
1918+
// Invoke verify_gas_limits.
1919+
let invoke_args = invoke_tx_args! {
1920+
sender_address: account_address,
1921+
nonce: test_manager.next_nonce(account_address),
1922+
calldata: create_calldata(
1923+
account_address,
1924+
"verify_gas_limits",
1925+
&[
1926+
Felt::from(expected_validate_gas_lower_limit),
1927+
Felt::from(expected_validate_gas_upper_limit),
1928+
Felt::from(expected_execute_gas_lower_limit),
1929+
Felt::from(expected_execute_gas_upper_limit)
1930+
]
1931+
),
1932+
resource_bounds: resource_bounds,
1933+
};
1934+
test_manager.add_invoke_tx_from_args(invoke_args, &CHAIN_ID_FOR_TESTS, None);
1935+
}
1936+
1937+
// L1 handler bounds test.
1938+
let expected_l1_handler_gas_upper_bound = os_constants.l1_handler_max_amount_bounds.l2_gas.0;
1939+
let expected_l1_handler_gas_lower_bound = expected_l1_handler_gas_upper_bound - 10001;
1940+
let from_address = Felt::from_hex_unchecked("0xDEADACC");
1941+
let selector = selector_from_name("verify_gas_limits_l1_handler");
1942+
let calldata = vec![
1943+
Felt::from(expected_l1_handler_gas_lower_bound),
1944+
Felt::from(expected_l1_handler_gas_upper_bound),
1945+
];
1946+
let l1_handler_tx = ExecutableL1HandlerTransaction::create(
1947+
L1HandlerTransaction {
1948+
version: L1HandlerTransaction::VERSION,
1949+
nonce: Nonce::default(),
1950+
contract_address: account_address,
1951+
entry_point_selector: selector,
1952+
calldata: Calldata(Arc::new([vec![from_address], calldata.clone()].concat())),
1953+
},
1954+
&CHAIN_ID_FOR_TESTS,
1955+
Fee(1_000_000),
1956+
)
1957+
.unwrap();
1958+
test_manager.add_l1_handler_tx(l1_handler_tx.clone(), None);
1959+
let messages_to_l2 = vec![MessageToL2 {
1960+
from_address: EthAddress::try_from(from_address).unwrap(),
1961+
to_address: account_address,
1962+
nonce: Nonce::default(),
1963+
selector,
1964+
payload: L1ToL2Payload(calldata),
1965+
}];
1966+
1967+
// Run test.
1968+
let test_output = test_manager
1969+
.execute_test_with_default_block_contexts(&TestParameters {
1970+
use_kzg_da: true,
1971+
messages_to_l2,
1972+
..Default::default()
1973+
})
1974+
.await;
1975+
1976+
test_output.perform_default_validations();
1977+
}

0 commit comments

Comments
 (0)