channeldb: export now function
To allow mocking when testing other packages.
This commit is contained in:
parent
1371e5affc
commit
e234f88b82
@ -137,7 +137,8 @@ type DB struct {
|
|||||||
*bbolt.DB
|
*bbolt.DB
|
||||||
dbPath string
|
dbPath string
|
||||||
graph *ChannelGraph
|
graph *ChannelGraph
|
||||||
now func() time.Time
|
|
||||||
|
Now func() time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens an existing channeldb. Any necessary schemas migrations due to
|
// Open opens an existing channeldb. Any necessary schemas migrations due to
|
||||||
@ -171,7 +172,7 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
|
|||||||
chanDB := &DB{
|
chanDB := &DB{
|
||||||
DB: bdb,
|
DB: bdb,
|
||||||
dbPath: dbPath,
|
dbPath: dbPath,
|
||||||
now: time.Now,
|
Now: time.Now,
|
||||||
}
|
}
|
||||||
chanDB.graph = newChannelGraph(
|
chanDB.graph = newChannelGraph(
|
||||||
chanDB, opts.RejectCacheSize, opts.ChannelCacheSize,
|
chanDB, opts.RejectCacheSize, opts.ChannelCacheSize,
|
||||||
|
@ -337,7 +337,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 time.Unix(1, 0) }
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -1244,7 +1244,7 @@ func (d *DB) updateInvoice(hash lntypes.Hash, invoices, settleIndex *bbolt.Bucke
|
|||||||
// Update invoice state.
|
// Update invoice state.
|
||||||
invoice.State = update.State
|
invoice.State = update.State
|
||||||
|
|
||||||
now := d.now()
|
now := d.Now()
|
||||||
|
|
||||||
// Update htlc set.
|
// Update htlc set.
|
||||||
for key, htlcUpdate := range update.Htlcs {
|
for key, htlcUpdate := range update.Htlcs {
|
||||||
|
Loading…
Reference in New Issue
Block a user