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.

65 lines
1.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
  1. package client_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. abci "github.com/tendermint/tendermint/abci/types"
  9. tmrand "github.com/tendermint/tendermint/libs/rand"
  10. "github.com/tendermint/tendermint/rpc/client"
  11. "github.com/tendermint/tendermint/rpc/coretypes"
  12. "github.com/tendermint/tendermint/types"
  13. )
  14. const waitForEventTimeout = 2 * time.Second
  15. // MakeTxKV returns a text transaction, allong with expected key, value pair
  16. func MakeTxKV() ([]byte, []byte, []byte) {
  17. k := []byte(tmrand.Str(8))
  18. v := []byte(tmrand.Str(8))
  19. return k, v, append(k, append([]byte("="), v...)...)
  20. }
  21. func testTxEventsSent(ctx context.Context, t *testing.T, broadcastMethod string, c client.Client) {
  22. t.Helper()
  23. // make the tx
  24. _, _, tx := MakeTxKV()
  25. // send
  26. done := make(chan struct{})
  27. go func() {
  28. defer close(done)
  29. var (
  30. txres *coretypes.ResultBroadcastTx
  31. err error
  32. )
  33. switch broadcastMethod {
  34. case "async":
  35. txres, err = c.BroadcastTxAsync(ctx, tx)
  36. case "sync":
  37. txres, err = c.BroadcastTxSync(ctx, tx)
  38. default:
  39. require.FailNowf(t, "Unknown broadcastMethod %s", broadcastMethod)
  40. }
  41. if assert.NoError(t, err) {
  42. assert.Equal(t, txres.Code, abci.CodeTypeOK)
  43. }
  44. }()
  45. // and wait for confirmation
  46. evt, err := client.WaitForOneEvent(ctx, c, types.EventTxValue, waitForEventTimeout)
  47. require.NoError(t, err)
  48. // and make sure it has the proper info
  49. txe, ok := evt.(types.EventDataTx)
  50. require.True(t, ok)
  51. // make sure this is the proper tx
  52. require.EqualValues(t, tx, txe.Tx)
  53. require.True(t, txe.Result.IsOK())
  54. <-done
  55. }