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.

203 lines
5.6 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
abci: Synchronize FinalizeBlock with the updated specification (#7983) This change set implements the most recent version of `FinalizeBlock`. # What does this change actually contain? * This change set is rather large but fear not! The majority of the files touched and changes are renaming `ResponseDeliverTx` to `ExecTxResult`. This should be a pretty inoffensive change since they're effectively the same type but with a different name. * The `execBlockOnProxyApp` was totally removed since it served as just a wrapper around the logic that is now mostly encapsulated within `FinalizeBlock` * The `updateState` helper function has been made a public method on `State`. It was being exposed as a shim through the testing infrastructure, so this seemed innocuous. * Tests already existed to ensure that the application received the `ByzantineValidators` and the `ValidatorUpdates`, but one was fixed up to ensure that `LastCommitInfo` was being sent across. * Tests were removed from the `psql` indexer that seemed to search for an event in the indexer that was not being created. # Questions for reviewers * We store this [ABCIResponses](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/proto/tendermint/state/types.pb.go#L37) type in the data base as the block results. This type has changed since v0.35 to contain the `FinalizeBlock` response. I'm wondering if we need to do any shimming to keep the old data retrieveable? * Similarly, this change is exposed via the RPC through [ResultBlockResults](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/rpc/coretypes/responses.go#L69) changing. Should we somehow shim or notify for this change? closes: #7658
3 years ago
abci: Synchronize FinalizeBlock with the updated specification (#7983) This change set implements the most recent version of `FinalizeBlock`. # What does this change actually contain? * This change set is rather large but fear not! The majority of the files touched and changes are renaming `ResponseDeliverTx` to `ExecTxResult`. This should be a pretty inoffensive change since they're effectively the same type but with a different name. * The `execBlockOnProxyApp` was totally removed since it served as just a wrapper around the logic that is now mostly encapsulated within `FinalizeBlock` * The `updateState` helper function has been made a public method on `State`. It was being exposed as a shim through the testing infrastructure, so this seemed innocuous. * Tests already existed to ensure that the application received the `ByzantineValidators` and the `ValidatorUpdates`, but one was fixed up to ensure that `LastCommitInfo` was being sent across. * Tests were removed from the `psql` indexer that seemed to search for an event in the indexer that was not being created. # Questions for reviewers * We store this [ABCIResponses](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/proto/tendermint/state/types.pb.go#L37) type in the data base as the block results. This type has changed since v0.35 to contain the `FinalizeBlock` response. I'm wondering if we need to do any shimming to keep the old data retrieveable? * Similarly, this change is exposed via the RPC through [ResultBlockResults](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/rpc/coretypes/responses.go#L69) changing. Should we somehow shim or notify for this change? closes: #7658
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
abci: Synchronize FinalizeBlock with the updated specification (#7983) This change set implements the most recent version of `FinalizeBlock`. # What does this change actually contain? * This change set is rather large but fear not! The majority of the files touched and changes are renaming `ResponseDeliverTx` to `ExecTxResult`. This should be a pretty inoffensive change since they're effectively the same type but with a different name. * The `execBlockOnProxyApp` was totally removed since it served as just a wrapper around the logic that is now mostly encapsulated within `FinalizeBlock` * The `updateState` helper function has been made a public method on `State`. It was being exposed as a shim through the testing infrastructure, so this seemed innocuous. * Tests already existed to ensure that the application received the `ByzantineValidators` and the `ValidatorUpdates`, but one was fixed up to ensure that `LastCommitInfo` was being sent across. * Tests were removed from the `psql` indexer that seemed to search for an event in the indexer that was not being created. # Questions for reviewers * We store this [ABCIResponses](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/proto/tendermint/state/types.pb.go#L37) type in the data base as the block results. This type has changed since v0.35 to contain the `FinalizeBlock` response. I'm wondering if we need to do any shimming to keep the old data retrieveable? * Similarly, this change is exposed via the RPC through [ResultBlockResults](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/rpc/coretypes/responses.go#L69) changing. Should we somehow shim or notify for this change? closes: #7658
3 years ago
  1. package mock_test
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "github.com/tendermint/tendermint/abci/example/kvstore"
  10. abci "github.com/tendermint/tendermint/abci/types"
  11. "github.com/tendermint/tendermint/libs/bytes"
  12. "github.com/tendermint/tendermint/rpc/client"
  13. "github.com/tendermint/tendermint/rpc/client/mock"
  14. "github.com/tendermint/tendermint/rpc/coretypes"
  15. "github.com/tendermint/tendermint/types"
  16. )
  17. func TestABCIMock(t *testing.T) {
  18. ctx, cancel := context.WithCancel(context.Background())
  19. defer cancel()
  20. key, value := []byte("foo"), []byte("bar")
  21. height := int64(10)
  22. goodTx := types.Tx{0x01, 0xff}
  23. badTx := types.Tx{0x12, 0x21}
  24. m := mock.ABCIMock{
  25. Info: mock.Call{Error: errors.New("foobar")},
  26. Query: mock.Call{Response: abci.ResponseQuery{
  27. Key: key,
  28. Value: value,
  29. Height: height,
  30. }},
  31. // Broadcast commit depends on call
  32. BroadcastCommit: mock.Call{
  33. Args: goodTx,
  34. Response: &coretypes.ResultBroadcastTxCommit{
  35. CheckTx: abci.ResponseCheckTx{Data: bytes.HexBytes("stand")},
  36. TxResult: abci.ExecTxResult{Data: bytes.HexBytes("deliver")},
  37. },
  38. Error: errors.New("bad tx"),
  39. },
  40. Broadcast: mock.Call{Error: errors.New("must commit")},
  41. }
  42. // now, let's try to make some calls
  43. _, err := m.ABCIInfo(ctx)
  44. require.Error(t, err)
  45. assert.Equal(t, "foobar", err.Error())
  46. // query always returns the response
  47. _query, err := m.ABCIQueryWithOptions(ctx, "/", nil, client.ABCIQueryOptions{Prove: false})
  48. query := _query.Response
  49. require.NoError(t, err)
  50. require.NotNil(t, query)
  51. assert.EqualValues(t, key, query.Key)
  52. assert.EqualValues(t, value, query.Value)
  53. assert.Equal(t, height, query.Height)
  54. // non-commit calls always return errors
  55. _, err = m.BroadcastTxSync(ctx, goodTx)
  56. require.Error(t, err)
  57. assert.Equal(t, "must commit", err.Error())
  58. _, err = m.BroadcastTxAsync(ctx, goodTx)
  59. require.Error(t, err)
  60. assert.Equal(t, "must commit", err.Error())
  61. // commit depends on the input
  62. _, err = m.BroadcastTxCommit(ctx, badTx)
  63. require.Error(t, err)
  64. assert.Equal(t, "bad tx", err.Error())
  65. bres, err := m.BroadcastTxCommit(ctx, goodTx)
  66. require.NoError(t, err, "%+v", err)
  67. assert.EqualValues(t, 0, bres.CheckTx.Code)
  68. assert.EqualValues(t, "stand", bres.CheckTx.Data)
  69. assert.EqualValues(t, "deliver", bres.TxResult.Data)
  70. }
  71. func TestABCIRecorder(t *testing.T) {
  72. ctx, cancel := context.WithCancel(context.Background())
  73. defer cancel()
  74. // This mock returns errors on everything but Query
  75. m := mock.ABCIMock{
  76. Info: mock.Call{Response: abci.ResponseInfo{
  77. Data: "data",
  78. Version: "v0.9.9",
  79. }},
  80. Query: mock.Call{Error: errors.New("query")},
  81. Broadcast: mock.Call{Error: errors.New("broadcast")},
  82. BroadcastCommit: mock.Call{Error: errors.New("broadcast_commit")},
  83. }
  84. r := mock.NewABCIRecorder(m)
  85. require.Equal(t, 0, len(r.Calls))
  86. _, err := r.ABCIInfo(ctx)
  87. assert.NoError(t, err, "expected no err on info")
  88. _, err = r.ABCIQueryWithOptions(
  89. ctx,
  90. "path",
  91. bytes.HexBytes("data"),
  92. client.ABCIQueryOptions{Prove: false},
  93. )
  94. assert.Error(t, err, "expected error on query")
  95. require.Equal(t, 2, len(r.Calls))
  96. info := r.Calls[0]
  97. assert.Equal(t, "abci_info", info.Name)
  98. assert.Nil(t, info.Error)
  99. assert.Nil(t, info.Args)
  100. require.NotNil(t, info.Response)
  101. ir, ok := info.Response.(*coretypes.ResultABCIInfo)
  102. require.True(t, ok)
  103. assert.Equal(t, "data", ir.Response.Data)
  104. assert.Equal(t, "v0.9.9", ir.Response.Version)
  105. query := r.Calls[1]
  106. assert.Equal(t, "abci_query", query.Name)
  107. assert.Nil(t, query.Response)
  108. require.NotNil(t, query.Error)
  109. assert.Equal(t, "query", query.Error.Error())
  110. require.NotNil(t, query.Args)
  111. qa, ok := query.Args.(mock.QueryArgs)
  112. require.True(t, ok)
  113. assert.Equal(t, "path", qa.Path)
  114. assert.EqualValues(t, "data", qa.Data)
  115. assert.False(t, qa.Prove)
  116. // now add some broadcasts (should all err)
  117. txs := []types.Tx{{1}, {2}, {3}}
  118. _, err = r.BroadcastTxCommit(ctx, txs[0])
  119. assert.Error(t, err, "expected err on broadcast")
  120. _, err = r.BroadcastTxSync(ctx, txs[1])
  121. assert.Error(t, err, "expected err on broadcast")
  122. _, err = r.BroadcastTxAsync(ctx, txs[2])
  123. assert.Error(t, err, "expected err on broadcast")
  124. require.Equal(t, 5, len(r.Calls))
  125. bc := r.Calls[2]
  126. assert.Equal(t, "broadcast_tx_commit", bc.Name)
  127. assert.Nil(t, bc.Response)
  128. require.NotNil(t, bc.Error)
  129. assert.EqualValues(t, bc.Args, txs[0])
  130. bs := r.Calls[3]
  131. assert.Equal(t, "broadcast_tx_sync", bs.Name)
  132. assert.Nil(t, bs.Response)
  133. require.NotNil(t, bs.Error)
  134. assert.EqualValues(t, bs.Args, txs[1])
  135. ba := r.Calls[4]
  136. assert.Equal(t, "broadcast_tx_async", ba.Name)
  137. assert.Nil(t, ba.Response)
  138. require.NotNil(t, ba.Error)
  139. assert.EqualValues(t, ba.Args, txs[2])
  140. }
  141. func TestABCIApp(t *testing.T) {
  142. app := kvstore.NewApplication()
  143. m := mock.ABCIApp{app}
  144. ctx, cancel := context.WithCancel(context.Background())
  145. defer cancel()
  146. // get some info
  147. info, err := m.ABCIInfo(ctx)
  148. require.NoError(t, err)
  149. assert.Equal(t, `{"size":0}`, info.Response.GetData())
  150. // add a key
  151. key, value := "foo", "bar"
  152. tx := fmt.Sprintf("%s=%s", key, value)
  153. res, err := m.BroadcastTxCommit(ctx, types.Tx(tx))
  154. require.NoError(t, err)
  155. assert.True(t, res.CheckTx.IsOK())
  156. require.NotNil(t, res.TxResult)
  157. assert.True(t, res.TxResult.IsOK())
  158. // commit
  159. // TODO: This may not be necessary in the future
  160. if res.Height == -1 {
  161. m.App.Commit()
  162. }
  163. // check the key
  164. _qres, err := m.ABCIQueryWithOptions(
  165. ctx,
  166. "/key",
  167. bytes.HexBytes(key),
  168. client.ABCIQueryOptions{Prove: true},
  169. )
  170. qres := _qres.Response
  171. require.NoError(t, err)
  172. assert.EqualValues(t, value, qres.Value)
  173. // XXX Check proof
  174. }