lnd/lnwire/ping_test.go
Erick Cestari aca27e27f5
lint: remove redundant loop var copies in test files
Since Go 1.22 loop variables are scoped per-iteration, so the
`x := x` / `a, b := a, b` copies inside range/for loops are no longer
needed. This removes the existing redundant copies in test files.
2026-06-03 15:32:45 -03:00

50 lines
1.3 KiB
Go

package lnwire
import (
"bytes"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
// TestPingDecodeAllowsNoReplyPongSizes asserts that ping messages using the
// BOLT 1 no-reply sentinel range still deserialize successfully.
func TestPingDecodeAllowsNoReplyPongSizes(t *testing.T) {
t.Parallel()
// Arrange: Pick values from the BOLT 1 no-reply range. These
// pings are valid on the wire and should decode successfully
// even though they do not require a pong response.
testCases := []uint16{65532, 65535}
for _, numPongBytes := range testCases {
testName := strconv.FormatUint(uint64(numPongBytes), 10)
t.Run(testName, func(t *testing.T) {
// Arrange: Encode a ping carrying a no-reply pong
// size together with a small payload so we exercise
// the normal wire format.
var buf bytes.Buffer
want := &Ping{
NumPongBytes: numPongBytes,
PaddingBytes: PingPayload{1, 2, 3},
}
_, err := WriteMessage(&buf, want, 0)
require.NoError(t, err)
// Act: Decode the serialized message through the
// standard parser.
msg, err := ReadMessage(bytes.NewReader(buf.Bytes()), 0)
require.NoError(t, err)
// Assert: The decoded ping matches the original
// input exactly.
got, ok := msg.(*Ping)
require.True(t, ok)
require.Equal(t, want, got)
})
}
}