Skip to content

Commit 7857d2c

Browse files
authored
Merge pull request #9969 from ellemouton/fixLnwireTestDataRace
lnwire: fix test data race
2 parents 5e9e182 + 667e0aa commit 7857d2c

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

lnwire/onion_error_test.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@ import (
1414
)
1515

1616
var (
17-
testOnionHash = [OnionPacketSize]byte{}
18-
testAmount = MilliSatoshi(1)
19-
testCtlvExpiry = uint32(2)
20-
testFlags = uint16(2)
21-
testType = uint64(3)
22-
testOffset = uint16(24)
23-
sig, _ = NewSigFromSignature(testSig)
24-
testChannelUpdate = ChannelUpdate1{
17+
testOnionHash = [OnionPacketSize]byte{}
18+
testAmount = MilliSatoshi(1)
19+
testCtlvExpiry = uint32(2)
20+
testFlags = uint16(2)
21+
testType = uint64(3)
22+
testOffset = uint16(24)
23+
sig, _ = NewSigFromSignature(testSig)
24+
)
25+
26+
func makeTestChannelUpdate() *ChannelUpdate1 {
27+
return &ChannelUpdate1{
2528
Signature: sig,
2629
ShortChannelID: NewShortChanIDFromInt(1),
2730
Timestamp: 1,
2831
MessageFlags: 0,
2932
ChannelFlags: 1,
3033
ExtraOpaqueData: make([]byte, 0),
3134
}
32-
)
35+
}
3336

3437
var onionFailures = []FailureMessage{
3538
&FailInvalidRealm{},
@@ -47,13 +50,13 @@ var onionFailures = []FailureMessage{
4750
NewInvalidOnionVersion(testOnionHash[:]),
4851
NewInvalidOnionHmac(testOnionHash[:]),
4952
NewInvalidOnionKey(testOnionHash[:]),
50-
NewTemporaryChannelFailure(&testChannelUpdate),
53+
NewTemporaryChannelFailure(makeTestChannelUpdate()),
5154
NewTemporaryChannelFailure(nil),
52-
NewAmountBelowMinimum(testAmount, testChannelUpdate),
53-
NewFeeInsufficient(testAmount, testChannelUpdate),
54-
NewIncorrectCltvExpiry(testCtlvExpiry, testChannelUpdate),
55-
NewExpiryTooSoon(testChannelUpdate),
56-
NewChannelDisabled(testFlags, testChannelUpdate),
55+
NewAmountBelowMinimum(testAmount, *makeTestChannelUpdate()),
56+
NewFeeInsufficient(testAmount, *makeTestChannelUpdate()),
57+
NewIncorrectCltvExpiry(testCtlvExpiry, *makeTestChannelUpdate()),
58+
NewExpiryTooSoon(*makeTestChannelUpdate()),
59+
NewChannelDisabled(testFlags, *makeTestChannelUpdate()),
5760
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
5861
NewFinalIncorrectHtlcAmount(testAmount),
5962
NewInvalidOnionPayload(testType, testOffset),
@@ -128,6 +131,8 @@ func testEncodeDecodeTlv(t *testing.T, testFailure FailureMessage) {
128131
func TestChannelUpdateCompatibilityParsing(t *testing.T) {
129132
t.Parallel()
130133

134+
testChannelUpdate := *makeTestChannelUpdate()
135+
131136
// We'll start by taking out test channel update, and encoding it into
132137
// a set of raw bytes.
133138
var b bytes.Buffer
@@ -146,9 +151,7 @@ func TestChannelUpdateCompatibilityParsing(t *testing.T) {
146151

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

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

0 commit comments

Comments
 (0)