MCPcopy Create free account
hub / github.com/tendermint/tendermint / TestReactorInvalidPrecommit

Function TestReactorInvalidPrecommit

internal/consensus/invalid_test.go:17–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestReactorInvalidPrecommit(t *testing.T) {
18 config := configSetup(t)
19
20 n := 4
21 states, cleanup := randConsensusState(t,
22 config, n, "consensus_reactor_test",
23 newMockTickerFunc(true), newKVStore)
24 t.Cleanup(cleanup)
25
26 for i := 0; i < 4; i++ {
27 ticker := NewTimeoutTicker()
28 ticker.SetLogger(states[i].Logger)
29 states[i].SetTimeoutTicker(ticker)
30 }
31
32 rts := setup(t, n, states, 100) // buffer must be large enough to not deadlock
33
34 for _, reactor := range rts.reactors {
35 state := reactor.state.GetState()
36 reactor.SwitchToConsensus(state, false)
37 }
38
39 // this val sends a random precommit at each height
40 node := rts.network.RandomNode()
41
42 byzState := rts.states[node.NodeID]
43 byzReactor := rts.reactors[node.NodeID]
44
45 // Update the doPrevote function to just send a valid precommit for a random
46 // block and otherwise disable the priv validator.
47 byzState.mtx.Lock()
48 privVal := byzState.privValidator
49 byzState.doPrevote = func(height int64, round int32) {
50 invalidDoPrevoteFunc(t, height, round, byzState, byzReactor, privVal)
51 }
52 byzState.mtx.Unlock()
53
54 // wait for a bunch of blocks
55 //
56 // TODO: Make this tighter by ensuring the halt happens by block 2.
57 var wg sync.WaitGroup
58 for i := 0; i < 10; i++ {
59 for _, sub := range rts.subs {
60 wg.Add(1)
61
62 go func(s types.Subscription) {
63 <-s.Out()
64 wg.Done()
65 }(sub)
66 }
67 }
68
69 wg.Wait()
70}
71
72func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, r *Reactor, pv types.PrivValidator) {
73 // routine to:

Callers

nothing calls this directly

Calls 15

SetLoggerMethod · 0.95
configSetupFunction · 0.85
randConsensusStateFunction · 0.85
newMockTickerFuncFunction · 0.85
NewTimeoutTickerFunction · 0.85
invalidDoPrevoteFuncFunction · 0.85
SetTimeoutTickerMethod · 0.80
RandomNodeMethod · 0.80
setupFunction · 0.70
CleanupMethod · 0.65
GetStateMethod · 0.65
SwitchToConsensusMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…