(t *testing.T)
| 203 | } |
| 204 | |
| 205 | func TestDHTService_Ping(t *testing.T) { |
| 206 | utils.RemoveAll(DHTStorePath + "*") |
| 207 | defer utils.RemoveAll(DHTStorePath + "*") |
| 208 | log.SetLevel(log.DebugLevel) |
| 209 | addr := "127.0.0.1:0" |
| 210 | |
| 211 | dht, _ := NewDHTService(DHTStorePath, new(consistent.KMSStorage), false) |
| 212 | rpc.RegisterName(DHTRPCName, dht) |
| 213 | ln, err := net.Listen("tcp", addr) |
| 214 | if err != nil { |
| 215 | fmt.Println(err) |
| 216 | return |
| 217 | } |
| 218 | |
| 219 | go func() { |
| 220 | for { |
| 221 | c, err := ln.Accept() |
| 222 | if err != nil { |
| 223 | continue |
| 224 | } |
| 225 | go rpc.ServeCodec(utils.GetMsgPackServerCodec(c)) |
| 226 | } |
| 227 | }() |
| 228 | |
| 229 | client, err := net.Dial("tcp", ln.Addr().String()) |
| 230 | if err != nil { |
| 231 | log.Error(err) |
| 232 | } |
| 233 | |
| 234 | NewNodeIDDifficultyTimeout = 100 * time.Millisecond |
| 235 | node1 := NewNode() |
| 236 | node1.InitNodeCryptoInfo(100 * time.Millisecond) |
| 237 | |
| 238 | reqA := &PingReq{ |
| 239 | Node: *node1, |
| 240 | } |
| 241 | respA := new(PingResp) |
| 242 | rc := rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client)) |
| 243 | err = rc.Call("DHT.Ping", reqA, respA) |
| 244 | if err != nil { |
| 245 | t.Error(err) |
| 246 | } |
| 247 | log.Debugf("respA: %v", respA) |
| 248 | rc.Close() |
| 249 | |
| 250 | respA3 := new(PingResp) |
| 251 | conf.GConf.MinNodeIDDifficulty = 256 |
| 252 | client, _ = net.Dial("tcp", ln.Addr().String()) |
| 253 | rc = rpc.NewClientWithCodec(utils.GetMsgPackClientCodec(client)) |
| 254 | err = rc.Call("DHT.Ping", reqA, respA3) |
| 255 | if err == nil || !strings.Contains(err.Error(), "difficulty too low") { |
| 256 | t.Error(err) |
| 257 | } |
| 258 | log.Debugf("respA3: %v", respA3) |
| 259 | rc.Close() |
| 260 | |
| 261 | respA2 := new(PingResp) |
| 262 | reqA.Node.Nonce.A = ^uint64(0) |
nothing calls this directly
no test coverage detected