(t *testing.T)
| 23 | const validationTestsStopHeight int64 = 10 |
| 24 | |
| 25 | func TestValidateBlockHeader(t *testing.T) { |
| 26 | proxyApp := newTestApp() |
| 27 | require.NoError(t, proxyApp.Start()) |
| 28 | defer proxyApp.Stop() //nolint:errcheck // ignore for tests |
| 29 | |
| 30 | state, stateDB, privVals := makeState(3, 1) |
| 31 | stateStore := sm.NewStore(stateDB, sm.StoreOptions{ |
| 32 | DiscardABCIResponses: false, |
| 33 | }) |
| 34 | blockExec := sm.NewBlockExecutor( |
| 35 | stateStore, |
| 36 | log.TestingLogger(), |
| 37 | proxyApp.Consensus(), |
| 38 | memmock.Mempool{}, |
| 39 | sm.EmptyEvidencePool{}, |
| 40 | ) |
| 41 | lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) |
| 42 | |
| 43 | // some bad values |
| 44 | wrongHash := tmhash.Sum([]byte("this hash is wrong")) |
| 45 | wrongVersion1 := state.Version.Consensus |
| 46 | wrongVersion1.Block += 2 |
| 47 | wrongVersion2 := state.Version.Consensus |
| 48 | wrongVersion2.App += 2 |
| 49 | |
| 50 | // Manipulation of any header field causes failure. |
| 51 | testCases := []struct { |
| 52 | name string |
| 53 | malleateBlock func(block *types.Block) |
| 54 | }{ |
| 55 | {"Version wrong1", func(block *types.Block) { block.Version = wrongVersion1 }}, |
| 56 | {"Version wrong2", func(block *types.Block) { block.Version = wrongVersion2 }}, |
| 57 | {"ChainID wrong", func(block *types.Block) { block.ChainID = "not-the-real-one" }}, |
| 58 | {"Height wrong", func(block *types.Block) { block.Height += 10 }}, |
| 59 | {"Time wrong", func(block *types.Block) { block.Time = block.Time.Add(-time.Second * 1) }}, |
| 60 | |
| 61 | {"LastBlockID wrong", func(block *types.Block) { block.LastBlockID.PartSetHeader.Total += 10 }}, |
| 62 | {"LastCommitHash wrong", func(block *types.Block) { block.LastCommitHash = wrongHash }}, |
| 63 | {"DataHash wrong", func(block *types.Block) { block.DataHash = wrongHash }}, |
| 64 | |
| 65 | {"ValidatorsHash wrong", func(block *types.Block) { block.ValidatorsHash = wrongHash }}, |
| 66 | {"NextValidatorsHash wrong", func(block *types.Block) { block.NextValidatorsHash = wrongHash }}, |
| 67 | {"ConsensusHash wrong", func(block *types.Block) { block.ConsensusHash = wrongHash }}, |
| 68 | {"AppHash wrong", func(block *types.Block) { block.AppHash = wrongHash }}, |
| 69 | {"LastResultsHash wrong", func(block *types.Block) { block.LastResultsHash = wrongHash }}, |
| 70 | |
| 71 | {"EvidenceHash wrong", func(block *types.Block) { block.EvidenceHash = wrongHash }}, |
| 72 | {"Proposer wrong", func(block *types.Block) { block.ProposerAddress = ed25519.GenPrivKey().PubKey().Address() }}, |
| 73 | {"Proposer invalid", func(block *types.Block) { block.ProposerAddress = []byte("wrong size") }}, |
| 74 | } |
| 75 | |
| 76 | // Build up state for multiple heights |
| 77 | for height := int64(1); height < validationTestsStopHeight; height++ { |
| 78 | proposerAddr := state.Validators.GetProposer().Address |
| 79 | /* |
| 80 | Invalid blocks don't pass |
| 81 | */ |
| 82 | for _, tc := range testCases { |
nothing calls this directly
no test coverage detected