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.

126 lines
3.2 KiB

lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
  1. package evidence
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tendermint/tendermint/types"
  7. dbm "github.com/tendermint/tm-db"
  8. )
  9. //-------------------------------------------
  10. func TestStoreAddDuplicate(t *testing.T) {
  11. assert := assert.New(t)
  12. db := dbm.NewMemDB()
  13. store := NewStore(db)
  14. priority := int64(10)
  15. ev := types.NewMockEvidence(2, time.Now().UTC(), 1, []byte("val1"))
  16. added := store.AddNewEvidence(ev, priority)
  17. assert.True(added)
  18. // cant add twice
  19. added = store.AddNewEvidence(ev, priority)
  20. assert.False(added)
  21. }
  22. func TestStoreCommitDuplicate(t *testing.T) {
  23. assert := assert.New(t)
  24. db := dbm.NewMemDB()
  25. store := NewStore(db)
  26. priority := int64(10)
  27. ev := types.NewMockEvidence(2, time.Now().UTC(), 1, []byte("val1"))
  28. store.MarkEvidenceAsCommitted(ev)
  29. added := store.AddNewEvidence(ev, priority)
  30. assert.False(added)
  31. }
  32. func TestStoreMark(t *testing.T) {
  33. assert := assert.New(t)
  34. db := dbm.NewMemDB()
  35. store := NewStore(db)
  36. // before we do anything, priority/pending are empty
  37. priorityEv := store.PriorityEvidence()
  38. pendingEv := store.PendingEvidence(-1)
  39. assert.Equal(0, len(priorityEv))
  40. assert.Equal(0, len(pendingEv))
  41. priority := int64(10)
  42. ev := types.NewMockEvidence(2, time.Now().UTC(), 1, []byte("val1"))
  43. added := store.AddNewEvidence(ev, priority)
  44. assert.True(added)
  45. // get the evidence. verify. should be uncommitted
  46. ei := store.GetInfo(ev.Height(), ev.Hash())
  47. assert.Equal(ev, ei.Evidence)
  48. assert.Equal(priority, ei.Priority)
  49. assert.False(ei.Committed)
  50. // new evidence should be returns in priority/pending
  51. priorityEv = store.PriorityEvidence()
  52. pendingEv = store.PendingEvidence(-1)
  53. assert.Equal(1, len(priorityEv))
  54. assert.Equal(1, len(pendingEv))
  55. // priority is now empty
  56. store.MarkEvidenceAsBroadcasted(ev)
  57. priorityEv = store.PriorityEvidence()
  58. pendingEv = store.PendingEvidence(-1)
  59. assert.Equal(0, len(priorityEv))
  60. assert.Equal(1, len(pendingEv))
  61. // priority and pending are now empty
  62. store.MarkEvidenceAsCommitted(ev)
  63. priorityEv = store.PriorityEvidence()
  64. pendingEv = store.PendingEvidence(-1)
  65. assert.Equal(0, len(priorityEv))
  66. assert.Equal(0, len(pendingEv))
  67. // evidence should show committed
  68. newPriority := int64(0)
  69. ei = store.GetInfo(ev.Height(), ev.Hash())
  70. assert.Equal(ev, ei.Evidence)
  71. assert.Equal(newPriority, ei.Priority)
  72. assert.True(ei.Committed)
  73. }
  74. func TestStorePriority(t *testing.T) {
  75. assert := assert.New(t)
  76. db := dbm.NewMemDB()
  77. store := NewStore(db)
  78. // sorted by priority and then height
  79. cases := []struct {
  80. ev types.MockEvidence
  81. priority int64
  82. }{
  83. {types.NewMockEvidence(2, time.Now().UTC(), 1, []byte("val1")), 17},
  84. {types.NewMockEvidence(5, time.Now().UTC(), 2, []byte("val2")), 15},
  85. {types.NewMockEvidence(10, time.Now().UTC(), 2, []byte("val2")), 13},
  86. {types.NewMockEvidence(100, time.Now().UTC(), 2, []byte("val2")), 11},
  87. {types.NewMockEvidence(90, time.Now().UTC(), 2, []byte("val2")), 11},
  88. {types.NewMockEvidence(80, time.Now().UTC(), 2, []byte("val2")), 11},
  89. }
  90. for _, c := range cases {
  91. added := store.AddNewEvidence(c.ev, c.priority)
  92. assert.True(added)
  93. }
  94. evList := store.PriorityEvidence()
  95. for i, ev := range evList {
  96. assert.Equal(ev, cases[i].ev)
  97. }
  98. }