Skip to content

Commit 412e05f

Browse files
committed
lnwire: add *OpaqueAddrs case in WriteElements
And then expand the chanbackup unit tests to cover such a case.
1 parent a154891 commit 412e05f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

chanbackup/backup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func TestFetchStaticChanBackups(t *testing.T) {
157157
chanSource.addAddrsForNode(randomChan1.IdentityPub, []net.Addr{addr1})
158158
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr2})
159159
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr3})
160+
chanSource.addAddrsForNode(randomChan2.IdentityPub, []net.Addr{addr4})
160161

161162
// With the channel source populated, we'll now attempt to create a set
162163
// of backups for all the channels. This should succeed, as all items

chanbackup/multi_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ func TestMultiPackUnpack(t *testing.T) {
2222
t.Fatalf("unable to gen channel: %v", err)
2323
}
2424

25-
single := NewSingle(channel, []net.Addr{addr1, addr2, addr3})
25+
single := NewSingle(
26+
channel, []net.Addr{addr1, addr2, addr3, addr4},
27+
)
2628

2729
originalSingles = append(originalSingles, single)
2830
multi.StaticBackups = append(multi.StaticBackups, single)

chanbackup/single_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ var (
4141
OnionService: "3g2upl4pq6kufc4m.onion",
4242
Port: 9735,
4343
}
44+
addr4 = &lnwire.OpaqueAddrs{
45+
// The first byte must be an address type we are not yet aware
46+
// of for it to be a valid OpaqueAddrs.
47+
Payload: []byte{math.MaxUint8, 1, 2, 3, 4},
48+
}
4449
)
4550

4651
func assertSingleEqual(t *testing.T, a, b Single) {
@@ -314,7 +319,9 @@ func TestSinglePackUnpack(t *testing.T) {
314319
channel, err := genRandomOpenChannelShell()
315320
require.NoError(t, err, "unable to gen open channel")
316321

317-
singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2, addr3})
322+
singleChanBackup := NewSingle(
323+
channel, []net.Addr{addr1, addr2, addr3, addr4},
324+
)
318325

319326
keyRing := &lnencrypt.MockKeyRing{}
320327

@@ -639,7 +646,9 @@ func TestSingleUnconfirmedChannel(t *testing.T) {
639646
channel.ShortChannelID.BlockHeight = 0
640647
channel.FundingBroadcastHeight = fundingBroadcastHeight
641648

642-
singleChanBackup := NewSingle(channel, []net.Addr{addr1, addr2, addr3})
649+
singleChanBackup := NewSingle(
650+
channel, []net.Addr{addr1, addr2, addr3, addr4},
651+
)
643652
keyRing := &lnencrypt.MockKeyRing{}
644653

645654
// Pack it and then unpack it again to make sure everything is written

lnwire/lnwire.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ func WriteElement(w *bytes.Buffer, element interface{}) error {
348348
return err
349349
}
350350

351+
case *OpaqueAddrs:
352+
if err := WriteOpaqueAddrs(w, e); err != nil {
353+
return err
354+
}
355+
351356
case []net.Addr:
352357
// First, we'll encode all the addresses into an intermediate
353358
// buffer. We need to do this in order to compute the total

0 commit comments

Comments
 (0)