mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-21 22:11:46 +01:00
improve tests
This commit is contained in:
parent
d26758b2d7
commit
a055abb738
5 changed files with 296 additions and 233 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -23,5 +23,5 @@ dependency-reduced-pom.xml
|
|||
*.iml
|
||||
target/
|
||||
project/target
|
||||
DeleteMe*.scala
|
||||
DeleteMe*.*
|
||||
*~
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
package fr.acinq.eclair.channel
|
||||
|
||||
import akka.actor.{ActorSystem, Props}
|
||||
import akka.testkit.{ImplicitSender, TestKit}
|
||||
import fr.acinq.bitcoin._
|
||||
import fr.acinq.eclair._
|
||||
import fr.acinq.eclair.blockchain._
|
||||
import lightning._
|
||||
import lightning.locktime.Locktime.Blocks
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest._
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class BarSpec extends TestKit(ActorSystem("TestSystem")) with WordSpecLike with ShouldMatchers with ImplicitSender {
|
||||
|
||||
val anchorAmount = 100100000L
|
||||
|
||||
// Alice is funder, Bob is not
|
||||
|
||||
object Alice {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cQPmcNr6pwBQPyGfab3SksE9nTCtx9ism9T4dkS9dETNU2KKtJHk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cUrAtLtV7GGddqdkhUxnbZVDWGJBTducpPoon3eKp9Vnr1zxs6BG")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 1, 100000, "alice-seed".getBytes(), Some(anchorAmount))
|
||||
}
|
||||
|
||||
object Bob {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cSUwLtdZ2tht9ZmHhdQue48pfe7tY2GT2TGWJDtjoZgo6FHrubGk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cPR7ZgXpUaDPA3GwGceMDS5pfnSm955yvks3yELf3wMJwegsdGTg")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 2, 100000, "bob-seed".getBytes(), None)
|
||||
}
|
||||
|
||||
"channel" should {
|
||||
"open, manage htlcs and close" in {
|
||||
val alice = system.actorOf(Props(new Channel(self, Alice.channelParams)), "Alice")
|
||||
val bob = system.actorOf(Props(new Channel(self, Bob.channelParams)), "Bob")
|
||||
|
||||
alice.tell(INPUT_NONE, bob)
|
||||
bob.tell(INPUT_NONE, alice)
|
||||
|
||||
val MakeAnchor(_, _, amount) = expectMsgClass(classOf[MakeAnchor])
|
||||
val anchorTx = Transaction(version = 1,
|
||||
txIn = Seq.empty[TxIn],
|
||||
txOut = TxOut(amount, Scripts.anchorPubkeyScript(Alice.channelParams.commitPubKey, Bob.channelParams.commitPubKey)) :: Nil,
|
||||
lockTime = 0
|
||||
)
|
||||
alice ! (anchorTx, 0)
|
||||
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
expectMsgClass(classOf[WatchSpent])
|
||||
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
expectMsgClass(classOf[WatchSpent])
|
||||
expectMsgClass(classOf[Publish])
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAITING_OURANCHOR)
|
||||
|
||||
alice ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[WatchLost])
|
||||
|
||||
bob ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[WatchLost])
|
||||
|
||||
Thread.sleep(100)
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_HIGHPRIO)
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_LOWPRIO)
|
||||
|
||||
val R: BinaryData = "0102030405060708010203040506070801020304050607080102030405060708"
|
||||
val H = Crypto.sha256(R)
|
||||
alice ! CMD_SEND_HTLC_UPDATE(60000000, H, locktime(Blocks(4)))
|
||||
|
||||
Thread.sleep(100)
|
||||
|
||||
bob ! CMD_SEND_HTLC_FULFILL(R)
|
||||
|
||||
Thread.sleep(100)
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_HIGHPRIO)
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_LOWPRIO)
|
||||
|
||||
alice ! CMD_CLOSE(10000)
|
||||
|
||||
expectMsgClass(classOf[WatchConfirmedBasedOnOutputs])
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx1) = expectMsgClass(classOf[Publish])
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx2) = expectMsgClass(classOf[Publish])
|
||||
|
||||
Thread.sleep(100)
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(CLOSING)
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(CLOSING)
|
||||
|
||||
alice ! (BITCOIN_ANCHOR_SPENT, closingTx1)
|
||||
bob ! (BITCOIN_ANCHOR_SPENT, closingTx1)
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(CLOSING)
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(CLOSING)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package fr.acinq.eclair.channel
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import akka.actor.FSM.{CurrentState, SubscribeTransitionCallBack, Transition}
|
||||
import akka.actor.{Terminated, ActorRef, ActorSystem, Props}
|
||||
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
|
||||
import fr.acinq.bitcoin._
|
||||
import fr.acinq.eclair._
|
||||
import fr.acinq.eclair.blockchain._
|
||||
import lightning._
|
||||
import lightning.locktime.Locktime.Blocks
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest._
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class Channel2Spec extends TestKit(ActorSystem("TestSystem")) with fixture.WordSpecLike with ShouldMatchers with ImplicitSender {
|
||||
|
||||
val anchorAmount = 100100000L
|
||||
|
||||
// Alice is funder, Bob is not
|
||||
|
||||
object Alice {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cQPmcNr6pwBQPyGfab3SksE9nTCtx9ism9T4dkS9dETNU2KKtJHk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cUrAtLtV7GGddqdkhUxnbZVDWGJBTducpPoon3eKp9Vnr1zxs6BG")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 1, 100000, "alice-seed".getBytes(), Some(anchorAmount))
|
||||
}
|
||||
|
||||
object Bob {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cSUwLtdZ2tht9ZmHhdQue48pfe7tY2GT2TGWJDtjoZgo6FHrubGk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cPR7ZgXpUaDPA3GwGceMDS5pfnSm955yvks3yELf3wMJwegsdGTg")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 2, 100000, "bob-seed".getBytes(), None)
|
||||
}
|
||||
|
||||
case class FixtureParam(alice: ActorRef, bob: ActorRef, monitora: TestProbe, monitorb: TestProbe, blockchain: TestProbe) {
|
||||
def waitForAliceTransition = monitora.expectMsgClass(classOf[Transition[_]])
|
||||
def waitForBobTransition = monitorb.expectMsgClass(classOf[Transition[_]])
|
||||
}
|
||||
|
||||
def withFixture(test: OneArgTest) = {
|
||||
val blockchain = TestProbe("blockchain")
|
||||
val alice = system.actorOf(Props(new Channel(blockchain.ref, Alice.channelParams)), "Alice")
|
||||
val bob = system.actorOf(Props(new Channel(blockchain.ref, Bob.channelParams)), "Bob")
|
||||
|
||||
val monitora = TestProbe()
|
||||
val monitorb = TestProbe()
|
||||
|
||||
alice ! SubscribeTransitionCallBack(monitora.ref)
|
||||
val CurrentState(_, INIT_WITHANCHOR) = monitora.expectMsgClass(classOf[CurrentState[_]])
|
||||
|
||||
bob ! SubscribeTransitionCallBack(monitorb.ref)
|
||||
val CurrentState(_, INIT_NOANCHOR) = monitorb.expectMsgClass(classOf[CurrentState[_]])
|
||||
|
||||
alice.tell(INPUT_NONE, bob)
|
||||
bob.tell(INPUT_NONE, alice)
|
||||
|
||||
val theFixture = FixtureParam(alice, bob, monitora, monitorb, blockchain)
|
||||
val Transition(_, INIT_WITHANCHOR, OPEN_WAIT_FOR_OPEN_WITHANCHOR) = theFixture.waitForAliceTransition
|
||||
val Transition(_, INIT_NOANCHOR, OPEN_WAIT_FOR_OPEN_NOANCHOR) = theFixture.waitForBobTransition
|
||||
|
||||
try {
|
||||
withFixture(test.toNoArgTest(theFixture)) // "loan" the fixture to the test
|
||||
}
|
||||
finally {
|
||||
monitora.watch(alice)
|
||||
monitorb.watch(bob)
|
||||
system.stop(alice)
|
||||
system.stop(bob)
|
||||
monitora.receiveWhile(){
|
||||
case Terminated(_) => false
|
||||
case _ => true
|
||||
}
|
||||
monitorb.receiveWhile(){
|
||||
case Terminated(_) => false
|
||||
case _ => true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"channel" should {
|
||||
"open, propose, accept, fulfill htlcs and close" in { f =>
|
||||
import f._
|
||||
|
||||
val MakeAnchor(_, _, amount) = blockchain.expectMsgClass(classOf[MakeAnchor])
|
||||
val anchorTx = Transaction(version = 1,
|
||||
txIn = Seq.empty[TxIn],
|
||||
txOut = TxOut(amount, Scripts.anchorPubkeyScript(Alice.channelParams.commitPubKey, Bob.channelParams.commitPubKey)) :: Nil,
|
||||
lockTime = 0
|
||||
)
|
||||
blockchain.reply((anchorTx, 0))
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
blockchain.expectMsgClass(classOf[WatchSpent])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
blockchain.expectMsgClass(classOf[WatchSpent])
|
||||
blockchain.expectMsgClass(classOf[Publish])
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_OPEN_WITHANCHOR, OPEN_WAIT_FOR_COMMIT_SIG) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_OPEN_NOANCHOR, OPEN_WAIT_FOR_ANCHOR) = waitForBobTransition
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_COMMIT_SIG, OPEN_WAITING_OURANCHOR) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_ANCHOR, OPEN_WAITING_THEIRANCHOR) = waitForBobTransition
|
||||
|
||||
blockchain.send(alice, BITCOIN_ANCHOR_DEPTHOK)
|
||||
blockchain.expectMsgClass(classOf[WatchLost])
|
||||
|
||||
blockchain.send(bob, BITCOIN_ANCHOR_DEPTHOK)
|
||||
blockchain.expectMsgClass(classOf[WatchLost])
|
||||
|
||||
val Transition(_, OPEN_WAITING_OURANCHOR, OPEN_WAIT_FOR_COMPLETE_OURANCHOR) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAITING_THEIRANCHOR, OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR) = waitForBobTransition
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_COMPLETE_OURANCHOR, NORMAL_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR, NORMAL_LOWPRIO) = waitForBobTransition
|
||||
|
||||
val R: BinaryData = "0102030405060708010203040506070801020304050607080102030405060708"
|
||||
val H = Crypto.sha256(R)
|
||||
alice ! CMD_SEND_HTLC_UPDATE(60000000, H, locktime(Blocks(4)))
|
||||
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_UPDATE_SIG_LOWPRIO) = waitForBobTransition
|
||||
|
||||
val Transition(_, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO, NORMAL_LOWPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_SIG_LOWPRIO, NORMAL_HIGHPRIO) = waitForBobTransition
|
||||
|
||||
bob ! CMD_SEND_HTLC_FULFILL(R)
|
||||
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_UPDATE_SIG_LOWPRIO) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO) = waitForBobTransition
|
||||
|
||||
val Transition(_, WAIT_FOR_UPDATE_SIG_LOWPRIO, NORMAL_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO) = waitForBobTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO, NORMAL_LOWPRIO) = waitForBobTransition
|
||||
|
||||
alice ! CMD_CLOSE(10000)
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_CLOSE_COMPLETE) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_CLOSE_ACK) = waitForBobTransition
|
||||
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmedBasedOnOutputs])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx1) = blockchain.expectMsgClass(classOf[Publish])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx2) = blockchain.expectMsgClass(classOf[Publish])
|
||||
|
||||
val Transition(_, WAIT_FOR_CLOSE_COMPLETE, CLOSING) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_CLOSE_ACK, CLOSING) = waitForBobTransition
|
||||
|
||||
blockchain.send(alice, (BITCOIN_ANCHOR_SPENT, closingTx1))
|
||||
blockchain.send(bob, (BITCOIN_ANCHOR_SPENT, closingTx1))
|
||||
|
||||
blockchain.send(alice, BITCOIN_CLOSE_DONE)
|
||||
blockchain.send(bob, BITCOIN_CLOSE_DONE)
|
||||
|
||||
val Transition(_, CLOSING, CLOSED) = waitForAliceTransition
|
||||
val Transition(_, CLOSING, CLOSED) = waitForBobTransition
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package fr.acinq.eclair.channel
|
||||
|
||||
import akka.actor.FSM.{Transition, CurrentState, SubscribeTransitionCallBack}
|
||||
import akka.actor.{Actor, ActorSystem, Props}
|
||||
import akka.actor.ActorDSL._
|
||||
import akka.testkit.{TestProbe, ImplicitSender, TestKit}
|
||||
import fr.acinq.bitcoin._
|
||||
import fr.acinq.eclair._
|
||||
import fr.acinq.eclair.blockchain._
|
||||
import lightning._
|
||||
import lightning.locktime.Locktime.Blocks
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest._
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class ChannelSpec extends TestKit(ActorSystem("TestSystem")) with WordSpecLike with ShouldMatchers with ImplicitSender {
|
||||
|
||||
val anchorAmount = 100100000L
|
||||
|
||||
// Alice is funder, Bob is not
|
||||
|
||||
object Alice {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cQPmcNr6pwBQPyGfab3SksE9nTCtx9ism9T4dkS9dETNU2KKtJHk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cUrAtLtV7GGddqdkhUxnbZVDWGJBTducpPoon3eKp9Vnr1zxs6BG")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 1, 100000, "alice-seed".getBytes(), Some(anchorAmount))
|
||||
}
|
||||
|
||||
object Bob {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cSUwLtdZ2tht9ZmHhdQue48pfe7tY2GT2TGWJDtjoZgo6FHrubGk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cPR7ZgXpUaDPA3GwGceMDS5pfnSm955yvks3yELf3wMJwegsdGTg")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 2, 100000, "bob-seed".getBytes(), None)
|
||||
}
|
||||
|
||||
"channel" should {
|
||||
"open, propose, accept, fulfill htlcs and close" in {
|
||||
val blockchain = TestProbe("blockchain")
|
||||
val alice = system.actorOf(Props(new Channel(blockchain.ref, Alice.channelParams)), "Alice")
|
||||
val bob = system.actorOf(Props(new Channel(blockchain.ref, Bob.channelParams)), "Bob")
|
||||
|
||||
val monitora = TestProbe()
|
||||
val monitorb = TestProbe()
|
||||
|
||||
alice ! SubscribeTransitionCallBack(monitora.ref)
|
||||
val CurrentState(_, INIT_WITHANCHOR) = monitora.expectMsgClass(classOf[CurrentState[_]])
|
||||
|
||||
bob ! SubscribeTransitionCallBack(monitorb.ref)
|
||||
val CurrentState(_, INIT_NOANCHOR) = monitorb.expectMsgClass(classOf[CurrentState[_]])
|
||||
|
||||
alice.tell(INPUT_NONE, bob)
|
||||
bob.tell(INPUT_NONE, alice)
|
||||
|
||||
def waitForAliceTransition = monitora.expectMsgClass(classOf[Transition[_]])
|
||||
def waitForBobTransition = monitorb.expectMsgClass(classOf[Transition[_]])
|
||||
|
||||
val Transition(_, INIT_WITHANCHOR, OPEN_WAIT_FOR_OPEN_WITHANCHOR) = waitForAliceTransition
|
||||
val Transition(_, INIT_NOANCHOR, OPEN_WAIT_FOR_OPEN_NOANCHOR) = waitForBobTransition
|
||||
|
||||
val MakeAnchor(_, _, amount) = blockchain.expectMsgClass(classOf[MakeAnchor])
|
||||
val anchorTx = Transaction(version = 1,
|
||||
txIn = Seq.empty[TxIn],
|
||||
txOut = TxOut(amount, Scripts.anchorPubkeyScript(Alice.channelParams.commitPubKey, Bob.channelParams.commitPubKey)) :: Nil,
|
||||
lockTime = 0
|
||||
)
|
||||
blockchain.reply((anchorTx, 0))
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
blockchain.expectMsgClass(classOf[WatchSpent])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
blockchain.expectMsgClass(classOf[WatchSpent])
|
||||
blockchain.expectMsgClass(classOf[Publish])
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_OPEN_WITHANCHOR, OPEN_WAIT_FOR_COMMIT_SIG) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_OPEN_NOANCHOR, OPEN_WAIT_FOR_ANCHOR) = waitForBobTransition
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_COMMIT_SIG, OPEN_WAITING_OURANCHOR) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_ANCHOR, OPEN_WAITING_THEIRANCHOR) = waitForBobTransition
|
||||
|
||||
blockchain.send(alice, BITCOIN_ANCHOR_DEPTHOK)
|
||||
blockchain.expectMsgClass(classOf[WatchLost])
|
||||
|
||||
blockchain.send(bob, BITCOIN_ANCHOR_DEPTHOK)
|
||||
blockchain.expectMsgClass(classOf[WatchLost])
|
||||
|
||||
val Transition(_, OPEN_WAITING_OURANCHOR, OPEN_WAIT_FOR_COMPLETE_OURANCHOR) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAITING_THEIRANCHOR, OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR) = waitForBobTransition
|
||||
|
||||
val Transition(_, OPEN_WAIT_FOR_COMPLETE_OURANCHOR, NORMAL_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR, NORMAL_LOWPRIO) = waitForBobTransition
|
||||
|
||||
val R: BinaryData = "0102030405060708010203040506070801020304050607080102030405060708"
|
||||
val H = Crypto.sha256(R)
|
||||
alice ! CMD_SEND_HTLC_UPDATE(60000000, H, locktime(Blocks(4)))
|
||||
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_UPDATE_SIG_LOWPRIO) = waitForBobTransition
|
||||
|
||||
val Transition(_, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO, NORMAL_LOWPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_SIG_LOWPRIO, NORMAL_HIGHPRIO) = waitForBobTransition
|
||||
|
||||
bob ! CMD_SEND_HTLC_FULFILL(R)
|
||||
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_UPDATE_SIG_LOWPRIO) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO) = waitForBobTransition
|
||||
|
||||
val Transition(_, WAIT_FOR_UPDATE_SIG_LOWPRIO, NORMAL_HIGHPRIO) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_HTLC_ACCEPT_HIGHPRIO, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO) = waitForBobTransition
|
||||
val Transition(_, WAIT_FOR_UPDATE_COMPLETE_HIGHPRIO, NORMAL_LOWPRIO) = waitForBobTransition
|
||||
|
||||
alice ! CMD_CLOSE(10000)
|
||||
val Transition(_, NORMAL_HIGHPRIO, WAIT_FOR_CLOSE_COMPLETE) = waitForAliceTransition
|
||||
val Transition(_, NORMAL_LOWPRIO, WAIT_FOR_CLOSE_ACK) = waitForBobTransition
|
||||
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmedBasedOnOutputs])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx1) = blockchain.expectMsgClass(classOf[Publish])
|
||||
blockchain.expectMsgClass(classOf[WatchConfirmed])
|
||||
val Publish(closingTx2) = blockchain.expectMsgClass(classOf[Publish])
|
||||
|
||||
val Transition(_, WAIT_FOR_CLOSE_COMPLETE, CLOSING) = waitForAliceTransition
|
||||
val Transition(_, WAIT_FOR_CLOSE_ACK, CLOSING) = waitForBobTransition
|
||||
|
||||
blockchain.send(alice, (BITCOIN_ANCHOR_SPENT, closingTx1))
|
||||
blockchain.send(bob, (BITCOIN_ANCHOR_SPENT, closingTx1))
|
||||
|
||||
blockchain.send(alice, BITCOIN_CLOSE_DONE)
|
||||
blockchain.send(bob, BITCOIN_CLOSE_DONE)
|
||||
|
||||
val Transition(_, CLOSING, CLOSED) = waitForAliceTransition
|
||||
val Transition(_, CLOSING, CLOSED) = waitForBobTransition
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
package fr.acinq.eclair.channel
|
||||
|
||||
import akka.actor.{ActorSystem, Props}
|
||||
import akka.testkit.{ImplicitSender, TestKit}
|
||||
import fr.acinq.bitcoin._
|
||||
import fr.acinq.eclair._
|
||||
import fr.acinq.eclair.blockchain._
|
||||
import lightning._
|
||||
import lightning.locktime.Locktime.Blocks
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest._
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class FooSpec extends TestKit(ActorSystem("TestSystem")) with WordSpecLike with ShouldMatchers with ImplicitSender {
|
||||
|
||||
val anchorAmount = 100100000L
|
||||
|
||||
// Alice is funder, Bob is not
|
||||
|
||||
object Alice {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cQPmcNr6pwBQPyGfab3SksE9nTCtx9ism9T4dkS9dETNU2KKtJHk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cUrAtLtV7GGddqdkhUxnbZVDWGJBTducpPoon3eKp9Vnr1zxs6BG")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 1, 100000, "alice-seed".getBytes(), Some(anchorAmount))
|
||||
}
|
||||
|
||||
object Bob {
|
||||
val (Base58.Prefix.SecretKeyTestnet, commitPrivKey) = Base58Check.decode("cSUwLtdZ2tht9ZmHhdQue48pfe7tY2GT2TGWJDtjoZgo6FHrubGk")
|
||||
val (Base58.Prefix.SecretKeyTestnet, finalPrivKey) = Base58Check.decode("cPR7ZgXpUaDPA3GwGceMDS5pfnSm955yvks3yELf3wMJwegsdGTg")
|
||||
val channelParams = OurChannelParams(locktime(Blocks(10)), commitPrivKey, finalPrivKey, 2, 100000, "bob-seed".getBytes(), None)
|
||||
}
|
||||
|
||||
"channel" should {
|
||||
"reach open state without anchor" in {
|
||||
val alice = system.actorOf(Props(new Channel(self, Alice.channelParams)), "Alice")
|
||||
val bob = system.actorOf(Props(new Channel(self, Bob.channelParams)), "Bob")
|
||||
|
||||
alice ! INPUT_NONE
|
||||
val opena = expectMsgClass(classOf[open_channel])
|
||||
bob ! INPUT_NONE
|
||||
val openb = expectMsgClass(classOf[open_channel])
|
||||
|
||||
bob ! opena
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_ANCHOR)
|
||||
|
||||
alice ! openb
|
||||
val MakeAnchor(_, _, amount) = expectMsgClass(classOf[MakeAnchor])
|
||||
val anchorTx = Transaction(version = 1,
|
||||
txIn = Seq.empty[TxIn],
|
||||
txOut = TxOut(amount, Scripts.anchorPubkeyScript(Alice.channelParams.commitPubKey, Bob.channelParams.commitPubKey)) :: Nil,
|
||||
lockTime = 0
|
||||
)
|
||||
alice ! (anchorTx, 0)
|
||||
val openanchora = expectMsgClass(classOf[open_anchor])
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_COMMIT_SIG)
|
||||
|
||||
bob ! openanchora
|
||||
val opencommitsigb = expectMsgClass(classOf[open_commit_sig])
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
expectMsgClass(classOf[WatchSpent])
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAITING_THEIRANCHOR)
|
||||
|
||||
alice ! opencommitsigb
|
||||
expectMsgClass(classOf[WatchConfirmed])
|
||||
expectMsgClass(classOf[WatchSpent])
|
||||
expectMsgClass(classOf[Publish])
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAITING_OURANCHOR)
|
||||
|
||||
alice ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[WatchLost])
|
||||
val opencompletea = expectMsgClass(classOf[open_complete])
|
||||
|
||||
bob ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[WatchLost])
|
||||
val opencompleteb = expectMsgClass(classOf[open_complete])
|
||||
|
||||
alice ! opencompleteb
|
||||
bob ! opencompletea
|
||||
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_HIGHPRIO)
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_LOWPRIO)
|
||||
|
||||
val R = sha256_hash(1, 2, 1, 2)
|
||||
val H = Crypto.sha256(R)
|
||||
alice ! CMD_SEND_HTLC_UPDATE(60000000, H, locktime(Blocks(4)))
|
||||
val addhtlca = expectMsgClass(classOf[update_add_htlc])
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(WAIT_FOR_HTLC_ACCEPT_HIGHPRIO)
|
||||
|
||||
bob ! addhtlca
|
||||
val htlcacceptb = expectMsgClass(classOf[update_accept])
|
||||
alice ! htlcacceptb
|
||||
val updatesiga = expectMsgClass(classOf[update_signature])
|
||||
bob ! updatesiga
|
||||
val update_complete(preimage) = expectMsgClass(classOf[update_complete])
|
||||
alice ! update_complete(preimage)
|
||||
|
||||
bob ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_HIGHPRIO)
|
||||
alice ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_LOWPRIO)
|
||||
|
||||
bob ! CMD_SEND_HTLC_FULFILL(R)
|
||||
val fulfillhtlcb = expectMsgClass(classOf[update_fulfill_htlc])
|
||||
alice ! fulfillhtlcb
|
||||
|
||||
alice ! CMD_CLOSE(10000)
|
||||
expectMsgClass(classOf[WatchConfirmedBasedOnOutputs])
|
||||
val closea = expectMsgClass(classOf[close_channel])
|
||||
|
||||
bob ! closea
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue