fn initialize_ledger(
        mint_address: Pubkey,
        config: &TestValidatorGenesis,
    ) -> Result<PathBuf, Box<dyn std::error::Error>> {
        let validator_identity = Keypair::new();
        let validator_vote_account = Keypair::new();
        let validator_stake_account = Keypair::new();
        let validator_identity_lamports = sol_to_lamports(500.);
        let validator_stake_lamports = sol_to_lamports(1_000_000.);
        let mint_lamports = sol_to_lamports(500_000_000.);

        let mut accounts = config.accounts.clone();
        for (address, account) in solana_program_test::programs::spl_programs(&config.rent) {
            accounts.entry(address).or_insert(account);
        }
        for program in &config.programs {
            let data = solana_program_test::read_file(&program.program_path);
            accounts.insert(
                program.program_id,
                AccountSharedData::from(Account {
                    lamports: Rent::default().minimum_balance(data.len()).min(1),
                    data,
                    owner: program.loader,
                    executable: true,
                    rent_epoch: 0,
                }),
            );
        }

        let mut genesis_config = create_genesis_config_with_leader_ex(
            mint_lamports,
            &mint_address,
            &validator_identity.pubkey(),
            &validator_vote_account.pubkey(),
            &validator_stake_account.pubkey(),
            validator_stake_lamports,
            validator_identity_lamports,
            config.fee_rate_governor.clone(),
            config.rent,
            solana_sdk::genesis_config::ClusterType::Development,
            accounts.into_iter().collect(),
        );
        genesis_config.epoch_schedule = config
            .epoch_schedule
            .unwrap_or_else(EpochSchedule::without_warmup);

        let ledger_path = match &config.ledger_path {
            None => create_new_tmp_ledger!(&genesis_config).0,
            Some(ledger_path) => {
                if TestValidatorGenesis::ledger_exists(ledger_path) {
                    return Ok(ledger_path.to_path_buf());
                }

                let _ = create_new_ledger(
                    ledger_path,
                    &genesis_config,
                    config
                        .max_genesis_archive_unpacked_size
                        .unwrap_or(MAX_GENESIS_ARCHIVE_UNPACKED_SIZE),
                    solana_ledger::blockstore_db::AccessType::PrimaryOnly,
                )
                .map_err(|err| {
                    format!(
                        "Failed to create ledger at {}: {}",
                        ledger_path.display(),
                        err
                    )
                })?;
                ledger_path.to_path_buf()
            }
        };

        write_keypair_file(
            &validator_identity,
            ledger_path.join("validator-keypair.json").to_str().unwrap(),
        )?;

        // `ledger_exists` should fail until the vote account keypair is written
        assert!(!TestValidatorGenesis::ledger_exists(&ledger_path));

        write_keypair_file(
            &validator_vote_account,
            ledger_path
                .join("vote-account-keypair.json")
                .to_str()
                .unwrap(),
        )?;

        Ok(ledger_path)
    }
/// Initialize the ledger directory
///
/// If `ledger_path` is `None`, a temporary ledger will be created.  Otherwise the ledger will
/// be initialized in the provided directory if it doesn't already exist.
///
/// Returns the path to the ledger directory.
Initialize the ledger directory
If `ledger_path` is `None`, a temporary ledger will be created.  Otherwise the ledger will
be initialized in the provided directory if it doesn't already exist.

