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.

73 lines
1.7 KiB

  1. package core
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. cfg "github.com/tendermint/tendermint/config"
  7. "github.com/tendermint/tendermint/libs/log"
  8. "github.com/tendermint/tendermint/p2p"
  9. rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
  10. )
  11. func TestUnsafeDialSeeds(t *testing.T) {
  12. sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123",
  13. func(n int, sw *p2p.Switch) *p2p.Switch { return sw })
  14. err := sw.Start()
  15. require.NoError(t, err)
  16. defer sw.Stop()
  17. logger = log.TestingLogger()
  18. p2pPeers = sw
  19. testCases := []struct {
  20. seeds []string
  21. isErr bool
  22. }{
  23. {[]string{}, true},
  24. {[]string{"d51fb70907db1c6c2d5237e78379b25cf1a37ab4@127.0.0.1:41198"}, false},
  25. {[]string{"127.0.0.1:41198"}, true},
  26. }
  27. for _, tc := range testCases {
  28. res, err := UnsafeDialSeeds(&rpctypes.Context{}, tc.seeds)
  29. if tc.isErr {
  30. assert.Error(t, err)
  31. } else {
  32. assert.NoError(t, err)
  33. assert.NotNil(t, res)
  34. }
  35. }
  36. }
  37. func TestUnsafeDialPeers(t *testing.T) {
  38. sw := p2p.MakeSwitch(cfg.DefaultP2PConfig(), 1, "testing", "123.123.123",
  39. func(n int, sw *p2p.Switch) *p2p.Switch { return sw })
  40. err := sw.Start()
  41. require.NoError(t, err)
  42. defer sw.Stop()
  43. logger = log.TestingLogger()
  44. p2pPeers = sw
  45. testCases := []struct {
  46. peers []string
  47. isErr bool
  48. }{
  49. {[]string{}, true},
  50. {[]string{"d51fb70907db1c6c2d5237e78379b25cf1a37ab4@127.0.0.1:41198"}, false},
  51. {[]string{"127.0.0.1:41198"}, true},
  52. }
  53. for _, tc := range testCases {
  54. res, err := UnsafeDialPeers(&rpctypes.Context{}, tc.peers, false)
  55. if tc.isErr {
  56. assert.Error(t, err)
  57. } else {
  58. assert.NoError(t, err)
  59. assert.NotNil(t, res)
  60. }
  61. }
  62. }