Making simulator prinln debug logs, fmt

This commit is contained in:
godmodegalactus 2024-10-21 16:34:02 +02:00
parent cf291318b9
commit 51ba6cf861
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
2 changed files with 37 additions and 24 deletions

View File

@ -11,16 +11,16 @@ use router_test_lib::{execution_dump, serialize};
use serde::Deserialize;
use sha2::{Digest, Sha256};
use solana_sdk::account::ReadableAccount;
use solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState;
use solana_sdk::clock::Clock;
use solana_sdk::config::program;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
use solana_sdk::signer::Signer;
use solana_sdk::sysvar::SysvarId;
use solana_sdk::bpf_loader_upgradeable::UpgradeableLoaderState;
use std::str::FromStr;
use std::sync::Arc;
use tracing::{debug, error};
use std::str::FromStr;
pub async fn run_dump_mainnet_data(
dex: Arc<dyn DexInterface>,
@ -133,7 +133,10 @@ pub async fn run_dump_mainnet_data_with_custom_amount(
// get buffer for upgradable programs
if account.owner == solana_sdk::bpf_loader_upgradeable::ID {
let state = bincode::deserialize::<UpgradeableLoaderState>(&account.data).unwrap();
if let UpgradeableLoaderState::Program { programdata_address } = state {
if let UpgradeableLoaderState::Program {
programdata_address,
} = state
{
rpc_client.get_account(&programdata_address).await?;
}
}
@ -329,13 +332,20 @@ pub async fn run_dump_swap_ix_with_custom_amount(
for program in dump.programs.clone() {
let program_account = account_provider.account(&program)?;
dump.accounts.insert(program, program_account.account.clone());
dump.accounts
.insert(program, program_account.account.clone());
// use downloaded buffers for the upgradable programs
if *program_account.account.owner() == solana_sdk::bpf_loader_upgradeable::ID {
let state = bincode::deserialize::<UpgradeableLoaderState>(program_account.account.data()).unwrap();
if let UpgradeableLoaderState::Program { programdata_address } = state {
let state =
bincode::deserialize::<UpgradeableLoaderState>(program_account.account.data())
.unwrap();
if let UpgradeableLoaderState::Program {
programdata_address,
} = state
{
let program_data_account = account_provider.account(&programdata_address)?;
dump.accounts.insert(programdata_address, program_data_account.account);
dump.accounts
.insert(programdata_address, program_data_account.account);
}
}
}

View File

@ -157,7 +157,7 @@ async fn run_all_swap_from_dump(dump_name: &str) -> Result<Result<(), Error>, Er
.await?;
for meta in &instruction.accounts {
let Ok(Some(account)) = ctx.banks_client.get_account(meta.pubkey).await else {
let Ok(Some(account)) = ctx.banks_client.get_account(meta.pubkey).await else {
log::warn!("missing account : {:?}", meta.pubkey);
continue;
};
@ -168,7 +168,6 @@ async fn run_all_swap_from_dump(dump_name: &str) -> Result<Result<(), Error>, Er
// let base64 = base64::encode(result);
// log::debug!("account : {:?} dump : {base64:?} executable : {}", meta.pubkey, account.executable());
}
if let Some(cus) = simulate_cu_usage(&mut ctx, &wallet, &instruction).await {
cus_required.push(cus);
@ -346,17 +345,19 @@ async fn initialize_accounts(
program_test: &mut ProgramTest,
dump: &ExecutionDump,
) -> anyhow::Result<()> {
println!("initializing accounts : {:?}", dump.accounts.len() );
println!("initializing accounts : {:?}", dump.accounts.len());
for (pk, account) in &dump.accounts {
println!("Setting data for {}", pk);
program_test.add_account(*pk, solana_sdk::account::Account {
lamports: account.lamports(),
owner: *account.owner(),
data: account.data().to_vec(),
rent_epoch: account.rent_epoch(),
executable: account.executable(),
});
program_test.add_account(
*pk,
solana_sdk::account::Account {
lamports: account.lamports(),
owner: *account.owner(),
data: account.data().to_vec(),
rent_epoch: account.rent_epoch(),
executable: account.executable(),
},
);
}
Ok(())
@ -384,10 +385,10 @@ async fn simulate_cu_usage(
log::debug!("units consumed : {}", cus);
Some(cus)
} else if sim.result.is_some() && sim.result.clone().unwrap().is_err() {
println!("simluation failed : {:?}", sim.result.unwrap());
println!("----logs");
log::debug!("simluation failed : {:?}", sim.result.unwrap());
log::debug!("----logs");
for log in simulation_details.logs {
println!("{log:?}");
log::debug!("{log:?}");
}
None
} else {
@ -526,7 +527,9 @@ fn create_wallet(ctx: &mut ProgramTestContext, address: Pubkey) {
);
}
async fn setup_test_chain(programs: &Vec<Pubkey>, clock: &Clock,
async fn setup_test_chain(
programs: &Vec<Pubkey>,
clock: &Clock,
dump: &ExecutionDump,
) -> ProgramTestContext {
// We need to intercept logs to capture program log output
@ -546,13 +549,13 @@ async fn setup_test_chain(programs: &Vec<Pubkey>, clock: &Clock,
let mut program_test = ProgramTest::default();
initialize_accounts(&mut program_test, dump).await.unwrap();
program_test.prefer_bpf(true);
for &key in programs {
program_test.add_program(key.to_string().as_str(), key, None);
}
program_test.add_program("autobahn_executor", autobahn_executor::ID, None);
// TODO: make this dynamic based on routes
program_test.set_compute_max_units(1_400_000);