From 98f5a077f4a5c5921ce6e714d91b276d5c813f8a Mon Sep 17 00:00:00 2001 From: joshuakrueger-dfx Date: Wed, 3 Jun 2026 23:39:47 +0200 Subject: [PATCH] fix(tx): return short transaction ids whole instead of a RangeError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit asShortTxId did substring(0, 10) + substring(length - 10) unconditionally, so any id shorter than 10 chars crashed with a RangeError and ids 10–19 chars long overlapped head/tail. Return the id whole when it is no longer than the elided form (23 chars). Regression: test/packages/service/transaction_history_service_test.dart Issue #657 — Part 9, finding L1. --- lib/packages/service/transaction_history_service.dart | 4 ++++ .../service/transaction_history_service_test.dart | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/packages/service/transaction_history_service.dart b/lib/packages/service/transaction_history_service.dart index 2212fa5d..8b0013f6 100644 --- a/lib/packages/service/transaction_history_service.dart +++ b/lib/packages/service/transaction_history_service.dart @@ -129,6 +129,10 @@ extension ToEpiAddress on String { String get asHexEip55 => EthereumAddress.fromHex(this).hexEip55; String get asShortTxId { + // A txid shorter than the elided form (10 + "..." + 10 = 23) is returned + // whole: slicing it would throw a RangeError for length < 10 and overlap + // the head/tail for length < 20 (issue #657 P9 L1). + if (length <= 23) return this; return '${substring(0, 10)}...${substring(length - 10)}'; } } diff --git a/test/packages/service/transaction_history_service_test.dart b/test/packages/service/transaction_history_service_test.dart index ada4cebb..7270c5ea 100644 --- a/test/packages/service/transaction_history_service_test.dart +++ b/test/packages/service/transaction_history_service_test.dart @@ -177,5 +177,15 @@ void main() { expect(txid.asShortTxId.contains('...'), isTrue); expect(txid.asShortTxId.length, 23); // 10 + 3 + 10 }); + + test('asShortTxId returns a short id whole without a RangeError ' + '(issue #657 P9 L1 regression)', () { + // Anything not longer than the elided form is shown whole; the old code + // crashed with a RangeError on substring(0, 10) / substring(length - 10) + // for these inputs. + expect('0xabc'.asShortTxId, '0xabc'); + expect(''.asShortTxId, ''); + expect('0x12345678'.asShortTxId, '0x12345678'); // length 10, would overlap + }); }); }