@@ -1774,3 +1774,49 @@ func TestBatch_DeleteADVEntries(t *testing.T) {
17741774 require .Len (t , b .ADVEntries , 1 )
17751775 require .Equal (t , "1" , b .ADVEntries [0 ].ID )
17761776}
1777+
1778+ func TestBatch_upsertOffsets_PanicRegression (t * testing.T ) {
1779+ batch := NewBatchWEB (& BatchHeader {
1780+ ServiceClassCode : MixedDebitsAndCredits ,
1781+ StandardEntryClassCode : "WEB" ,
1782+ CompanyName : "Test" ,
1783+ CompanyIdentification : "123456789" ,
1784+ })
1785+
1786+ // Add 3 normal entries
1787+ for i := 0 ; i < 3 ; i ++ {
1788+ batch .AddEntry (& EntryDetail {
1789+ TransactionCode : CheckingDebit ,
1790+ RDFIIdentification : "12345678" ,
1791+ Amount : 100 ,
1792+ IndividualName : "User" ,
1793+ })
1794+ }
1795+
1796+ // Add offset as last entry (this triggered the i+i bug)
1797+ batch .AddEntry (& EntryDetail {
1798+ TransactionCode : CheckingCredit ,
1799+ RDFIIdentification : "98765432" ,
1800+ Amount : 300 ,
1801+ IndividualName : offsetIndividualName ,
1802+ })
1803+
1804+ // Setup control
1805+ batch .Control = & BatchControl {
1806+ TotalDebitEntryDollarAmount : 300 ,
1807+ TotalCreditEntryDollarAmount : 300 ,
1808+ EntryAddendaCount : 4 ,
1809+ }
1810+
1811+ batch .offset = & Offset {
1812+ RoutingNumber : "987654320" ,
1813+ AccountNumber : "123456" ,
1814+ AccountType : OffsetChecking ,
1815+ }
1816+
1817+ require .NotPanics (t , func () {
1818+ batch .upsertOffsets ()
1819+ })
1820+
1821+ require .Len (t , batch .Entries , 4 )
1822+ }
0 commit comments