Skip to content

Commit e70dfd5

Browse files
refactor: use TokenMetadata instead of raw Word manipulation in genesis config
- Import BlockSigner at top of config/mod.rs and simplify as_account_files signature - Replace manual Word construction with TokenMetadata::try_from and with_token_supply - Use TokenMetadata::token_supply() in tests instead of raw Word indexing Co-authored-by: marti <marti@hungrycats.studio>
1 parent fb7329d commit e70dfd5

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

crates/store/src/genesis/config/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::str::FromStr;
55

66
use indexmap::IndexMap;
77
use miden_node_utils::crypto::get_rpo_random_coin;
8+
use miden_node_utils::signer::BlockSigner;
89
use miden_protocol::account::auth::AuthSecretKey;
910
use miden_protocol::account::{
1011
Account,
@@ -23,10 +24,10 @@ use miden_protocol::asset::{FungibleAsset, TokenSymbol};
2324
use miden_protocol::block::FeeParameters;
2425
use miden_protocol::crypto::dsa::falcon512_rpo::SecretKey as RpoSecretKey;
2526
use miden_protocol::errors::TokenSymbolError;
26-
use miden_protocol::{Felt, FieldElement, ONE, Word};
27+
use miden_protocol::{Felt, FieldElement, ONE};
2728
use miden_standards::AuthScheme;
2829
use miden_standards::account::auth::AuthFalcon512Rpo;
29-
use miden_standards::account::faucets::BasicFungibleFaucet;
30+
use miden_standards::account::faucets::{BasicFungibleFaucet, TokenMetadata};
3031
use miden_standards::account::wallets::create_basic_wallet;
3132
use rand::distr::weighted::Weight;
3233
use rand::{Rng, SeedableRng};
@@ -219,16 +220,13 @@ impl GenesisConfig {
219220
let mut storage_delta = AccountStorageDelta::default();
220221

221222
if total_issuance != 0 {
222-
let metadata_slot_name = BasicFungibleFaucet::metadata_slot();
223-
let current_metadata =
224-
faucet_account.storage().get_item(metadata_slot_name).unwrap();
225-
let updated_metadata = Word::from([
226-
Felt::new(total_issuance),
227-
current_metadata[1],
228-
current_metadata[2],
229-
current_metadata[3],
230-
]);
231-
storage_delta.set_item(metadata_slot_name.clone(), updated_metadata)?;
223+
let current_metadata = TokenMetadata::try_from(faucet_account.storage())?;
224+
let updated_metadata =
225+
current_metadata.with_token_supply(Felt::new(total_issuance))?;
226+
storage_delta.set_item(
227+
TokenMetadata::metadata_slot().clone(),
228+
updated_metadata.into(),
229+
)?;
232230
tracing::debug!(
233231
"Reducing faucet account {faucet} for {symbol} by {amount}",
234232
faucet = faucet_id.to_hex(),
@@ -448,7 +446,7 @@ impl AccountSecrets {
448446
/// and the index in
449447
pub fn as_account_files(
450448
&self,
451-
genesis_state: &GenesisState<impl miden_node_utils::signer::BlockSigner>,
449+
genesis_state: &GenesisState<impl BlockSigner>,
452450
) -> impl Iterator<Item = Result<AccountFileWithName, GenesisConfigError>> + '_ {
453451
let account_lut = IndexMap::<AccountId, Account>::from_iter(
454452
genesis_state.accounts.iter().map(|account| (account.id(), account.clone())),

crates/store/src/genesis/config/tests.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ fn parsing_yields_expected_default_values() -> TestResult {
4444
});
4545

4646
// check total issuance of the faucet
47-
assert_eq!(
48-
native_faucet.storage().get_item(BasicFungibleFaucet::metadata_slot()).unwrap()[0],
49-
Felt::new(999_777),
50-
"Issuance mismatch"
51-
);
47+
let metadata = TokenMetadata::try_from(native_faucet.storage()).unwrap();
48+
assert_eq!(metadata.token_supply(), Felt::new(999_777), "Issuance mismatch");
5249

5350
Ok(())
5451
}

0 commit comments

Comments
 (0)