mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 06:37:21 +01:00
graph: fix flake in unit test
This commit is contained in:
@@ -582,7 +582,7 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
// TestChansClosedOfflinePruneGraph tests that if channels we know of are
|
// TestChansClosedOfflinePruneGraph tests that if channels we know of are
|
||||||
// closed while we're offline, then once we resume operation of the
|
// closed while we're offline, then once we resume operation of the
|
||||||
// ChannelRouter, then the channels are properly pruned.
|
// ChannelRouter, then the channels are properly pruned.
|
||||||
func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
|
func TestChansClosedOfflinePruneGraph(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
const startingBlockHeight = 101
|
const startingBlockHeight = 101
|
||||||
|
|||||||
@@ -176,13 +176,21 @@ type mockChain struct {
|
|||||||
var _ lnwallet.BlockChainIO = (*mockChain)(nil)
|
var _ lnwallet.BlockChainIO = (*mockChain)(nil)
|
||||||
|
|
||||||
func newMockChain(currentHeight uint32) *mockChain {
|
func newMockChain(currentHeight uint32) *mockChain {
|
||||||
return &mockChain{
|
chain := &mockChain{
|
||||||
bestHeight: int32(currentHeight),
|
bestHeight: int32(currentHeight),
|
||||||
blocks: make(map[chainhash.Hash]*wire.MsgBlock),
|
blocks: make(map[chainhash.Hash]*wire.MsgBlock),
|
||||||
utxos: make(map[wire.OutPoint]wire.TxOut),
|
utxos: make(map[wire.OutPoint]wire.TxOut),
|
||||||
blockIndex: make(map[uint32]chainhash.Hash),
|
blockIndex: make(map[uint32]chainhash.Hash),
|
||||||
blockHeightIndex: make(map[chainhash.Hash]uint32),
|
blockHeightIndex: make(map[chainhash.Hash]uint32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize the block index with the empty hash for the
|
||||||
|
// starting height.
|
||||||
|
startingHash := chainhash.Hash{}
|
||||||
|
chain.blockIndex[currentHeight] = startingHash
|
||||||
|
chain.blockHeightIndex[startingHash] = currentHeight
|
||||||
|
|
||||||
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChain) setBestBlock(height int32) {
|
func (m *mockChain) setBestBlock(height int32) {
|
||||||
@@ -196,7 +204,11 @@ func (m *mockChain) GetBestBlock() (*chainhash.Hash, int32, error) {
|
|||||||
m.RLock()
|
m.RLock()
|
||||||
defer m.RUnlock()
|
defer m.RUnlock()
|
||||||
|
|
||||||
blockHash := m.blockIndex[uint32(m.bestHeight)]
|
blockHash, exists := m.blockIndex[uint32(m.bestHeight)]
|
||||||
|
if !exists {
|
||||||
|
return nil, 0, fmt.Errorf("block at height %d not found",
|
||||||
|
m.bestHeight)
|
||||||
|
}
|
||||||
|
|
||||||
return &blockHash, m.bestHeight, nil
|
return &blockHash, m.bestHeight, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user