mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-13 12:32:51 +02:00
netsync: add TestStartSyncChainCurrent for chain-current noop path
Verify that startSync does not set syncPeer or ibdMode when the chain tip is recent and no peer advertises a height above ours.
This commit is contained in:
parent
570d3c8da3
commit
2aae8a6d68
1 changed files with 44 additions and 0 deletions
|
|
@ -1169,3 +1169,47 @@ func TestStallNoDisconnectAtSameHeight(t *testing.T) {
|
|||
require.Nil(t, sm.syncPeer,
|
||||
"we should have nil syncPeer after handleStallSample")
|
||||
}
|
||||
|
||||
// TestStartSyncChainCurrent verifies that startSync does not set syncPeer
|
||||
// or ibdMode when the chain is current and no peer is strictly higher.
|
||||
// isInIBDMode sees IsCurrent()==true with no higher peers, returns false,
|
||||
// and startSync exits immediately.
|
||||
func TestStartSyncChainCurrent(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
params := chaincfg.RegressionNetParams
|
||||
params.Checkpoints = nil
|
||||
|
||||
sm, tearDown := makeMockSyncManager(t, ¶ms)
|
||||
defer tearDown()
|
||||
|
||||
// Mine a single block with a recent timestamp so
|
||||
// IsCurrent() returns true.
|
||||
cb := createTestCoinbase(1, ¶ms)
|
||||
header := wire.BlockHeader{
|
||||
Version: 1,
|
||||
PrevBlock: *params.GenesisHash,
|
||||
MerkleRoot: cb.TxHash(),
|
||||
Timestamp: time.Now().Truncate(time.Second),
|
||||
Bits: params.PowLimitBits,
|
||||
}
|
||||
require.True(t, solveTestBlock(&header, ¶ms))
|
||||
|
||||
block := btcutil.NewBlock(&wire.MsgBlock{
|
||||
Header: header,
|
||||
Transactions: []*wire.MsgTx{cb},
|
||||
})
|
||||
_, _, err := sm.chain.ProcessBlock(block, blockchain.BFNone)
|
||||
require.NoError(t, err)
|
||||
require.True(t, sm.chain.IsCurrent())
|
||||
|
||||
// Peer at our height — not higher.
|
||||
newSyncCandidate(t, sm, 1)
|
||||
|
||||
sm.startSync()
|
||||
|
||||
require.Nil(t, sm.syncPeer,
|
||||
"syncPeer should not be set when chain is already current")
|
||||
require.False(t, sm.ibdMode,
|
||||
"ibdMode should not be activated when chain is already current")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue