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.

42 lines
1.1 KiB

  1. package state
  2. import (
  3. "testing"
  4. dbm "github.com/tendermint/go-db"
  5. "github.com/tendermint/tendermint/config/tendermint_test"
  6. )
  7. func TestStateCopyEquals(t *testing.T) {
  8. config := tendermint_test.ResetConfig("state_")
  9. // Get State db
  10. stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
  11. state := GetState(config, stateDB)
  12. stateCopy := state.Copy()
  13. if !state.Equals(stateCopy) {
  14. t.Fatal("expected state and its copy to be identical. got %v\n expected %v\n", stateCopy, state)
  15. }
  16. stateCopy.LastBlockHeight += 1
  17. if state.Equals(stateCopy) {
  18. t.Fatal("expected states to be different. got same %v", state)
  19. }
  20. }
  21. func TestStateSaveLoad(t *testing.T) {
  22. config := tendermint_test.ResetConfig("state_")
  23. // Get State db
  24. stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
  25. state := GetState(config, stateDB)
  26. state.LastBlockHeight += 1
  27. state.Save()
  28. loadedState := LoadState(stateDB)
  29. if !state.Equals(loadedState) {
  30. t.Fatal("expected state and its copy to be identical. got %v\n expected %v\n", loadedState, state)
  31. }
  32. }