routing: add Reset() method to mockChainView

In this commit, we add a Reset() method to the mockChainView struct.
With this new method tests are able to fully simulate a restart of the
ChannelRouter. This is necessary as the FilteredChainView instances are
assumed to be stateless, and don’t write their state to disk before a
restart.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-06 15:58:52 -08:00
parent fea8cbf920
commit cdf2f43432
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -212,6 +212,8 @@ type mockChainView struct {
newBlocks chan *chainview.FilteredBlock
staleBlocks chan *chainview.FilteredBlock
chain lnwallet.BlockChainIO
filter map[wire.OutPoint]struct{}
quit chan struct{}
@ -221,8 +223,9 @@ type mockChainView struct {
// chainview.FilteredChainView.
var _ chainview.FilteredChainView = (*mockChainView)(nil)
func newMockChainView() *mockChainView {
func newMockChainView(chain lnwallet.BlockChainIO) *mockChainView {
return &mockChainView{
chain: chain,
newBlocks: make(chan *chainview.FilteredBlock, 10),
staleBlocks: make(chan *chainview.FilteredBlock, 10),
filter: make(map[wire.OutPoint]struct{}),
@ -230,6 +233,13 @@ func newMockChainView() *mockChainView {
}
}
func (m *mockChainView) Reset() {
m.filter = make(map[wire.OutPoint]struct{})
m.quit = make(chan struct{})
m.newBlocks = make(chan *chainview.FilteredBlock, 10)
m.staleBlocks = make(chan *chainview.FilteredBlock, 10)
}
func (m *mockChainView) UpdateFilter(ops []wire.OutPoint, updateHeight uint32) error {
m.Lock()
defer m.Unlock()
@ -316,6 +326,7 @@ func (m *mockChainView) Start() error {
}
func (m *mockChainView) Stop() error {
close(m.quit)
return nil
}