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.

64 lines
1.5 KiB

  1. package state
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func _TestValidateBlock(t *testing.T) {
  7. state := state()
  8. // proper block must pass
  9. block := makeBlock(state, 1)
  10. err := ValidateBlock(state, block)
  11. require.NoError(t, err)
  12. // wrong chain fails
  13. block = makeBlock(state, 1)
  14. block.ChainID = "not-the-real-one"
  15. err = ValidateBlock(state, block)
  16. require.Error(t, err)
  17. // wrong height fails
  18. block = makeBlock(state, 1)
  19. block.Height += 10
  20. err = ValidateBlock(state, block)
  21. require.Error(t, err)
  22. // wrong total tx fails
  23. block = makeBlock(state, 1)
  24. block.TotalTxs += 10
  25. err = ValidateBlock(state, block)
  26. require.Error(t, err)
  27. // wrong blockid fails
  28. block = makeBlock(state, 1)
  29. block.LastBlockID.PartsHeader.Total += 10
  30. err = ValidateBlock(state, block)
  31. require.Error(t, err)
  32. // wrong app hash fails
  33. block = makeBlock(state, 1)
  34. block.AppHash = []byte("wrong app hash")
  35. err = ValidateBlock(state, block)
  36. require.Error(t, err)
  37. // wrong consensus hash fails
  38. block = makeBlock(state, 1)
  39. block.ConsensusHash = []byte("wrong consensus hash")
  40. err = ValidateBlock(state, block)
  41. require.Error(t, err)
  42. // wrong results hash fails
  43. block = makeBlock(state, 1)
  44. block.LastResultsHash = []byte("wrong results hash")
  45. err = ValidateBlock(state, block)
  46. require.Error(t, err)
  47. // wrong validators hash fails
  48. block = makeBlock(state, 1)
  49. block.ValidatorsHash = []byte("wrong validators hash")
  50. err = ValidateBlock(state, block)
  51. require.Error(t, err)
  52. }