Skip to content

Commit 9277cbd

Browse files
starknet_os_flow_tests: use nonce as deployment salt (#9819)
1 parent 37aa37e commit 9277cbd

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
};
@@ -302,8 +303,9 @@ pub(crate) fn get_deploy_contract_tx_and_address(
302303
ctor_calldata,
303304
nonce,
304305
resource_bounds,
305-
// Default salt.
306-
ContractAddressSalt(Felt::ONE),
306+
// Use the nonce as the salt so it's easy to deploy the same contract (with the same
307+
// constructor calldata) multiple times.
308+
ContractAddressSalt(nonce.0),
307309
);
308310
(
309311
Transaction::new_for_sequencing(StarknetAPITransaction::Account(
@@ -368,10 +370,12 @@ pub(crate) fn get_deploy_fee_token_tx_and_address(nonce: Nonce) -> (Transaction,
368370
*FUNDED_ACCOUNT_ADDRESS.0.key(), // provisional_governance_admin
369371
10.into() // upgrade delay
370372
];
371-
get_deploy_contract_tx_and_address(
373+
let (tx, address) = get_deploy_contract_tx_and_address(
372374
class_hash,
373375
constructor_calldata,
374376
nonce,
375377
ValidResourceBounds::create_for_testing_no_fee_enforcement(),
376-
)
378+
);
379+
EXPECTED_STRK_FEE_TOKEN_ADDRESS.assert_debug_eq(&**address);
380+
(tx, address)
377381
}

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, GlobalRoot, Nonce};
23+
use starknet_api::core::{ChainId, ClassHash, ContractAddress, GlobalRoot, 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,
@@ -76,8 +76,20 @@ use crate::utils::{
7676
};
7777

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

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

0 commit comments

Comments
 (0)