Skip to content

Commit f522dd2

Browse files
starknet_os_flow_tests: use nonce as deployment salt
1 parent 0436e6d commit f522dd2

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

crates/starknet_os_flow_tests/src/initial_state.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use starknet_types_core::felt::Felt;
3737
use crate::state_trait::FlowTestState;
3838
use crate::test_manager::{
3939
block_context_for_flow_tests,
40+
EXPECTED_STRK_FEE_TOKEN_ADDRESS,
4041
FUNDED_ACCOUNT_ADDRESS,
4142
STRK_FEE_TOKEN_ADDRESS,
4243
};
@@ -303,8 +304,9 @@ pub(crate) fn get_deploy_contract_tx_and_address(
303304
ctor_calldata,
304305
nonce,
305306
resource_bounds,
306-
// Default salt.
307-
ContractAddressSalt(Felt::ONE),
307+
// Use the nonce as the salt so it's easy to deploy the same contract (with the same
308+
// constructor calldata) multiple times.
309+
ContractAddressSalt(nonce.0),
308310
);
309311
(
310312
Transaction::new_for_sequencing(StarknetAPITransaction::Account(
@@ -369,10 +371,12 @@ pub(crate) fn get_deploy_fee_token_tx_and_address(nonce: Nonce) -> (Transaction,
369371
*FUNDED_ACCOUNT_ADDRESS.0.key(), // provisional_governance_admin
370372
10.into() // upgrade delay
371373
];
372-
get_deploy_contract_tx_and_address(
374+
let (tx, address) = get_deploy_contract_tx_and_address(
373375
class_hash,
374376
constructor_calldata,
375377
nonce,
376378
ValidResourceBounds::create_for_testing_no_fee_enforcement(),
377-
)
379+
);
380+
EXPECTED_STRK_FEE_TOKEN_ADDRESS.assert_debug_eq(&**address);
381+
(tx, address)
378382
}

crates/starknet_os_flow_tests/src/test_manager.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use blockifier::transaction::transaction_execution::Transaction as BlockifierTra
1414
use blockifier_test_utils::calldata::create_calldata;
1515
use blockifier_test_utils::contracts::FeatureContract;
1616
use cairo_vm::types::builtin_name::BuiltinName;
17+
use expect_test::{expect, Expect};
1718
use itertools::Itertools;
1819
use starknet_api::abi::abi_utils::get_fee_token_var_address;
1920
use starknet_api::block::{BlockHash, BlockInfo, BlockNumber, PreviousBlockNumber};
2021
use starknet_api::contract_class::compiled_class_hash::{HashVersion, HashableCompiledClass};
2122
use starknet_api::contract_class::ContractClass;
22-
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce};
23+
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce, PatriciaKey};
2324
use starknet_api::executable_transaction::{
2425
AccountTransaction,
2526
DeclareTransaction,
@@ -57,7 +58,6 @@ use starknet_types_core::felt::Felt;
5758

5859
use crate::initial_state::{
5960
create_default_initial_state_data,
60-
get_deploy_fee_token_tx_and_address,
6161
get_initial_deploy_account_tx,
6262
InitialState,
6363
InitialStateData,
@@ -77,8 +77,20 @@ use crate::utils::{
7777
};
7878

7979
/// The STRK fee token address that was deployed when initializing the default initial state.
80-
pub(crate) static STRK_FEE_TOKEN_ADDRESS: LazyLock<ContractAddress> =
81-
LazyLock::new(|| get_deploy_fee_token_tx_and_address(Nonce::default()).1);
80+
/// The resulting address depends on the nonce of the deploying account - if extra init transactions
81+
/// are added to the initial state construction before the STRK fee token is deployed, the address
82+
/// must be updated.
83+
pub(crate) const EXPECTED_STRK_FEE_TOKEN_ADDRESS: Expect = expect![[r#"
84+
0x1a465ff487205d561821685efff4903cb07d69f014b1688a560f8c6380cd025
85+
"#]];
86+
pub(crate) static STRK_FEE_TOKEN_ADDRESS: LazyLock<ContractAddress> = LazyLock::new(|| {
87+
ContractAddress(
88+
PatriciaKey::try_from(Felt::from_hex_unchecked(
89+
EXPECTED_STRK_FEE_TOKEN_ADDRESS.data.trim(),
90+
))
91+
.unwrap(),
92+
)
93+
});
8294

8395
/// The address of a funded account that is able to pay fees for transactions.
8496
/// This address was initialized when creating the default initial state.

0 commit comments

Comments
 (0)