MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestMempoolProgressInHigherRound

Function TestMempoolProgressInHigherRound

consensus/mempool_test.go:64–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestMempoolProgressInHigherRound(t *testing.T) {
65 config := ResetConfig("consensus_mempool_txs_available_test")
66 defer os.RemoveAll(config.RootDir)
67 config.Consensus.CreateEmptyBlocks = false
68 state, privVals := randGenesisState(1, false, 10)
69 cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication())
70 assertMempool(cs.txNotifier).EnableTxsAvailable()
71 height, round := cs.Height, cs.Round
72 newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
73 newRoundCh := subscribe(cs.eventBus, types.EventQueryNewRound)
74 timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
75 cs.setProposal = func(proposal *types.Proposal) error {
76 if cs.Height == 2 && cs.Round == 0 {
77 // dont set the proposal in round 0 so we timeout and
78 // go to next round
79 cs.Logger.Info("Ignoring set proposal at height 2, round 0")
80 return nil
81 }
82 return cs.defaultSetProposal(proposal)
83 }
84 startTestRound(cs, height, round)
85
86 ensureNewRound(newRoundCh, height, round) // first round at first height
87 ensureNewEventOnChannel(newBlockCh) // first block gets committed
88
89 height++ // moving to the next height
90 round = 0
91
92 ensureNewRound(newRoundCh, height, round) // first round at next height
93 deliverTxsRange(cs, 0, 1) // we deliver txs, but dont set a proposal so we get the next round
94 ensureNewTimeout(timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds())
95
96 round++ // moving to the next round
97 ensureNewRound(newRoundCh, height, round) // wait for the next round
98 ensureNewEventOnChannel(newBlockCh) // now we can commit the block
99}
100
101func deliverTxsRange(cs *State, start, end int) {
102 // Deliver some txs.

Callers

nothing calls this directly

Calls 14

ResetConfigFunction · 0.85
randGenesisStateFunction · 0.85
newStateWithConfigFunction · 0.85
NewCounterApplicationFunction · 0.85
assertMempoolFunction · 0.85
subscribeFunction · 0.85
startTestRoundFunction · 0.85
ensureNewRoundFunction · 0.85
ensureNewEventOnChannelFunction · 0.85
deliverTxsRangeFunction · 0.85
ensureNewTimeoutFunction · 0.85
defaultSetProposalMethod · 0.80

Tested by

no test coverage detected