Skip to content

Commit dd35a60

Browse files
committed
feat: light program test skip startup logs
1 parent 935e774 commit dd35a60

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

sdk-libs/program-test/src/program_test/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub struct ProgramTestConfig {
2727
pub v2_address_tree_config: Option<InitAddressTreeAccountsInstructionData>,
2828
pub skip_protocol_init: bool,
2929
pub log_failed_tx: bool,
30+
pub no_logs: bool,
31+
pub skip_startup_logs: bool,
3032
}
3133

3234
impl ProgramTestConfig {
@@ -117,6 +119,8 @@ impl Default for ProgramTestConfig {
117119
skip_protocol_init: false,
118120
skip_v1_trees: false,
119121
log_failed_tx: true,
122+
no_logs: false,
123+
skip_startup_logs: true,
120124
}
121125
}
122126
}

sdk-libs/program-test/src/program_test/light_program_test.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::fmt::{self, Debug, Formatter};
22

33
use account_compression::{AddressMerkleTreeAccount, QueueAccount};
4-
use forester_utils::utils::airdrop_lamports;
54
use light_client::{
65
indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts},
76
rpc::{merkle_tree::MerkleTreeExt, RpcError},
@@ -61,16 +60,24 @@ impl LightProgramTest {
6160
config: config.clone(),
6261
};
6362
let keypairs = TestKeypairs::program_test_default();
64-
airdrop_lamports(
65-
&mut context,
66-
&keypairs.governance_authority.pubkey(),
67-
100_000_000_000,
68-
)
69-
.await?;
70-
airdrop_lamports(&mut context, &keypairs.forester.pubkey(), 10_000_000_000).await?;
63+
64+
context
65+
.context
66+
.airdrop(&keypairs.governance_authority.pubkey(), 100_000_000_000_000)
67+
.expect("governance_authority airdrop failed.");
68+
context
69+
.context
70+
.airdrop(&keypairs.forester.pubkey(), 10_000_000_000)
71+
.expect("forester airdrop failed.");
7172

7273
if !config.skip_protocol_init {
74+
if context.config.skip_startup_logs {
75+
context.config.no_logs = true;
76+
}
7377
initialize_accounts(&mut context, &config, &keypairs).await?;
78+
if context.config.skip_startup_logs {
79+
context.config.no_logs = false;
80+
}
7481
let batch_size = config
7582
.v2_state_tree_config
7683
.as_ref()

sdk-libs/program-test/src/program_test/rpc.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ impl Rpc for LightProgramTest {
146146

147147
RpcError::TransactionError(x.err)
148148
})?;
149-
#[cfg(debug_assertions)]
150-
{
151-
if std::env::var("RUST_BACKTRACE").is_ok() {
152-
println!("{}", _res.pretty_logs());
149+
if !self.config.no_logs {
150+
#[cfg(debug_assertions)]
151+
{
152+
if std::env::var("RUST_BACKTRACE").is_ok() {
153+
println!("{}", _res.pretty_logs());
154+
}
153155
}
154156
}
155157
}
@@ -408,14 +410,17 @@ impl LightProgramTest {
408410

409411
RpcError::TransactionError(x.err)
410412
})?;
411-
#[cfg(debug_assertions)]
412-
{
413-
if std::env::var("RUST_BACKTRACE").is_ok() {
414-
// Print all tx logs and events.
415-
println!("{}", _res.pretty_logs());
416-
println!("event:\n {:?}", event);
413+
if !self.config.no_logs {
414+
#[cfg(debug_assertions)]
415+
{
416+
if std::env::var("RUST_BACKTRACE").is_ok() {
417+
// Print all tx logs and events.
418+
println!("{}", _res.pretty_logs());
419+
println!("event:\n {:?}", event);
420+
}
417421
}
418422
}
423+
419424
let slot = self.context.get_sysvar::<Clock>().slot;
420425
let event = event.map(|e| (e, signature, slot));
421426

0 commit comments

Comments
 (0)