---------------------------------------------- byzantine failures one byz val sends a precommit for a random block at each height Ensure a testnet makes blocks
(t *testing.T)
| 18 | // one byz val sends a precommit for a random block at each height |
| 19 | // Ensure a testnet makes blocks |
| 20 | func 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 | |
| 58 | func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw *p2p.Switch, pv types.PrivValidator) { |
| 59 | // routine to: |
nothing calls this directly
no test coverage detected