Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions lnwire/onion_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ import (
)

var (
testOnionHash = [OnionPacketSize]byte{}
testAmount = MilliSatoshi(1)
testCtlvExpiry = uint32(2)
testFlags = uint16(2)
testType = uint64(3)
testOffset = uint16(24)
sig, _ = NewSigFromSignature(testSig)
testChannelUpdate = ChannelUpdate1{
testOnionHash = [OnionPacketSize]byte{}
testAmount = MilliSatoshi(1)
testCtlvExpiry = uint32(2)
testFlags = uint16(2)
testType = uint64(3)
testOffset = uint16(24)
sig, _ = NewSigFromSignature(testSig)
)

func makeTestChannelUpdate() *ChannelUpdate1 {
return &ChannelUpdate1{
Signature: sig,
ShortChannelID: NewShortChanIDFromInt(1),
Timestamp: 1,
MessageFlags: 0,
ChannelFlags: 1,
ExtraOpaqueData: make([]byte, 0),
}
)
}

var onionFailures = []FailureMessage{
&FailInvalidRealm{},
Expand All @@ -47,13 +50,13 @@ var onionFailures = []FailureMessage{
NewInvalidOnionVersion(testOnionHash[:]),
NewInvalidOnionHmac(testOnionHash[:]),
NewInvalidOnionKey(testOnionHash[:]),
NewTemporaryChannelFailure(&testChannelUpdate),
NewTemporaryChannelFailure(makeTestChannelUpdate()),
NewTemporaryChannelFailure(nil),
NewAmountBelowMinimum(testAmount, testChannelUpdate),
NewFeeInsufficient(testAmount, testChannelUpdate),
NewIncorrectCltvExpiry(testCtlvExpiry, testChannelUpdate),
NewExpiryTooSoon(testChannelUpdate),
NewChannelDisabled(testFlags, testChannelUpdate),
NewAmountBelowMinimum(testAmount, *makeTestChannelUpdate()),
NewFeeInsufficient(testAmount, *makeTestChannelUpdate()),
NewIncorrectCltvExpiry(testCtlvExpiry, *makeTestChannelUpdate()),
NewExpiryTooSoon(*makeTestChannelUpdate()),
NewChannelDisabled(testFlags, *makeTestChannelUpdate()),
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
NewFinalIncorrectHtlcAmount(testAmount),
NewInvalidOnionPayload(testType, testOffset),
Expand Down Expand Up @@ -128,6 +131,8 @@ func testEncodeDecodeTlv(t *testing.T, testFailure FailureMessage) {
func TestChannelUpdateCompatibilityParsing(t *testing.T) {
t.Parallel()

testChannelUpdate := *makeTestChannelUpdate()

// We'll start by taking out test channel update, and encoding it into
// a set of raw bytes.
var b bytes.Buffer
Expand All @@ -146,9 +151,7 @@ func TestChannelUpdateCompatibilityParsing(t *testing.T) {

// At this point, we'll ensure that we get the exact same failure out
// on the other side.
if !reflect.DeepEqual(testChannelUpdate, newChanUpdate) {
t.Fatalf("mismatched channel updates: %v", err)
}
require.Equal(t, testChannelUpdate, newChanUpdate)

// We'll now reset then re-encoded the same channel update to try it in
// the proper compatible mode.
Expand Down Expand Up @@ -185,7 +188,7 @@ func TestWriteOnionErrorChanUpdate(t *testing.T) {
// First, we'll write out the raw channel update so we can obtain the
// raw serialized length.
var b bytes.Buffer
update := testChannelUpdate
update := *makeTestChannelUpdate()
trueUpdateLength, err := WriteMessage(&b, &update, 0)
if err != nil {
t.Fatalf("unable to write update: %v", err)
Expand Down
Loading