channeldb: Fix payment serialization tests.

This modifies the tests that deal serializing the Invoice type to limit
the creation date to seconds since Go1.9 added the concept of a
monotonic component to times which does not round trip through
MarshalBinary and UnmarshalBinary and therefore causes the tests to fail.

In particular, it modifies the creation dates in the randInvoice,
makeFakePayment, makeRandomFakePayment, and TestInvoiceWorkflow
functions.

This results in allowing TestOutgoingPaymentSerialization,
TestOutgoingPaymentWorkflow, and TestInvoiceWorkflow to pass.
This commit is contained in:
Dave Collins 2017-08-28 22:04:06 -05:00 committed by Olaoluwa Osuntokun
parent 42a263b29f
commit 916ab454c1
2 changed files with 12 additions and 5 deletions

@ -12,14 +12,15 @@ import (
) )
func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) { func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
var pre [32]byte var pre [32]byte
if _, err := rand.Read(pre[:]); err != nil { if _, err := rand.Read(pre[:]); err != nil {
return nil, err return nil, err
} }
i := &Invoice{ i := &Invoice{
CreationDate: time.Now(), // Use single second precision to avoid false positive test
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Terms: ContractTerm{ Terms: ContractTerm{
PaymentPreimage: pre, PaymentPreimage: pre,
Value: value, Value: value,
@ -43,7 +44,9 @@ func TestInvoiceWorkflow(t *testing.T) {
// Create a fake invoice which we'll use several times in the tests // Create a fake invoice which we'll use several times in the tests
// below. // below.
fakeInvoice := &Invoice{ fakeInvoice := &Invoice{
CreationDate: time.Now(), // Use single second precision to avoid false positive test
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
} }
fakeInvoice.Memo = []byte("memo") fakeInvoice.Memo = []byte("memo")
fakeInvoice.Receipt = []byte("recipt") fakeInvoice.Receipt = []byte("recipt")

@ -15,7 +15,9 @@ import (
func makeFakePayment() *OutgoingPayment { func makeFakePayment() *OutgoingPayment {
fakeInvoice := &Invoice{ fakeInvoice := &Invoice{
CreationDate: time.Now(), // Use single second precision to avoid false positive test
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Memo: []byte("fake memo"), Memo: []byte("fake memo"),
Receipt: []byte("fake receipt"), Receipt: []byte("fake receipt"),
} }
@ -52,7 +54,9 @@ func randomBytes(minLen, maxLen int) ([]byte, error) {
func makeRandomFakePayment() (*OutgoingPayment, error) { func makeRandomFakePayment() (*OutgoingPayment, error) {
var err error var err error
fakeInvoice := &Invoice{ fakeInvoice := &Invoice{
CreationDate: time.Now(), // Use single second precision to avoid false positive test
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
} }
fakeInvoice.Memo, err = randomBytes(1, 50) fakeInvoice.Memo, err = randomBytes(1, 50)