swarm_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package swarm
  17. import (
  18. "testing"
  19. "github.com/ethereum/go-ethereum/common"
  20. )
  21. func TestParseEnsAPIAddress(t *testing.T) {
  22. for _, x := range []struct {
  23. description string
  24. value string
  25. tld string
  26. endpoint string
  27. addr common.Address
  28. }{
  29. {
  30. description: "IPC endpoint",
  31. value: "/data/testnet/geth.ipc",
  32. endpoint: "/data/testnet/geth.ipc",
  33. },
  34. {
  35. description: "HTTP endpoint",
  36. value: "http://127.0.0.1:1234",
  37. endpoint: "http://127.0.0.1:1234",
  38. },
  39. {
  40. description: "WS endpoint",
  41. value: "ws://127.0.0.1:1234",
  42. endpoint: "ws://127.0.0.1:1234",
  43. },
  44. {
  45. description: "IPC Endpoint and TLD",
  46. value: "test:/data/testnet/geth.ipc",
  47. endpoint: "/data/testnet/geth.ipc",
  48. tld: "test",
  49. },
  50. {
  51. description: "HTTP endpoint and TLD",
  52. value: "test:http://127.0.0.1:1234",
  53. endpoint: "http://127.0.0.1:1234",
  54. tld: "test",
  55. },
  56. {
  57. description: "WS endpoint and TLD",
  58. value: "test:ws://127.0.0.1:1234",
  59. endpoint: "ws://127.0.0.1:1234",
  60. tld: "test",
  61. },
  62. {
  63. description: "IPC Endpoint and contract address",
  64. value: "314159265dD8dbb310642f98f50C066173C1259b@/data/testnet/geth.ipc",
  65. endpoint: "/data/testnet/geth.ipc",
  66. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  67. },
  68. {
  69. description: "HTTP endpoint and contract address",
  70. value: "314159265dD8dbb310642f98f50C066173C1259b@http://127.0.0.1:1234",
  71. endpoint: "http://127.0.0.1:1234",
  72. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  73. },
  74. {
  75. description: "WS endpoint and contract address",
  76. value: "314159265dD8dbb310642f98f50C066173C1259b@ws://127.0.0.1:1234",
  77. endpoint: "ws://127.0.0.1:1234",
  78. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  79. },
  80. {
  81. description: "IPC Endpoint, TLD and contract address",
  82. value: "test:314159265dD8dbb310642f98f50C066173C1259b@/data/testnet/geth.ipc",
  83. endpoint: "/data/testnet/geth.ipc",
  84. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  85. tld: "test",
  86. },
  87. {
  88. description: "HTTP endpoint, TLD and contract address",
  89. value: "eth:314159265dD8dbb310642f98f50C066173C1259b@http://127.0.0.1:1234",
  90. endpoint: "http://127.0.0.1:1234",
  91. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  92. tld: "eth",
  93. },
  94. {
  95. description: "WS endpoint, TLD and contract address",
  96. value: "eth:314159265dD8dbb310642f98f50C066173C1259b@ws://127.0.0.1:1234",
  97. endpoint: "ws://127.0.0.1:1234",
  98. addr: common.HexToAddress("314159265dD8dbb310642f98f50C066173C1259b"),
  99. tld: "eth",
  100. },
  101. } {
  102. t.Run(x.description, func(t *testing.T) {
  103. tld, endpoint, addr := parseEnsAPIAddress(x.value)
  104. if endpoint != x.endpoint {
  105. t.Errorf("expected Endpoint %q, got %q", x.endpoint, endpoint)
  106. }
  107. if addr != x.addr {
  108. t.Errorf("expected ContractAddress %q, got %q", x.addr.String(), addr.String())
  109. }
  110. if tld != x.tld {
  111. t.Errorf("expected TLD %q, got %q", x.tld, tld)
  112. }
  113. })
  114. }
  115. }