mirror of
https://github.com/ACINQ/eclair.git
synced 2024-11-20 02:27:32 +01:00
Improved test coverage of io
package (#996)
* improved test coverage of `NodeURI` * improved test coverage of `Peer`
This commit is contained in:
parent
847d0999c8
commit
8718959164
@ -32,6 +32,10 @@ class NodeURISpec extends FunSuite {
|
||||
val IPV6_PREFIX = "[2001:db8:a0b:12f0::1/64]"
|
||||
val IPV6_ZONE_IDENTIFIER = "[2001:db8:a0b:12f0::1%eth0]"
|
||||
|
||||
test("default port") {
|
||||
assert(NodeURI.DEFAULT_PORT == 9735)
|
||||
}
|
||||
|
||||
// ---------- IPV4
|
||||
|
||||
test("parse NodeURI with IPV4 and port") {
|
||||
@ -118,6 +122,13 @@ class NodeURISpec extends FunSuite {
|
||||
intercept[IllegalArgumentException](NodeURI.parse(s"$NOT_HEXA_PUB_KEY@$IPV4_ENDURANCE"))
|
||||
}
|
||||
|
||||
// ---------- fail if host:port is not valid
|
||||
|
||||
test("parsing should fail if host:port is not valid") {
|
||||
intercept[IllegalArgumentException](NodeURI.parse(s"$SHORT_PUB_KEY@1.2.3.4:abcd"))
|
||||
intercept[IllegalArgumentException](NodeURI.parse(s"$SHORT_PUB_KEY@1.2.3.4:999999999999999999999"))
|
||||
}
|
||||
|
||||
test("parsing should fail if the uri is malformed") {
|
||||
intercept[IllegalArgumentException](NodeURI.parse("03933884aaf1d6b108397e5efe5c86bcf2d8ca8d2f700eda99db9214fc2712b134@"))
|
||||
intercept[IllegalArgumentException](NodeURI.parse("03933884aaf1d6b108397e5efe5c86bcf2d8ca8d2f700eda99db9214fc2712b134@123.45@654321"))
|
||||
@ -129,6 +140,7 @@ class NodeURISpec extends FunSuite {
|
||||
intercept[IllegalArgumentException](NodeURI.parse("@"))
|
||||
intercept[IllegalArgumentException](NodeURI.parse(":"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,12 +19,14 @@ package fr.acinq.eclair.io
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
import akka.actor.ActorRef
|
||||
import akka.testkit.TestProbe
|
||||
import akka.testkit.{TestFSMRef, TestProbe}
|
||||
import fr.acinq.bitcoin.Crypto.PublicKey
|
||||
import fr.acinq.eclair.TestConstants._
|
||||
import fr.acinq.eclair.blockchain.EclairWallet
|
||||
import fr.acinq.eclair.channel.HasCommitments
|
||||
import fr.acinq.eclair.crypto.TransportHandler
|
||||
import fr.acinq.eclair.io.Peer.{CHANNELID_ZERO, ResumeAnnouncements, SendPing}
|
||||
import fr.acinq.eclair.db.ChannelStateSpec
|
||||
import fr.acinq.eclair.io.Peer._
|
||||
import fr.acinq.eclair.router.RoutingSyncSpec.makeFakeRoutingInfo
|
||||
import fr.acinq.eclair.router.{ChannelRangeQueries, ChannelRangeQueriesSpec, Rebroadcast}
|
||||
import fr.acinq.eclair.wire.{Error, Ping, Pong}
|
||||
@ -41,7 +43,7 @@ class PeerSpec extends TestkitBaseClass {
|
||||
val updates = (fakeRoutingInfo.map(_._2) ++ fakeRoutingInfo.map(_._3)).toList
|
||||
val nodes = (fakeRoutingInfo.map(_._4) ++ fakeRoutingInfo.map(_._5)).toList
|
||||
|
||||
case class FixtureParam(remoteNodeId: PublicKey, authenticator: TestProbe, watcher: TestProbe, router: TestProbe, relayer: TestProbe, connection: TestProbe, transport: TestProbe, peer: ActorRef)
|
||||
case class FixtureParam(remoteNodeId: PublicKey, authenticator: TestProbe, watcher: TestProbe, router: TestProbe, relayer: TestProbe, connection: TestProbe, transport: TestProbe, peer: TestFSMRef[Peer.State, Peer.Data, Peer])
|
||||
|
||||
override protected def withFixture(test: OneArgTest): Outcome = {
|
||||
val authenticator = TestProbe()
|
||||
@ -52,14 +54,14 @@ class PeerSpec extends TestkitBaseClass {
|
||||
val transport = TestProbe()
|
||||
val wallet: EclairWallet = null // unused
|
||||
val remoteNodeId = Bob.nodeParams.nodeId
|
||||
val peer = system.actorOf(Peer.props(Alice.nodeParams, remoteNodeId, authenticator.ref, watcher.ref, router.ref, relayer.ref, wallet))
|
||||
val peer: TestFSMRef[Peer.State, Peer.Data, Peer] = TestFSMRef(new Peer(Alice.nodeParams, remoteNodeId, authenticator.ref, watcher.ref, router.ref, relayer.ref, wallet))
|
||||
withFixture(test.toNoArgTest(FixtureParam(remoteNodeId, authenticator, watcher, router, relayer, connection, transport, peer)))
|
||||
}
|
||||
|
||||
def connect(remoteNodeId: PublicKey, authenticator: TestProbe, watcher: TestProbe, router: TestProbe, relayer: TestProbe, connection: TestProbe, transport: TestProbe, peer: ActorRef): Unit = {
|
||||
def connect(remoteNodeId: PublicKey, authenticator: TestProbe, watcher: TestProbe, router: TestProbe, relayer: TestProbe, connection: TestProbe, transport: TestProbe, peer: ActorRef, channels: Set[HasCommitments] = Set.empty): Unit = {
|
||||
// let's simulate a connection
|
||||
val probe = TestProbe()
|
||||
probe.send(peer, Peer.Init(None, Set.empty))
|
||||
probe.send(peer, Peer.Init(None, channels))
|
||||
authenticator.send(peer, Authenticator.Authenticated(connection.ref, transport.ref, remoteNodeId, new InetSocketAddress("1.2.3.4", 42000), outgoing = true, None))
|
||||
transport.expectMsgType[TransportHandler.Listener]
|
||||
transport.expectMsgType[wire.Init]
|
||||
@ -70,6 +72,67 @@ class PeerSpec extends TestkitBaseClass {
|
||||
assert(probe.expectMsgType[Peer.PeerInfo].state == "CONNECTED")
|
||||
}
|
||||
|
||||
test("restore existing channels") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
connect(remoteNodeId, authenticator, watcher, router, relayer, connection, transport, peer, channels = Set(ChannelStateSpec.normal))
|
||||
probe.send(peer, Peer.GetPeerInfo)
|
||||
probe.expectMsg(PeerInfo(remoteNodeId, "CONNECTED", Some(new InetSocketAddress("1.2.3.4", 42000)), 1))
|
||||
}
|
||||
|
||||
test("ignore connect to same address") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
val previouslyKnownAddress = new InetSocketAddress("1.2.3.4", 9735)
|
||||
probe.send(peer, Peer.Init(Some(previouslyKnownAddress), Set.empty))
|
||||
probe.send(peer, Peer.Connect(NodeURI.parse("03933884aaf1d6b108397e5efe5c86bcf2d8ca8d2f700eda99db9214fc2712b134@1.2.3.4:9735")))
|
||||
probe.expectMsg("reconnection in progress")
|
||||
}
|
||||
|
||||
test("ignore reconnect (no known address)") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
probe.send(peer, Peer.Init(None, Set(ChannelStateSpec.normal)))
|
||||
probe.send(peer, Peer.Reconnect)
|
||||
probe.expectNoMsg()
|
||||
}
|
||||
|
||||
test("ignore reconnect (no channel)") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
val previouslyKnownAddress = new InetSocketAddress("1.2.3.4", 9735)
|
||||
probe.send(peer, Peer.Init(Some(previouslyKnownAddress), Set.empty))
|
||||
probe.send(peer, Peer.Reconnect)
|
||||
probe.expectNoMsg()
|
||||
}
|
||||
|
||||
test("count reconnections") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
val previouslyKnownAddress = new InetSocketAddress("1.2.3.4", 9735)
|
||||
probe.send(peer, Peer.Init(Some(previouslyKnownAddress), Set(ChannelStateSpec.normal)))
|
||||
probe.send(peer, Peer.Reconnect)
|
||||
awaitCond(peer.stateData.asInstanceOf[DisconnectedData].attempts == 1)
|
||||
probe.send(peer, Peer.Reconnect)
|
||||
awaitCond(peer.stateData.asInstanceOf[DisconnectedData].attempts == 2)
|
||||
probe.send(peer, Peer.Reconnect)
|
||||
awaitCond(peer.stateData.asInstanceOf[DisconnectedData].attempts == 3)
|
||||
}
|
||||
|
||||
test("disconnect if incompatible features") {f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
probe.watch(transport.ref)
|
||||
probe.send(peer, Peer.Init(None, Set.empty))
|
||||
authenticator.send(peer, Authenticator.Authenticated(connection.ref, transport.ref, remoteNodeId, new InetSocketAddress("1.2.3.4", 42000), outgoing = true, None))
|
||||
transport.expectMsgType[TransportHandler.Listener]
|
||||
transport.expectMsgType[wire.Init]
|
||||
import scodec.bits._
|
||||
transport.send(peer, wire.Init(Bob.nodeParams.globalFeatures, bin"01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".toByteVector))
|
||||
transport.expectMsgType[TransportHandler.ReadAck]
|
||||
probe.expectTerminated(transport.ref)
|
||||
}
|
||||
|
||||
test("reply to ping") { f =>
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
@ -116,10 +179,11 @@ class PeerSpec extends TestkitBaseClass {
|
||||
import f._
|
||||
val probe = TestProbe()
|
||||
connect(remoteNodeId, authenticator, watcher, router, relayer, connection, transport, peer)
|
||||
val peerActor: ActorRef = peer
|
||||
val rebroadcast = Rebroadcast(
|
||||
channels.map(_ -> Set.empty[ActorRef]).toMap + (channels(5) -> Set(peer)),
|
||||
updates.map(_ -> Set.empty[ActorRef]).toMap + (updates(6) -> Set(peer)) + (updates(10) -> Set(peer)),
|
||||
nodes.map(_ -> Set.empty[ActorRef]).toMap + (nodes(4) -> Set(peer)))
|
||||
channels.map(_ -> Set.empty[ActorRef]).toMap + (channels(5) -> Set(peerActor)),
|
||||
updates.map(_ -> Set.empty[ActorRef]).toMap + (updates(6) -> Set(peerActor)) + (updates(10) -> Set(peerActor)),
|
||||
nodes.map(_ -> Set.empty[ActorRef]).toMap + (nodes(4) -> Set(peerActor)))
|
||||
val filter = wire.GossipTimestampFilter(Alice.nodeParams.chainHash, 0, Long.MaxValue) // no filtering on timestamps
|
||||
probe.send(peer, filter)
|
||||
probe.send(peer, rebroadcast)
|
||||
|
Loading…
Reference in New Issue
Block a user