Skip to content

Commit 011d819

Browse files
committed
discovery: update chanAnn creation methods to take modifier options
In preparation for adding more modifiers. We want to later add a modifier that will tweak the errors returned by the mock chain once funding transaction validation has been moved to the gossiper.
1 parent b621063 commit 011d819

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

discovery/gossiper_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,26 @@ func signUpdate(nodeKey *btcec.PrivateKey, a *lnwire.ChannelUpdate1) error {
627627
return nil
628628
}
629629

630+
type fundingTxOpts struct {
631+
extraBytes []byte
632+
}
633+
634+
type fundingTxOption func(*fundingTxOpts)
635+
636+
func withExtraBytes(extraBytes []byte) fundingTxOption {
637+
return func(opts *fundingTxOpts) {
638+
opts.extraBytes = extraBytes
639+
}
640+
}
641+
630642
func (ctx *testCtx) createAnnouncementWithoutProof(blockHeight uint32,
631643
key1, key2 *btcec.PublicKey,
632-
extraBytes ...[]byte) *lnwire.ChannelAnnouncement1 {
644+
options ...fundingTxOption) *lnwire.ChannelAnnouncement1 {
645+
646+
var opts fundingTxOpts
647+
for _, opt := range options {
648+
opt(&opts)
649+
}
633650

634651
a := &lnwire.ChannelAnnouncement1{
635652
ShortChannelID: lnwire.ShortChannelID{
@@ -643,27 +660,25 @@ func (ctx *testCtx) createAnnouncementWithoutProof(blockHeight uint32,
643660
copy(a.NodeID2[:], key2.SerializeCompressed())
644661
copy(a.BitcoinKey1[:], bitcoinKeyPub1.SerializeCompressed())
645662
copy(a.BitcoinKey2[:], bitcoinKeyPub2.SerializeCompressed())
646-
if len(extraBytes) == 1 {
647-
a.ExtraOpaqueData = extraBytes[0]
648-
}
663+
a.ExtraOpaqueData = opts.extraBytes
649664

650665
return a
651666
}
652667

653668
func (ctx *testCtx) createRemoteChannelAnnouncement(blockHeight uint32,
654-
extraBytes ...[]byte) (*lnwire.ChannelAnnouncement1, error) {
669+
opts ...fundingTxOption) (*lnwire.ChannelAnnouncement1, error) {
655670

656671
return ctx.createChannelAnnouncement(
657-
blockHeight, remoteKeyPriv1, remoteKeyPriv2, extraBytes...,
672+
blockHeight, remoteKeyPriv1, remoteKeyPriv2, opts...,
658673
)
659674
}
660675

661676
func (ctx *testCtx) createChannelAnnouncement(blockHeight uint32, key1,
662677
key2 *btcec.PrivateKey,
663-
extraBytes ...[]byte) (*lnwire.ChannelAnnouncement1, error) {
678+
opts ...fundingTxOption) (*lnwire.ChannelAnnouncement1, error) {
664679

665680
a := ctx.createAnnouncementWithoutProof(
666-
blockHeight, key1.PubKey(), key2.PubKey(), extraBytes...,
681+
blockHeight, key1.PubKey(), key2.PubKey(), opts...,
667682
)
668683

669684
signer := mock.SingleSigner{Privkey: key1}
@@ -2610,7 +2625,9 @@ func TestExtraDataChannelAnnouncementValidation(t *testing.T) {
26102625
// that we don't know of ourselves, but should still include in the
26112626
// final signature check.
26122627
extraBytes := []byte("gotta validate this still!")
2613-
ca, err := ctx.createRemoteChannelAnnouncement(0, extraBytes)
2628+
ca, err := ctx.createRemoteChannelAnnouncement(
2629+
0, withExtraBytes(extraBytes),
2630+
)
26142631
require.NoError(t, err, "can't create channel announcement")
26152632

26162633
// We'll now send the announcement to the main gossiper. We should be

0 commit comments

Comments
 (0)