diff --git a/libp2p/protocols/connectivity/autonat.nim b/libp2p/protocols/connectivity/autonat.nim index a6d754d..c63d7e5 100644 --- a/libp2p/protocols/connectivity/autonat.nim +++ b/libp2p/protocols/connectivity/autonat.nim @@ -211,7 +211,8 @@ method dialMe*(a: Autonat, pid: PeerId, addrs: seq[MultiAddress] = newSeq[MultiA if autonatMsg.isNone() or autonatMsg.get().msgType != DialResponse or autonatMsg.get().response.isNone() or - autonatMsg.get().response.get().ma.isNone(): + (autonatMsg.get().response.get().status == Ok and + autonatMsg.get().response.get().ma.isNone()): raise newException(AutonatError, "Unexpected response") else: autonatMsg.get().response.get() diff --git a/tests/testautonat.nim b/tests/testautonat.nim index ce44b58..e1cde99 100644 --- a/tests/testautonat.nim +++ b/tests/testautonat.nim @@ -34,7 +34,7 @@ suite "Autonat": teardown: checkTrackers() - asyncTest "Simple test": + asyncTest "dialMe returns public address": let src = newStandardSwitch() dst = createAutonatSwitch() @@ -43,9 +43,10 @@ suite "Autonat": await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs) let ma = await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs) + check ma in src.peerInfo.addrs await allFutures(src.stop(), dst.stop()) - asyncTest "Simple failed test": + asyncTest "dialMe handles dial error msg": let src = newStandardSwitch() dst = makeAutonatServicePrivate() @@ -54,6 +55,6 @@ suite "Autonat": await dst.start() await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs) - expect AutonatError: + expect AutonatUnreachableError: discard await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs) await allFutures(src.stop(), dst.stop())