lnwire: replace all wire msg tests with a single property-based test
This commit does away with all the old manual message equality tests and replace it with a single property-based test that uses the testing/quick package. This test uses a single scenario which MUST hold for all the messages type and all possible messages generated for those types. As a result we are able to do away with all the prior manually generated test data as the fuzzer to scan the input space looking for a message that violates the scenario.
This commit is contained in:
23 files changed
+583
-853
No files matched your search
@@ -1,39 +0,0 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
|
||||
func TestUpdateAddHTLCEncodeDecode(t *testing.T) {
|
||||
// First create a new UPAH message.
|
||||
addReq := &UpdateAddHTLC{
|
||||
ChanID: ChannelID(revHash),
|
||||
ID: 99,
|
||||
Expiry: uint32(144),
|
||||
Amount: btcutil.Amount(123456000),
|
||||
PaymentHash: revHash,
|
||||
}
|
||||
copy(addReq.OnionBlob[:], bytes.Repeat([]byte{23}, OnionPacketSize))
|
||||
|
||||
// Next encode the HTLCAR message into an empty bytes buffer.
|
||||
var b bytes.Buffer
|
||||
if err := addReq.Encode(&b, 0); err != nil {
|
||||
t.Fatalf("unable to encode HTLCAddRequest: %v", err)
|
||||
}
|
||||
|
||||
// Deserialize the encoded UPAH message into a new empty struct.
|
||||
addReq2 := &UpdateAddHTLC{}
|
||||
if err := addReq2.Decode(&b, 0); err != nil {
|
||||
t.Fatalf("unable to decode HTLCAddRequest: %v", err)
|
||||
}
|
||||
|
||||
// Assert equality of the two instances.
|
||||
if !reflect.DeepEqual(addReq, addReq2) {
|
||||
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
||||
addReq, addReq2)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user