mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 14:12:27 +02:00
lnwire/reply_channel_range: assert sorted encodings
This commit is contained in:
34
lnwire/reply_channel_range_test.go
Normal file
34
lnwire/reply_channel_range_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestReplyChannelRangeUnsorted tests that decoding a ReplyChannelRange request
|
||||
// that contains duplicate or unsorted ids returns an ErrUnsortedSIDs failure.
|
||||
func TestReplyChannelRangeUnsorted(t *testing.T) {
|
||||
for _, test := range unsortedSidTests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
req := &ReplyChannelRange{
|
||||
EncodingType: test.encType,
|
||||
ShortChanIDs: test.sids,
|
||||
noSort: true,
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
err := req.Encode(&b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to encode req: %v", err)
|
||||
}
|
||||
|
||||
var req2 ReplyChannelRange
|
||||
err = req2.Decode(bytes.NewReader(b.Bytes()), 0)
|
||||
if _, ok := err.(ErrUnsortedSIDs); !ok {
|
||||
t.Fatalf("expected ErrUnsortedSIDs, got: %T",
|
||||
err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user