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.

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