lnd/lnwire/accept_channel_test.go
Oliver Gugger 7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00

73 lines
1.6 KiB
Go

package lnwire
import (
"bytes"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
)
// TestDecodeAcceptChannel tests decoding of an accept channel wire message with
// and without the optional upfront shutdown script.
func TestDecodeAcceptChannel(t *testing.T) {
tests := []struct {
name string
shutdownScript DeliveryAddress
}{
{
name: "no upfront shutdown script",
shutdownScript: nil,
},
{
name: "empty byte array",
shutdownScript: []byte{},
},
{
name: "upfront shutdown script set",
shutdownScript: []byte("example"),
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
priv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("cannot create privkey: %v", err)
}
pk := priv.PubKey()
encoded := &AcceptChannel{
PendingChannelID: [32]byte{},
FundingKey: pk,
RevocationPoint: pk,
PaymentPoint: pk,
DelayedPaymentPoint: pk,
HtlcPoint: pk,
FirstCommitmentPoint: pk,
UpfrontShutdownScript: test.shutdownScript,
}
buf := &bytes.Buffer{}
if _, err := WriteMessage(buf, encoded, 0); err != nil {
t.Fatalf("cannot write message: %v", err)
}
msg, err := ReadMessage(buf, 0)
if err != nil {
t.Fatalf("cannot read message: %v", err)
}
decoded := msg.(*AcceptChannel)
if !bytes.Equal(
decoded.UpfrontShutdownScript, encoded.UpfrontShutdownScript,
) {
t.Fatalf("decoded script: %x does not equal encoded script: %x",
decoded.UpfrontShutdownScript, encoded.UpfrontShutdownScript)
}
})
}
}