lnwire: Add upfront shutdown messages and feature bit
This commit adds the feature bit and additional fields required in `open_channel` and `accept_channel` wire messages for `option_upfront_shutdown_script`.
This commit is contained in:
1 parent
db21c394b2
commit
2fb7172725
8 files changed
+198
-21
No files matched your search
@@ -0,0 +1,71 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
)
|
||||
|
||||
// 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(btcec.S256())
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user