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.

37 lines
805 B

  1. package consensus
  2. import (
  3. "bytes"
  4. "testing"
  5. "time"
  6. "github.com/tendermint/tendermint/consensus/types"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestWALEncoderDecoder(t *testing.T) {
  11. now := time.Now()
  12. msgs := []TimedWALMessage{
  13. TimedWALMessage{Time: now, Msg: EndHeightMessage{0}},
  14. TimedWALMessage{Time: now, Msg: timeoutInfo{Duration: time.Second, Height: 1, Round: 1, Step: types.RoundStepPropose}},
  15. }
  16. b := new(bytes.Buffer)
  17. for _, msg := range msgs {
  18. b.Reset()
  19. enc := NewWALEncoder(b)
  20. err := enc.Encode(&msg)
  21. require.NoError(t, err)
  22. dec := NewWALDecoder(b)
  23. decoded, err := dec.Decode()
  24. require.NoError(t, err)
  25. assert.Equal(t, msg.Time.Truncate(time.Millisecond), decoded.Time)
  26. assert.Equal(t, msg.Msg, decoded.Msg)
  27. }
  28. }