Merge pull request #9969 from ellemouton/fixLnwireTestDataRace
lnwire: fix test data race
This commit is contained in:
1 file changed
+22
-19
+22
-19
@@ -14,14 +14,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testOnionHash = [OnionPacketSize]byte{}
|
testOnionHash = [OnionPacketSize]byte{}
|
||||||
testAmount = MilliSatoshi(1)
|
testAmount = MilliSatoshi(1)
|
||||||
testCtlvExpiry = uint32(2)
|
testCtlvExpiry = uint32(2)
|
||||||
testFlags = uint16(2)
|
testFlags = uint16(2)
|
||||||
testType = uint64(3)
|
testType = uint64(3)
|
||||||
testOffset = uint16(24)
|
testOffset = uint16(24)
|
||||||
sig, _ = NewSigFromSignature(testSig)
|
sig, _ = NewSigFromSignature(testSig)
|
||||||
testChannelUpdate = ChannelUpdate1{
|
)
|
||||||
|
|
||||||
|
func makeTestChannelUpdate() *ChannelUpdate1 {
|
||||||
|
return &ChannelUpdate1{
|
||||||
Signature: sig,
|
Signature: sig,
|
||||||
ShortChannelID: NewShortChanIDFromInt(1),
|
ShortChannelID: NewShortChanIDFromInt(1),
|
||||||
Timestamp: 1,
|
Timestamp: 1,
|
||||||
@@ -29,7 +32,7 @@ var (
|
|||||||
ChannelFlags: 1,
|
ChannelFlags: 1,
|
||||||
ExtraOpaqueData: make([]byte, 0),
|
ExtraOpaqueData: make([]byte, 0),
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
var onionFailures = []FailureMessage{
|
var onionFailures = []FailureMessage{
|
||||||
&FailInvalidRealm{},
|
&FailInvalidRealm{},
|
||||||
@@ -47,13 +50,13 @@ var onionFailures = []FailureMessage{
|
|||||||
NewInvalidOnionVersion(testOnionHash[:]),
|
NewInvalidOnionVersion(testOnionHash[:]),
|
||||||
NewInvalidOnionHmac(testOnionHash[:]),
|
NewInvalidOnionHmac(testOnionHash[:]),
|
||||||
NewInvalidOnionKey(testOnionHash[:]),
|
NewInvalidOnionKey(testOnionHash[:]),
|
||||||
NewTemporaryChannelFailure(&testChannelUpdate),
|
NewTemporaryChannelFailure(makeTestChannelUpdate()),
|
||||||
NewTemporaryChannelFailure(nil),
|
NewTemporaryChannelFailure(nil),
|
||||||
NewAmountBelowMinimum(testAmount, testChannelUpdate),
|
NewAmountBelowMinimum(testAmount, *makeTestChannelUpdate()),
|
||||||
NewFeeInsufficient(testAmount, testChannelUpdate),
|
NewFeeInsufficient(testAmount, *makeTestChannelUpdate()),
|
||||||
NewIncorrectCltvExpiry(testCtlvExpiry, testChannelUpdate),
|
NewIncorrectCltvExpiry(testCtlvExpiry, *makeTestChannelUpdate()),
|
||||||
NewExpiryTooSoon(testChannelUpdate),
|
NewExpiryTooSoon(*makeTestChannelUpdate()),
|
||||||
NewChannelDisabled(testFlags, testChannelUpdate),
|
NewChannelDisabled(testFlags, *makeTestChannelUpdate()),
|
||||||
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
|
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
|
||||||
NewFinalIncorrectHtlcAmount(testAmount),
|
NewFinalIncorrectHtlcAmount(testAmount),
|
||||||
NewInvalidOnionPayload(testType, testOffset),
|
NewInvalidOnionPayload(testType, testOffset),
|
||||||
@@ -128,6 +131,8 @@ func testEncodeDecodeTlv(t *testing.T, testFailure FailureMessage) {
|
|||||||
func TestChannelUpdateCompatibilityParsing(t *testing.T) {
|
func TestChannelUpdateCompatibilityParsing(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
testChannelUpdate := *makeTestChannelUpdate()
|
||||||
|
|
||||||
// We'll start by taking out test channel update, and encoding it into
|
// We'll start by taking out test channel update, and encoding it into
|
||||||
// a set of raw bytes.
|
// a set of raw bytes.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
@@ -146,9 +151,7 @@ func TestChannelUpdateCompatibilityParsing(t *testing.T) {
|
|||||||
|
|
||||||
// At this point, we'll ensure that we get the exact same failure out
|
// At this point, we'll ensure that we get the exact same failure out
|
||||||
// on the other side.
|
// on the other side.
|
||||||
if !reflect.DeepEqual(testChannelUpdate, newChanUpdate) {
|
require.Equal(t, testChannelUpdate, newChanUpdate)
|
||||||
t.Fatalf("mismatched channel updates: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We'll now reset then re-encoded the same channel update to try it in
|
// We'll now reset then re-encoded the same channel update to try it in
|
||||||
// the proper compatible mode.
|
// the proper compatible mode.
|
||||||
@@ -185,7 +188,7 @@ func TestWriteOnionErrorChanUpdate(t *testing.T) {
|
|||||||
// First, we'll write out the raw channel update so we can obtain the
|
// First, we'll write out the raw channel update so we can obtain the
|
||||||
// raw serialized length.
|
// raw serialized length.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
update := testChannelUpdate
|
update := *makeTestChannelUpdate()
|
||||||
trueUpdateLength, err := WriteMessage(&b, &update, 0)
|
trueUpdateLength, err := WriteMessage(&b, &update, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to write update: %v", err)
|
t.Fatalf("unable to write update: %v", err)
|
||||||
|
|||||||
Reference in new issue
Block a user