channeldb: remove time.Now() from tests

This commit is contained in:
Andras Banki-Horvath committed 2020-01-08 16:51:51 +01:00
1 parent ec6c0689ef
commit 4136b18e3d
1 file changed
+6 -7
+6 -7
View File
@@ -14,6 +14,7 @@ import (
var ( var (
emptyFeatures = lnwire.NewFeatureVector(nil, lnwire.Features) emptyFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
testNow = time.Unix(1, 0)
) )
func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) { func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
@@ -23,9 +24,7 @@ func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) {
} }
i := &Invoice{ i := &Invoice{
// Use single second precision to avoid false positive test CreationDate: testNow,
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Terms: ContractTerm{ Terms: ContractTerm{
Expiry: 4000, Expiry: 4000,
PaymentPreimage: pre, PaymentPreimage: pre,
@@ -87,9 +86,7 @@ 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{
// Use single second precision to avoid false positive test CreationDate: testNow,
// failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0),
Htlcs: map[CircuitKey]*InvoiceHTLC{}, Htlcs: map[CircuitKey]*InvoiceHTLC{},
} }
fakeInvoice.Memo = []byte("memo") fakeInvoice.Memo = []byte("memo")
@@ -285,6 +282,7 @@ func TestInvoiceAddTimeSeries(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to make test db: %v", err) t.Fatalf("unable to make test db: %v", err)
} }
db.Now = func() time.Time { return testNow }
// We'll start off by creating 20 random invoices, and inserting them // We'll start off by creating 20 random invoices, and inserting them
// into the database. // into the database.
@@ -537,7 +535,7 @@ func TestDuplicateSettleInvoice(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to make test db: %v", err) t.Fatalf("unable to make test db: %v", err)
} }
db.Now = func() time.Time { return time.Unix(1, 0) } db.Now = func() time.Time { return testNow }
// We'll start out by creating an invoice and writing it to the DB. // We'll start out by creating an invoice and writing it to the DB.
amt := lnwire.NewMSatFromSatoshis(1000) amt := lnwire.NewMSatFromSatoshis(1000)
@@ -675,6 +673,7 @@ func TestQueryInvoices(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unable to make test db: %v", err) t.Fatalf("unable to make test db: %v", err)
} }
db.Now = func() time.Time { return testNow }
// To begin the test, we'll add 50 invoices to the database. We'll // To begin the test, we'll add 50 invoices to the database. We'll
// assume that the index of the invoice within the database is the same // assume that the index of the invoice within the database is the same