2017-01-31 05:45:28 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFundingLockedWire(t *testing.T) {
|
|
|
|
// First create a new FundingLocked message.
|
2017-04-17 01:22:20 +03:00
|
|
|
fl := NewFundingLocked(ChannelID(revHash), pubKey)
|
2017-01-31 05:45:28 +03:00
|
|
|
|
|
|
|
// Next encode the FundingLocked message into an empty bytes buffer.
|
|
|
|
var b bytes.Buffer
|
|
|
|
if err := fl.Encode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to encode FundingLocked: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to ensure that the FundingLocked message is the correct size.
|
|
|
|
if uint32(b.Len()) > fl.MaxPayloadLength(0) {
|
|
|
|
t.Fatalf("length of FundingLocked message is too long: %v should be less than %v",
|
|
|
|
b.Len(), fl.MaxPayloadLength(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deserialize the encoded FundingLocked message into an empty struct.
|
|
|
|
fl2 := &FundingLocked{}
|
|
|
|
if err := fl2.Decode(&b, 0); err != nil {
|
|
|
|
t.Fatalf("unable to decode FundingLocked: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert equality of the two instances
|
|
|
|
if !reflect.DeepEqual(fl, fl2) {
|
|
|
|
t.Fatalf("encode/decode error messages don't match %#v vs %#v", fl, fl2)
|
|
|
|
}
|
|
|
|
}
|