Skip to content

Commit 246fa45

Browse files
committed
fix e2e test
1 parent cdfc10e commit 246fa45

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

program-tests/e2e-test/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ async fn test_batched_only() {
115115
None,
116116
)
117117
.await;
118-
// remove concurrent Merkle trees
119-
env.indexer.state_merkle_trees.remove(0);
118+
// remove the two concurrent Merkle trees
119+
env.indexer.state_merkle_trees.drain(..2);
120120
env.indexer.address_merkle_trees.remove(0);
121121
println!(
122122
"address_merkle_trees {:?}",

program-tests/utils/src/e2e_test_env.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,11 +2701,36 @@ where
27012701
root_indices.as_slice(),
27022702
&mut remaining_accounts,
27032703
);
2704-
let output_compressed_accounts = pack_output_compressed_accounts(
2704+
2705+
// Pack output accounts and track original creation order
2706+
let packed_outputs_with_index = pack_output_compressed_accounts(
27052707
output_accounts.as_slice(),
27062708
output_merkle_trees.as_slice(),
27072709
&mut remaining_accounts,
2710+
)
2711+
.into_iter()
2712+
.enumerate()
2713+
.collect::<Vec<_>>();
2714+
2715+
// Sort by merkle_tree_index while tracking original indices
2716+
let mut sorted_outputs = packed_outputs_with_index.clone();
2717+
sorted_outputs.sort_by_key(|(_, account)| account.merkle_tree_index);
2718+
2719+
// Create mapping: creation_order_index -> sorted_index
2720+
let mut creation_to_sorted_index = vec![0usize; sorted_outputs.len()];
2721+
for (sorted_idx, (creation_idx, _)) in sorted_outputs.iter().enumerate() {
2722+
creation_to_sorted_index[*creation_idx] = sorted_idx;
2723+
}
2724+
println!(
2725+
"creation_to_sorted_index mapping: {:?}",
2726+
creation_to_sorted_index
27082727
);
2728+
2729+
let output_compressed_accounts = sorted_outputs
2730+
.into_iter()
2731+
.map(|(_, account)| account)
2732+
.collect::<Vec<_>>();
2733+
27092734
println!(
27102735
"output_compressed_accounts: {:?}",
27112736
output_compressed_accounts
@@ -2734,13 +2759,15 @@ where
27342759
);
27352760
let mut new_address_params = Vec::new();
27362761
for (index, new_address_param) in invoke_cpi.new_address_params.into_iter().enumerate() {
2737-
if let Some((_, account_index)) = new_address_indices
2762+
if let Some((_, creation_order_idx)) = new_address_indices
27382763
.iter()
27392764
.find(|(address_index, _)| *address_index == index)
27402765
{
2766+
// Map creation order index to sorted index
2767+
let sorted_idx = creation_to_sorted_index[*creation_order_idx as usize];
27412768
new_address_params.push(NewAddressParamsAssignedPacked::new(
27422769
new_address_param,
2743-
Some(*account_index),
2770+
Some(sorted_idx.try_into().unwrap()),
27442771
));
27452772
} else {
27462773
new_address_params

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn parse_invoke_instruction(data: &[u8], accounts: &[AccountMeta]) -> Instructio
255255
merkle_tree_index: Some(param.address_merkle_tree_account_index),
256256
root_index: Some(param.address_merkle_tree_root_index),
257257
derived_address: None,
258+
assigned_account_index: super::types::AddressAssignment::V1,
258259
})
259260
.collect(),
260261
)
@@ -399,6 +400,7 @@ fn parse_invoke_cpi_instruction(data: &[u8], accounts: &[AccountMeta]) -> Instru
399400
merkle_tree_index: Some(param.address_merkle_tree_account_index),
400401
root_index: Some(param.address_merkle_tree_root_index),
401402
derived_address: None,
403+
assigned_account_index: super::types::AddressAssignment::V1,
402404
})
403405
.collect(),
404406
)
@@ -538,6 +540,11 @@ fn parse_invoke_cpi_readonly_instruction(
538540
merkle_tree_index: Some(param.address_merkle_tree_account_index),
539541
root_index: Some(param.address_merkle_tree_root_index),
540542
derived_address: None,
543+
assigned_account_index: if param.assigned_to_account {
544+
super::types::AddressAssignment::AssignedIndex(param.assigned_account_index)
545+
} else {
546+
super::types::AddressAssignment::None
547+
},
541548
});
542549
}
543550

@@ -549,6 +556,7 @@ fn parse_invoke_cpi_readonly_instruction(
549556
merkle_tree_index: Some(readonly_addr.address_merkle_tree_account_index),
550557
root_index: Some(readonly_addr.address_merkle_tree_root_index),
551558
derived_address: Some(readonly_addr.address),
559+
assigned_account_index: super::types::AddressAssignment::None,
552560
});
553561
}
554562

@@ -684,6 +692,11 @@ fn parse_invoke_cpi_account_info_instruction(
684692
merkle_tree_index: Some(param.address_merkle_tree_account_index),
685693
root_index: Some(param.address_merkle_tree_root_index),
686694
derived_address: None,
695+
assigned_account_index: if param.assigned_to_account {
696+
super::types::AddressAssignment::AssignedIndex(param.assigned_account_index)
697+
} else {
698+
super::types::AddressAssignment::None
699+
},
687700
});
688701
}
689702

@@ -695,6 +708,7 @@ fn parse_invoke_cpi_account_info_instruction(
695708
merkle_tree_index: Some(readonly_addr.address_merkle_tree_account_index),
696709
root_index: Some(readonly_addr.address_merkle_tree_root_index),
697710
derived_address: Some(readonly_addr.address),
711+
assigned_account_index: super::types::AddressAssignment::None,
698712
});
699713
}
700714

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,26 @@ impl TransactionFormatter {
922922
self.colors.reset
923923
)?;
924924
}
925+
let assignment_str = match addr_param.assigned_account_index {
926+
super::types::AddressAssignment::AssignedIndex(idx) => {
927+
format!("{}", idx)
928+
}
929+
super::types::AddressAssignment::None => {
930+
"none".to_string()
931+
}
932+
super::types::AddressAssignment::V1 => {
933+
"n/a (v1)".to_string()
934+
}
935+
};
936+
writeln!(
937+
output,
938+
"{} {}assigned_to_output_account: {}{}{}",
939+
indent,
940+
self.colors.gray,
941+
self.colors.yellow,
942+
assignment_str,
943+
self.colors.reset
944+
)?;
925945
}
926946
}
927947

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ pub struct FeeSummary {
106106
pub compression_fee: Option<u64>,
107107
}
108108

109+
/// Address assignment state
110+
#[derive(Debug, Clone)]
111+
pub enum AddressAssignment {
112+
/// V1 address param (no assignment tracking)
113+
V1,
114+
/// Not assigned to any output account
115+
None,
116+
/// Assigned to output account at index
117+
AssignedIndex(u8),
118+
}
119+
109120
/// Address parameter information
110121
#[derive(Debug, Clone)]
111122
pub struct AddressParam {
@@ -114,6 +125,7 @@ pub struct AddressParam {
114125
pub merkle_tree_index: Option<u8>,
115126
pub root_index: Option<u16>,
116127
pub derived_address: Option<[u8; 32]>,
128+
pub assigned_account_index: AddressAssignment,
117129
}
118130

119131
/// Input account data

0 commit comments

Comments
 (0)