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.

53 lines
1.0 KiB

  1. package evidence
  2. import (
  3. "sync"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tendermint/tendermint/types"
  7. dbm "github.com/tendermint/tmlibs/db"
  8. )
  9. type mockState struct{}
  10. func (m mockState) VerifyEvidence(ev types.Evidence) (int64, error) {
  11. err := ev.Verify("")
  12. return 10, err
  13. }
  14. func TestEvidencePool(t *testing.T) {
  15. assert := assert.New(t)
  16. params := types.EvidenceParams{}
  17. store := NewEvidenceStore(dbm.NewMemDB())
  18. state := mockState{}
  19. pool := NewEvidencePool(params, store, state)
  20. goodEvidence := newMockGoodEvidence(5, 1, []byte("val1"))
  21. badEvidence := MockBadEvidence{goodEvidence}
  22. err := pool.AddEvidence(badEvidence)
  23. assert.NotNil(err)
  24. var wg sync.WaitGroup
  25. wg.Add(1)
  26. go func() {
  27. <-pool.EvidenceChan()
  28. wg.Done()
  29. }()
  30. err = pool.AddEvidence(goodEvidence)
  31. assert.Nil(err)
  32. wg.Wait()
  33. // if we send it again it wont fire on the chan
  34. err = pool.AddEvidence(goodEvidence)
  35. assert.Nil(err)
  36. select {
  37. case <-pool.EvidenceChan():
  38. t.Fatal("unexpected read on EvidenceChan")
  39. default:
  40. }
  41. }