-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register can forward messages to nodes (#2863)
We add a `ForwardNodeId` command to the `Register` to forward messages to a `Peer` actor based on its `node_id`.
- Loading branch information
Showing
9 changed files
with
128 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 63 additions & 13 deletions
76
eclair-core/src/test/scala/fr/acinq/eclair/channel/RegisterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,74 @@ | ||
package fr.acinq.eclair.channel | ||
|
||
import fr.acinq.eclair._ | ||
|
||
import akka.actor.{ActorRef, Props} | ||
import akka.testkit.TestProbe | ||
import akka.actor.typed.scaladsl.adapter._ | ||
import akka.actor.{ActorRef, PoisonPill} | ||
import akka.testkit.{TestActorRef, TestProbe} | ||
import fr.acinq.bitcoin.scalacompat.ByteVector32 | ||
import fr.acinq.bitcoin.scalacompat.Crypto.PublicKey | ||
import org.scalatest.funsuite.AnyFunSuiteLike | ||
import org.scalatest.ParallelTestExecution | ||
import fr.acinq.eclair._ | ||
import fr.acinq.eclair.io.PeerCreated | ||
import org.scalatest.funsuite.FixtureAnyFunSuiteLike | ||
import org.scalatest.{Outcome, ParallelTestExecution} | ||
|
||
class RegisterSpec extends TestKitBaseClass with AnyFunSuiteLike with ParallelTestExecution { | ||
class RegisterSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with ParallelTestExecution { | ||
|
||
case class CustomChannelRestored(channel: ActorRef, channelId: ByteVector32, peer: ActorRef, remoteNodeId: PublicKey) extends AbstractChannelRestored | ||
|
||
test("register processes custom restored events") { | ||
val sender = TestProbe() | ||
val registerRef = system.actorOf(Register.props()) | ||
case class FixtureParam(register: TestActorRef[Register], probe: TestProbe) | ||
|
||
override def withFixture(test: OneArgTest): Outcome = { | ||
val probe = TestProbe() | ||
system.eventStream.subscribe(probe.ref, classOf[SubscriptionsComplete]) | ||
val register = TestActorRef(new Register()) | ||
probe.expectMsg(SubscriptionsComplete(classOf[Register])) | ||
try { | ||
withFixture(test.toNoArgTest(FixtureParam(register, probe))) | ||
} finally { | ||
system.stop(register) | ||
} | ||
} | ||
|
||
test("process custom restored events") { f => | ||
import f._ | ||
|
||
val customRestoredEvent = CustomChannelRestored(TestProbe().ref, randomBytes32(), TestProbe().ref, randomKey().publicKey) | ||
registerRef ! customRestoredEvent | ||
sender.send(registerRef, Symbol("channels")) | ||
sender.expectMsgType[Map[ByteVector32, ActorRef]] == Map(customRestoredEvent.channelId -> customRestoredEvent.channel) | ||
system.eventStream.publish(customRestoredEvent) | ||
awaitAssert({ | ||
probe.send(register, Register.GetChannels) | ||
probe.expectMsgType[Map[ByteVector32, ActorRef]] == Map(customRestoredEvent.channelId -> customRestoredEvent.channel) | ||
}) | ||
} | ||
|
||
test("forward messages to peers") { f => | ||
import f._ | ||
|
||
val nodeId = randomKey().publicKey | ||
val peer1 = TestProbe() | ||
system.eventStream.publish(PeerCreated(peer1.ref, nodeId)) | ||
|
||
awaitAssert({ | ||
register ! Register.ForwardNodeId(probe.ref.toTyped, nodeId, "hello") | ||
peer1.expectMsg("hello") | ||
}) | ||
|
||
// We simulate a race condition, where the peer is recreated but we receive events out of order. | ||
val peer2 = TestProbe() | ||
system.eventStream.publish(PeerCreated(peer2.ref, nodeId)) | ||
awaitAssert({ | ||
register ! Register.ForwardNodeId(probe.ref.toTyped, nodeId, "world") | ||
peer2.expectMsg("world") | ||
}) | ||
register ! Register.PeerTerminated(peer1.ref, nodeId) | ||
|
||
register ! Register.ForwardNodeId(probe.ref.toTyped, nodeId, "hello again") | ||
peer2.expectMsg("hello again") | ||
|
||
peer2.ref ! PoisonPill | ||
awaitAssert({ | ||
val fwd = Register.ForwardNodeId(probe.ref.toTyped, nodeId, "d34d") | ||
register ! fwd | ||
probe.expectMsg(Register.ForwardNodeIdFailure(fwd)) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters