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.

54 lines
1.1 KiB

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