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

Function TestReactorInvalidPrecommit

consensus/invalid_test.go:20–56  ·  view source on GitHub ↗

---------------------------------------------- byzantine failures one byz val sends a precommit for a random block at each height Ensure a testnet makes blocks

(t *testing.T)

Source from the content-addressed store, hash-verified

18// one byz val sends a precommit for a random block at each height
19// Ensure a testnet makes blocks
20func TestReactorInvalidPrecommit(t *testing.T) {
21 N := 4
22 css, cleanup := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter)
23 defer cleanup()
24
25 for i := 0; i < 4; i++ {
26 ticker := NewTimeoutTicker()
27 ticker.SetLogger(css[i].Logger)
28 css[i].SetTimeoutTicker(ticker)
29
30 }
31
32 reactors, blocksSubs, eventBuses := startConsensusNet(t, css, N)
33
34 // this val sends a random precommit at each height
35 byzValIdx := 0
36 byzVal := css[byzValIdx]
37 byzR := reactors[byzValIdx]
38
39 // update the doPrevote function to just send a valid precommit for a random block
40 // and otherwise disable the priv validator
41 byzVal.mtx.Lock()
42 pv := byzVal.privValidator
43 byzVal.doPrevote = func(height int64, round int32) {
44 invalidDoPrevoteFunc(t, height, round, byzVal, byzR.Switch, pv)
45 }
46 byzVal.mtx.Unlock()
47 defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
48
49 // wait for a bunch of blocks
50 // TODO: make this tighter by ensuring the halt happens by block 2
51 for i := 0; i < 10; i++ {
52 timeoutWaitGroup(t, N, func(j int) {
53 <-blocksSubs[j].Out()
54 }, css)
55 }
56}
57
58func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw *p2p.Switch, pv types.PrivValidator) {
59 // routine to:

Callers

nothing calls this directly

Calls 14

SetLoggerMethod · 0.95
TestingLoggerFunction · 0.92
randConsensusNetFunction · 0.85
newMockTickerFuncFunction · 0.85
cleanupFunction · 0.85
startConsensusNetFunction · 0.85
invalidDoPrevoteFuncFunction · 0.85
stopConsensusNetFunction · 0.85
timeoutWaitGroupFunction · 0.85
NewTimeoutTickerFunction · 0.70
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected