You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

  1. package e2e_test
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. // assert that all nodes that have blocks at the height of a misbehavior has evidence
  10. // for that misbehavior
  11. func TestEvidence_Misbehavior(t *testing.T) {
  12. blocks := fetchBlockChain(t)
  13. testNode(t, func(t *testing.T, node e2e.Node) {
  14. seenEvidence := make(map[int64]struct{})
  15. for _, block := range blocks {
  16. // Find any evidence blaming this node in this block
  17. var nodeEvidence types.Evidence
  18. for _, evidence := range block.Evidence.Evidence {
  19. switch evidence := evidence.(type) {
  20. case *types.DuplicateVoteEvidence:
  21. if bytes.Equal(evidence.VoteA.ValidatorAddress, node.PrivvalKey.PubKey().Address()) {
  22. nodeEvidence = evidence
  23. }
  24. default:
  25. t.Fatalf("unexpected evidence type %T", evidence)
  26. }
  27. }
  28. if nodeEvidence == nil {
  29. continue // no evidence for the node at this height
  30. }
  31. // Check that evidence was as expected
  32. misbehavior, ok := node.Misbehaviors[nodeEvidence.Height()]
  33. require.True(t, ok, "found unexpected evidence %v in height %v",
  34. nodeEvidence, block.Height)
  35. switch misbehavior {
  36. case "double-prevote":
  37. require.IsType(t, &types.DuplicateVoteEvidence{}, nodeEvidence, "unexpected evidence type")
  38. default:
  39. t.Fatalf("unknown misbehavior %v", misbehavior)
  40. }
  41. seenEvidence[nodeEvidence.Height()] = struct{}{}
  42. }
  43. // see if there is any evidence that we were expecting but didn't see
  44. for height, misbehavior := range node.Misbehaviors {
  45. _, ok := seenEvidence[height]
  46. require.True(t, ok, "expected evidence for %v misbehavior at height %v by node but was never found",
  47. misbehavior, height)
  48. }
  49. })
  50. }