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.

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