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.

125 lines
3.0 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. "github.com/stretchr/testify/assert"
  5. "github.com/tendermint/tendermint/types"
  6. dbm "github.com/tendermint/tm-db"
  7. )
  8. //-------------------------------------------
  9. func TestStoreAddDuplicate(t *testing.T) {
  10. assert := assert.New(t)
  11. db := dbm.NewMemDB()
  12. store := NewStore(db)
  13. priority := int64(10)
  14. ev := types.NewMockGoodEvidence(2, 1, []byte("val1"))
  15. added := store.AddNewEvidence(ev, priority)
  16. assert.True(added)
  17. // cant add twice
  18. added = store.AddNewEvidence(ev, priority)
  19. assert.False(added)
  20. }
  21. func TestStoreCommitDuplicate(t *testing.T) {
  22. assert := assert.New(t)
  23. db := dbm.NewMemDB()
  24. store := NewStore(db)
  25. priority := int64(10)
  26. ev := types.NewMockGoodEvidence(2, 1, []byte("val1"))
  27. store.MarkEvidenceAsCommitted(ev)
  28. added := store.AddNewEvidence(ev, priority)
  29. assert.False(added)
  30. }
  31. func TestStoreMark(t *testing.T) {
  32. assert := assert.New(t)
  33. db := dbm.NewMemDB()
  34. store := NewStore(db)
  35. // before we do anything, priority/pending are empty
  36. priorityEv := store.PriorityEvidence()
  37. pendingEv := store.PendingEvidence(-1)
  38. assert.Equal(0, len(priorityEv))
  39. assert.Equal(0, len(pendingEv))
  40. priority := int64(10)
  41. ev := types.NewMockGoodEvidence(2, 1, []byte("val1"))
  42. added := store.AddNewEvidence(ev, priority)
  43. assert.True(added)
  44. // get the evidence. verify. should be uncommitted
  45. ei := store.GetInfo(ev.Height(), ev.Hash())
  46. assert.Equal(ev, ei.Evidence)
  47. assert.Equal(priority, ei.Priority)
  48. assert.False(ei.Committed)
  49. // new evidence should be returns in priority/pending
  50. priorityEv = store.PriorityEvidence()
  51. pendingEv = store.PendingEvidence(-1)
  52. assert.Equal(1, len(priorityEv))
  53. assert.Equal(1, len(pendingEv))
  54. // priority is now empty
  55. store.MarkEvidenceAsBroadcasted(ev)
  56. priorityEv = store.PriorityEvidence()
  57. pendingEv = store.PendingEvidence(-1)
  58. assert.Equal(0, len(priorityEv))
  59. assert.Equal(1, len(pendingEv))
  60. // priority and pending are now empty
  61. store.MarkEvidenceAsCommitted(ev)
  62. priorityEv = store.PriorityEvidence()
  63. pendingEv = store.PendingEvidence(-1)
  64. assert.Equal(0, len(priorityEv))
  65. assert.Equal(0, len(pendingEv))
  66. // evidence should show committed
  67. newPriority := int64(0)
  68. ei = store.GetInfo(ev.Height(), ev.Hash())
  69. assert.Equal(ev, ei.Evidence)
  70. assert.Equal(newPriority, ei.Priority)
  71. assert.True(ei.Committed)
  72. }
  73. func TestStorePriority(t *testing.T) {
  74. assert := assert.New(t)
  75. db := dbm.NewMemDB()
  76. store := NewStore(db)
  77. // sorted by priority and then height
  78. cases := []struct {
  79. ev types.MockGoodEvidence
  80. priority int64
  81. }{
  82. {types.NewMockGoodEvidence(2, 1, []byte("val1")), 17},
  83. {types.NewMockGoodEvidence(5, 2, []byte("val2")), 15},
  84. {types.NewMockGoodEvidence(10, 2, []byte("val2")), 13},
  85. {types.NewMockGoodEvidence(100, 2, []byte("val2")), 11},
  86. {types.NewMockGoodEvidence(90, 2, []byte("val2")), 11},
  87. {types.NewMockGoodEvidence(80, 2, []byte("val2")), 11},
  88. }
  89. for _, c := range cases {
  90. added := store.AddNewEvidence(c.ev, c.priority)
  91. assert.True(added)
  92. }
  93. evList := store.PriorityEvidence()
  94. for i, ev := range evList {
  95. assert.Equal(ev, cases[i].ev)
  96. }
  97. }