github.com/decred/dcrlnd@v0.7.6/netann/channel_announcement_test.go (about)

     1  package netann
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/decred/dcrd/chaincfg/chainhash"
     8  	"github.com/decred/dcrd/dcrutil/v4"
     9  	"github.com/decred/dcrd/wire"
    10  	"github.com/decred/dcrlnd/channeldb"
    11  	"github.com/decred/dcrlnd/lnwire"
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestCreateChanAnnouncement(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	key := [33]byte{0x1}
    19  	sig := lnwire.Sig{0x1}
    20  	features := lnwire.NewRawFeatureVector(lnwire.AnchorsRequired)
    21  	var featuresBuf bytes.Buffer
    22  	if err := features.Encode(&featuresBuf); err != nil {
    23  		t.Fatalf("unable to encode features: %v", err)
    24  	}
    25  
    26  	expChanAnn := &lnwire.ChannelAnnouncement{
    27  		ChainHash:       chainhash.Hash{0x1},
    28  		ShortChannelID:  lnwire.ShortChannelID{BlockHeight: 1},
    29  		NodeID1:         key,
    30  		NodeID2:         key,
    31  		NodeSig1:        sig,
    32  		NodeSig2:        sig,
    33  		DecredKey1:      key,
    34  		DecredKey2:      key,
    35  		DecredSig1:      sig,
    36  		DecredSig2:      sig,
    37  		Features:        features,
    38  		ExtraOpaqueData: []byte{0x1},
    39  	}
    40  
    41  	chanProof := &channeldb.ChannelAuthProof{
    42  		NodeSig1Bytes:   expChanAnn.NodeSig1.ToSignatureBytes(),
    43  		NodeSig2Bytes:   expChanAnn.NodeSig2.ToSignatureBytes(),
    44  		DecredSig1Bytes: expChanAnn.DecredSig1.ToSignatureBytes(),
    45  		DecredSig2Bytes: expChanAnn.DecredSig2.ToSignatureBytes(),
    46  	}
    47  	chanInfo := &channeldb.ChannelEdgeInfo{
    48  		ChainHash:       expChanAnn.ChainHash,
    49  		ChannelID:       expChanAnn.ShortChannelID.ToUint64(),
    50  		ChannelPoint:    wire.OutPoint{Index: 1},
    51  		Capacity:        dcrutil.AtomsPerCoin,
    52  		NodeKey1Bytes:   key,
    53  		NodeKey2Bytes:   key,
    54  		DecredKey1Bytes: key,
    55  		DecredKey2Bytes: key,
    56  		Features:        featuresBuf.Bytes(),
    57  		ExtraOpaqueData: expChanAnn.ExtraOpaqueData,
    58  	}
    59  	chanAnn, _, _, err := CreateChanAnnouncement(
    60  		chanProof, chanInfo, nil, nil,
    61  	)
    62  	if err != nil {
    63  		t.Fatalf("unable to create channel announcement: %v", err)
    64  	}
    65  
    66  	assert.Equal(t, chanAnn, expChanAnn)
    67  }