From 9643b45dbc622116f6d49136893928bc686f2ab8 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 9 Feb 2019 17:22:32 +0100 Subject: [PATCH] htlcswitch/test: move preimage cache to server level In this commit the preimage cache is instantiated on the mock server level where it belongs. Previously it was a cache shared across all mock servers. --- htlcswitch/mock.go | 8 +++++++- htlcswitch/test_utils.go | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index cd6a5dcfa..1d797fb1f 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -131,6 +131,7 @@ type mockServer struct { htlcSwitch *Switch registry *mockInvoiceRegistry + pCache *mockPreimageCache interceptorFuncs []messageInterceptor } @@ -186,19 +187,24 @@ func newMockServer(t testing.TB, name string, startingHeight uint32, h := sha256.Sum256([]byte(name)) copy(id[:], h[:]) + pCache := newMockPreimageCache() + htlcSwitch, err := initSwitchWithDB(startingHeight, db) if err != nil { return nil, err } + registry := newMockRegistry(defaultDelta) + return &mockServer{ t: t, id: id, name: name, messages: make(chan lnwire.Message, 3000), quit: make(chan struct{}), - registry: newMockRegistry(defaultDelta), + registry: registry, htlcSwitch: htlcSwitch, + pCache: pCache, interceptorFuncs: make([]messageInterceptor, 0), }, nil } diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index b7a5975a5..46e0dac34 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -971,7 +971,6 @@ type hopNetwork struct { feeEstimator *mockFeeEstimator globalPolicy ForwardingPolicy obfuscator ErrorEncrypter - pCache *mockPreimageCache defaultDelta uint32 } @@ -979,8 +978,6 @@ type hopNetwork struct { func newHopNetwork() *hopNetwork { defaultDelta := uint32(6) - pCache := newMockPreimageCache() - globalPolicy := ForwardingPolicy{ MinHTLC: lnwire.NewMSatFromSatoshis(5), BaseFee: lnwire.NewMSatFromSatoshis(1), @@ -997,7 +994,6 @@ func newHopNetwork() *hopNetwork { feeEstimator: feeEstimator, globalPolicy: globalPolicy, obfuscator: obfuscator, - pCache: pCache, defaultDelta: defaultDelta, } } @@ -1028,7 +1024,7 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer, FetchLastChannelUpdate: mockGetChanUpdateMessage, Registry: server.registry, FeeEstimator: h.feeEstimator, - PreimageCache: h.pCache, + PreimageCache: server.pCache, UpdateContractSignals: func(*contractcourt.ContractSignals) error { return nil },