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.

68 lines
1.7 KiB

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