mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-03 17:26:57 +01:00
wtclient: demo addr iterator panic
This commit adds a test that shows that it is possible to cause the AddressIterator to panic if the `Next` method is ever called twice when the iterator is at the end of its list without Reset first being called.
This commit is contained in:
parent
de80fffa6c
commit
1047514515
1 changed files with 23 additions and 0 deletions
|
@ -216,4 +216,27 @@ func TestAddrIterator(t *testing.T) {
|
|||
iter.ReleaseLock(addr3)
|
||||
require.False(t, iter.HasLocked())
|
||||
})
|
||||
|
||||
t.Run("calling Next twice without Reset panics", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// This defer-function asserts that a panic does occur.
|
||||
defer func() {
|
||||
r := recover()
|
||||
require.NotNilf(t, r, "the code did not panic")
|
||||
}()
|
||||
|
||||
// Initialise the iterator with addr1.
|
||||
iter, err := newAddressIterator(addr1)
|
||||
require.NoError(t, err)
|
||||
|
||||
a1 := iter.Peek()
|
||||
require.Equal(t, addr1, a1)
|
||||
|
||||
_, err = iter.Next()
|
||||
require.ErrorIs(t, err, ErrAddressesExhausted)
|
||||
|
||||
_, err = iter.Next()
|
||||
require.ErrorIs(t, err, ErrAddressesExhausted)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue