From fb7960395aa4cae4bead0769e44981ba53f9374b Mon Sep 17 00:00:00 2001 From: Rachit2323 Date: Sat, 11 Jul 2026 01:44:32 +0530 Subject: [PATCH 1/2] fix: return all transactions when start is None in index get_account_transactions --- rs/ledger_suite/icp/index/src/main.rs | 8 ++-- rs/ledger_suite/icp/index/tests/tests.rs | 41 +++++++++++++++++++ rs/ledger_suite/icrc1/index-ng/src/main.rs | 8 ++-- rs/ledger_suite/icrc1/index-ng/tests/tests.rs | 29 +++++++++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/rs/ledger_suite/icp/index/src/main.rs b/rs/ledger_suite/icp/index/src/main.rs index 79d22cdf0db4..b3c7b7f38141 100644 --- a/rs/ledger_suite/icp/index/src/main.rs +++ b/rs/ledger_suite/icp/index/src/main.rs @@ -659,16 +659,16 @@ fn get_account_identifier_transactions( .max_results .min(icp_ledger::max_blocks_per_request(&PrincipalId::from(msg_caller())) as u64) .min(usize::MAX as u64) as usize; - // TODO: deal with the user setting start to u64::MAX - let start = arg.start.map_or(u64::MAX, |n| n); - let key = account_identifier_block_ids_key(arg.account_identifier, start); + let start = arg.start; + let scan_from = start.unwrap_or(u64::MAX); + let key = account_identifier_block_ids_key(arg.account_identifier, scan_from); let mut settled_transactions = vec![]; let indices = with_account_identifier_block_ids(|account_identifier_block_ids| { account_identifier_block_ids .range(key..) // old txs of the requested account_identifier and skip the start index .take_while(|(k, _)| k.0 == key.0) - .filter(|(k, _)| k.1.0 < start) + .filter(|(k, _)| start.is_none_or(|s| k.1.0 < s)) .take(length) .map(|(k, _)| k.1.0) .collect::>() diff --git a/rs/ledger_suite/icp/index/tests/tests.rs b/rs/ledger_suite/icp/index/tests/tests.rs index 86d4e32c3e01..8b75a25f5267 100644 --- a/rs/ledger_suite/icp/index/tests/tests.rs +++ b/rs/ledger_suite/icp/index/tests/tests.rs @@ -1273,6 +1273,47 @@ fn test_get_account_transactions_start_length() { } } +#[test] +fn test_get_account_identifier_transactions_without_start_matches_unbounded_start() { + let initial_balances = HashMap::new(); + let env = &StateMachine::new(); + let ledger_id = install_ledger(env, initial_balances, default_archive_options()); + let index_id = install_index(env, ledger_id); + + transfer( + env, + ledger_id, + Account { + owner: MINTER_PRINCIPAL.into(), + subaccount: None, + }, + account(1, 0), + 10_000, + ); + transfer( + env, + ledger_id, + Account { + owner: MINTER_PRINCIPAL.into(), + subaccount: None, + }, + account(1, 0), + 20_000, + ); + wait_until_sync_is_completed(env, index_id, ledger_id); + + let without_start = + get_account_identifier_transactions(env, index_id, account(1, 0), None, 100); + let with_unbounded_start = + get_account_identifier_transactions(env, index_id, account(1, 0), Some(u64::MAX), 100); + + assert_eq!(without_start.transactions.len(), 2); + assert_eq!( + without_start.transactions, + with_unbounded_start.transactions + ); +} + #[test] fn test_get_account_identifier_transactions_pagination() { // 10_000 mint transactions to index for the same account_identifier diff --git a/rs/ledger_suite/icrc1/index-ng/src/main.rs b/rs/ledger_suite/icrc1/index-ng/src/main.rs index 0ab6e2124236..114f5933bf3e 100644 --- a/rs/ledger_suite/icrc1/index-ng/src/main.rs +++ b/rs/ledger_suite/icrc1/index-ng/src/main.rs @@ -1268,18 +1268,18 @@ fn get_account_transactions(arg: GetAccountTransactionsArgs) -> GetAccountTransa .expect("The length must be a u64!") .min(with_state(|opts| opts.max_blocks_per_response)) .min(usize::MAX as u64) as usize; - // TODO: deal with the user setting start to u64::MAX let start = arg .start - .map_or(u64::MAX, |n| n.0.to_u64().expect("start must be a u64!")); - let key = account_block_ids_key(arg.account, start); + .map(|n| n.0.to_u64().expect("start must be a u64!")); + let scan_from = start.unwrap_or(u64::MAX); + let key = account_block_ids_key(arg.account, scan_from); let mut transactions = vec![]; let indices = with_account_block_ids(|account_block_ids| { account_block_ids .range(key..) // old txs of the requested account and skip the start index .take_while(|(k, _)| k.0 == key.0) - .filter(|(k, _)| k.1.0 < start) + .filter(|(k, _)| start.is_none_or(|s| k.1.0 < s)) .take(length) .map(|(k, _)| k.1.0) .collect::>() diff --git a/rs/ledger_suite/icrc1/index-ng/tests/tests.rs b/rs/ledger_suite/icrc1/index-ng/tests/tests.rs index 85ce809190ef..d0812bddd9ea 100644 --- a/rs/ledger_suite/icrc1/index-ng/tests/tests.rs +++ b/rs/ledger_suite/icrc1/index-ng/tests/tests.rs @@ -904,6 +904,35 @@ fn test_get_account_transactions_start_length() { } } +#[test] +fn test_get_account_transactions_without_start_matches_unbounded_start() { + let initial_balances = vec![(account(1, 0), 1_000_000_000_000u64)]; + let env = &StateMachine::new(); + let minter = minter_identity().sender().unwrap(); + let ledger_id = install_ledger( + env, + initial_balances, + default_archive_options(), + None, + minter, + ); + let index_id = install_index_ng(env, index_init_arg_without_interval(ledger_id)); + + transfer(env, ledger_id, account(1, 0), account(2, 0), 1_000); + transfer(env, ledger_id, account(1, 0), account(2, 0), 2_000); + wait_until_sync_is_completed(env, index_id, ledger_id); + + let without_start = get_account_transactions(env, index_id, account(1, 0), None, 100); + let with_unbounded_start = + get_account_transactions(env, index_id, account(1, 0), Some(u64::MAX), 100); + + assert_eq!(without_start.transactions.len(), 3); + assert_eq!( + without_start.transactions, + with_unbounded_start.transactions + ); +} + #[test] fn test_get_account_transactions_pagination() { // 10_000 mint transactions to index for the same account. From cd95932ad6f66c4ae749f0385d223e2c1804b42a Mon Sep 17 00:00:00 2001 From: Rachit2323 Date: Sat, 11 Jul 2026 16:07:14 +0530 Subject: [PATCH 2/2] fix: add underscore separator before u64 suffix --- rs/ledger_suite/icrc1/index-ng/tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs/ledger_suite/icrc1/index-ng/tests/tests.rs b/rs/ledger_suite/icrc1/index-ng/tests/tests.rs index d0812bddd9ea..97cfc7ea952a 100644 --- a/rs/ledger_suite/icrc1/index-ng/tests/tests.rs +++ b/rs/ledger_suite/icrc1/index-ng/tests/tests.rs @@ -906,7 +906,7 @@ fn test_get_account_transactions_start_length() { #[test] fn test_get_account_transactions_without_start_matches_unbounded_start() { - let initial_balances = vec![(account(1, 0), 1_000_000_000_000u64)]; + let initial_balances = vec![(account(1, 0), 1_000_000_000_000_u64)]; let env = &StateMachine::new(); let minter = minter_identity().sender().unwrap(); let ledger_id = install_ledger(