Skip to content

Commit cca0d58

Browse files
authored
refactor: light-program-test add leaf index and root index to logging (#1947)
1 parent a4de8b8 commit cca0d58

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

sdk-libs/program-test/src/logging/decoder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ fn parse_invoke_instruction(data: &[u8], accounts: &[AccountMeta]) -> Instructio
295295
} else {
296296
vec![]
297297
},
298+
leaf_index: Some(acc.merkle_context.leaf_index),
299+
root_index: Some(acc.root_index),
298300
}
299301
})
300302
.collect(),
@@ -437,6 +439,8 @@ fn parse_invoke_cpi_instruction(data: &[u8], accounts: &[AccountMeta]) -> Instru
437439
} else {
438440
vec![]
439441
},
442+
leaf_index: Some(acc.merkle_context.leaf_index),
443+
root_index: Some(acc.root_index),
440444
}
441445
})
442446
.collect(),
@@ -576,6 +580,8 @@ fn parse_invoke_cpi_readonly_instruction(
576580
address: acc.address,
577581
data_hash: acc.data_hash.to_vec(),
578582
discriminator: acc.discriminator.to_vec(),
583+
leaf_index: Some(acc.merkle_context.leaf_index),
584+
root_index: Some(acc.root_index),
579585
}
580586
})
581587
.collect(),
@@ -713,6 +719,8 @@ fn parse_invoke_cpi_account_info_instruction(
713719
address: account_info.address, // Use address from CompressedAccountInfo
714720
data_hash: input.data_hash.to_vec(),
715721
discriminator: input.discriminator.to_vec(),
722+
leaf_index: Some(input.merkle_context.leaf_index),
723+
root_index: Some(input.root_index),
716724
});
717725
}
718726
}

sdk-libs/program-test/src/logging/formatter.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,13 @@ impl TransactionFormatter {
295295
) -> fmt::Result {
296296
writeln!(
297297
output,
298-
"{}│{} {}Transaction: {}{} | Slot: {} | Status: {} {}{}",
298+
"{}│{} {}Transaction: {}{} | Slot: {} | Status: {}{}",
299299
self.colors.gray,
300300
self.colors.reset,
301301
self.colors.bold,
302302
self.colors.cyan,
303303
log.signature,
304304
log.slot,
305-
log.status.symbol(),
306305
self.status_color(&log.status),
307306
log.status.text(),
308307
)?;
@@ -709,6 +708,30 @@ impl TransactionFormatter {
709708
self.colors.reset
710709
)?;
711710
}
711+
// Display leaf index after queue_pubkey
712+
if let Some(leaf_idx) = acc_data.leaf_index {
713+
writeln!(
714+
output,
715+
"{} {}leaf_index: {}{}{}",
716+
indent,
717+
self.colors.gray,
718+
self.colors.cyan,
719+
leaf_idx,
720+
self.colors.reset
721+
)?;
722+
}
723+
// Display root index after leaf index
724+
if let Some(root_idx) = acc_data.root_index {
725+
writeln!(
726+
output,
727+
"{} {}root_index: {}{}{}",
728+
indent,
729+
self.colors.gray,
730+
self.colors.cyan,
731+
root_idx,
732+
self.colors.reset
733+
)?;
734+
}
712735
}
713736
}
714737

sdk-libs/program-test/src/logging/types.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ pub enum TransactionStatus {
3131
}
3232

3333
impl TransactionStatus {
34-
pub fn symbol(&self) -> &'static str {
35-
match self {
36-
TransactionStatus::Success => "✅",
37-
TransactionStatus::Failed(_) => "❌",
38-
TransactionStatus::Unknown => "⚠️",
39-
}
40-
}
41-
4234
pub fn text(&self) -> String {
4335
match self {
4436
TransactionStatus::Success => "Success".to_string(),
@@ -136,6 +128,8 @@ pub struct InputAccountData {
136128
pub address: Option<[u8; 32]>,
137129
pub data_hash: Vec<u8>,
138130
pub discriminator: Vec<u8>,
131+
pub leaf_index: Option<u32>,
132+
pub root_index: Option<u16>,
139133
}
140134

141135
/// Output account data

0 commit comments

Comments
 (0)