Returns the path to the ledger directory.
Initialize the ledger directory If ` ledger_path ` is ` None ` a temporary ledger will be created . Otherwise the ledger will be initialized in the provided directory if it doesn ' t already exist . Returns the path to the ledger directory .
fn initialize_ledger(
        mint_address: Pubkey,
        config: &TestValidatorGenesis,
    ) -> Result<PathBuf, Box<dyn std::error::Error>> {
        let validator_identity = Keypair::new();
        let validator_vote_account = Keypair::new();
        let validator_stake_account = Keypair::new();
        let validator_identity_lamports = sol_to_lamports(500.);
        let validator_stake_lamports = sol_to_lamports(1_000_000.);
        let mint_lamports = sol_to_lamports(500_000_000.);
        let mut accounts = config.accounts.clone();
        for (address, account) in solana_program_test::programs::spl_programs(&config.rent) {
            accounts.entry(address).or_insert(account);
        }
        for program in &config.programs {
            let data = solana_program_test::read_file(&program.program_path);
            accounts.insert(
                program.program_id,
                AccountSharedData::from(Account {
                    lamports: Rent::default().minimum_balance(data.len()).min(1),
                    data,
                    owner: program.loader,
                    executable: true,
                    rent_epoch: 0,
                }),
            );
        }
        let mut genesis_config = create_genesis_config_with_leader_ex(
            mint_lamports,
            &mint_address,
            &validator_identity.pubkey(),
            &validator_vote_account.pubkey(),
            &validator_stake_account.pubkey(),
            validator_stake_lamports,
            validator_identity_lamports,
            config.fee_rate_governor.clone(),
            config.rent,
            solana_sdk::genesis_config::ClusterType::Development,
            accounts.into_iter().collect(),
        );
        genesis_config.epoch_schedule = config
            .epoch_schedule
            .unwrap_or_else(EpochSchedule::without_warmup);
        let ledger_path = match &config.ledger_path {
            None => create_new_tmp_ledger!(&genesis_config).0,
            Some(ledger_path) => {
                if TestValidatorGenesis::ledger_exists(ledger_path) {
                    return Ok(ledger_path.to_path_buf());
                }
                let _ = create_new_ledger(
                    ledger_path,
                    &genesis_config,
                    config
                        .max_genesis_archive_unpacked_size
                        .unwrap_or(MAX_GENESIS_ARCHIVE_UNPACKED_SIZE),
                    solana_ledger::blockstore_db::AccessType::PrimaryOnly,
                )
                .map_err(|err| {
                    format!(
                        "Failed to create ledger at {}: {}",
                        ledger_path.display(),
                        err
                    )
                })?;
                ledger_path.to_path_buf()
            }
        };
        write_keypair_file(
            &validator_identity,
            ledger_path.join("validator-keypair.json").to_str().unwrap(),
        )?;
        // `ledger_exists` should fail until the vote account keypair is written
        assert!(!TestValidatorGenesis::ledger_exists(&ledger_path));
        write_keypair_file(
            &validator_vote_account,
            ledger_path
                .join("vote-account-keypair.json")
                .to_str()
                .unwrap(),
        )?;
        Ok(ledger_path)
    }
fn initialize_ledger ( mint_address : Pubkey , config : & TestValidatorGenesis , ) -> Result < PathBuf , Box < dyn std :: error :: Error > > { let validator_identity = Keypair :: new ( ) ; let validator_vote_account = Keypair :: new ( ) ; let validator_stake_account = Keypair :: new ( ) ; let validator_identity_lamports = sol_to_lamports ( 500. ) ; let validator_stake_lamports = sol_to_lamports ( 1_000_000. ) ; let mint_lamports = sol_to_lamports ( 500_000_000. ) ; let mut accounts = config . accounts . clone ( ) ; for ( address , account ) in solana_program_test :: programs :: spl_programs ( & config . rent ) { accounts . entry ( address ) . or_insert ( account ) ; } for program in & config . programs { let data = solana_program_test :: read_file ( & program . program_path ) ; accounts . insert ( program . program_id , AccountSharedData :: from ( Account { lamports : Rent :: default ( ) . minimum_balance ( data . len ( ) ) . min ( 1 ) , data , owner : program . loader , executable : true , rent_epoch : 0 , } ) , ) ; } let mut genesis_config = create_genesis_config_with_leader_ex ( mint_lamports , & mint_address , & validator_identity . pubkey ( ) , & validator_vote_account . pubkey ( ) , & validator_stake_account . pubkey ( ) , validator_stake_lamports , validator_identity_lamports , config . fee_rate_governor . clone ( ) , config . rent , solana_sdk :: genesis_config :: ClusterType :: Development , accounts . into_iter ( ) . collect ( ) , ) ; genesis_config . epoch_schedule = config . epoch_schedule . unwrap_or_else ( EpochSchedule :: without_warmup ) ; let ledger_path = match & config . ledger_path { None => create_new_tmp_ledger ! ( genesis_config ) . 0 , Some ( ledger_path ) => { if TestValidatorGenesis :: ledger_exists ( ledger_path ) { return Ok ( ledger_path . to_path_buf ( ) ) ; } let _ = create_new_ledger ( ledger_path , & genesis_config , config . max_genesis_archive_unpacked_size . unwrap_or ( MAX_GENESIS_ARCHIVE_UNPACKED_SIZE ) , solana_ledger :: blockstore_db :: AccessType :: PrimaryOnly , ) . map_err ( | err | { format ! ( " " ledger_path display ( ) err ) } ) ? ; ledger_path . to_path_buf ( ) } } ; write_keypair_file ( & validator_identity , ledger_path . join ( " " ) . to_str ( ) . unwrap ( ) , ) ? ; // `ledger_exists` should fail until the vote account keypair is written assert ! ( TestValidatorGenesis ledger_exists ( ledger_path ) ) ; write_keypair_file ( & validator_vote_account , ledger_path . join ( " " ) . to_str ( ) . unwrap ( ) , ) ? ; Ok ( ledger_path ) }
Initialize the ledger directory
If `ledger_path` is `None`, a temporary ledger will be created.
Initialize the ledger directory If ` ledger_path ` is ` None ` a temporary ledger will be created .
mint_address
Pubkey
config
&TestValidatorGenesis