mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-23 14:40:34 +01:00
added tests on CMD_CLOSE during channel opening sequence (wip)
This commit is contained in:
parent
3144c00fff
commit
12bbe9d2eb
2 changed files with 156 additions and 13 deletions
|
@ -592,7 +592,6 @@ class Node(val blockchain: ActorRef, val commitPrivKey: BinaryData, val finalPri
|
|||
when(WAIT_FOR_UPDATE_COMPLETE_LOWPRIO)(WAIT_FOR_UPDATE_COMPLETE_handler)
|
||||
|
||||
when(WAIT_FOR_CLOSE_COMPLETE) {
|
||||
|
||||
case Event(close_channel_complete(theirSig), DATA_NORMAL(ourParams, theirParams, Commitment(commitment, state, _, _))) =>
|
||||
val finalTx = makeFinalTx(commitment.txIn, ourParams.finalKey, theirParams.finalKey, state)
|
||||
val signedFinalTx = sign_our_commitment_tx(ourParams, theirParams, finalTx, theirSig)
|
||||
|
|
|
@ -7,7 +7,7 @@ import fr.acinq.bitcoin._
|
|||
import fr.acinq.lightning._
|
||||
import lightning.locktime.Locktime.Blocks
|
||||
import lightning._
|
||||
import lightning.open_channel.anchor_offer.WILL_CREATE_ANCHOR
|
||||
import lightning.open_channel.anchor_offer.{WONT_CREATE_ANCHOR, WILL_CREATE_ANCHOR}
|
||||
import org.bouncycastle.util.encoders.Hex
|
||||
import org.scalatest.{BeforeAndAfterAll, WordSpecLike, Matchers}
|
||||
|
||||
|
@ -18,6 +18,7 @@ class ChannelOpenSpec(_system: ActorSystem) extends TestKit(_system) with Implic
|
|||
|
||||
def this() = this(ActorSystem("MySpec"))
|
||||
|
||||
|
||||
override def afterAll {
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
|
@ -37,38 +38,181 @@ class ChannelOpenSpec(_system: ActorSystem) extends TestKit(_system) with Implic
|
|||
|
||||
val ourParams = ChannelParams(our_delay, our_commitkey_pub, our_finalkey_pub, our_mindepth, our_commitment_fee)
|
||||
|
||||
"Bob" must {
|
||||
"Node" must {
|
||||
|
||||
"correctly open a channel in ANCHOR_NOINPUT" in {
|
||||
val bob = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, None)), name = "bob")
|
||||
bob ! INPUT_NONE
|
||||
"successfuly open a channel in ANCHOR_NOINPUT mode" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, None)))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
bob ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WILL_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WILL_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
val anchorTx = makeAnchorTx(ourParams.commitKey, theirParams.commitKey, anchorInput.amount, anchorInput.previousTxOutput, anchorInput.signData)
|
||||
val anchorOutputIndex = 0
|
||||
// we fund the channel with the anchor tx, so the money is ours
|
||||
val state = ChannelState(them = ChannelOneSide(0, 0, Seq()), us = ChannelOneSide(anchorInput.amount - our_commitment_fee, 0, Seq()))
|
||||
// we build our commitment tx, leaving it unsigned
|
||||
val ourCommitTx = makeCommitTx(ourParams.finalKey, theirParams.finalKey, theirParams.delay, anchorTx.hash, anchorOutputIndex, Crypto.sha256(ourRevocationHashPreimage), state)
|
||||
//val ourCommitTx = makeCommitTx(ourParams.finalKey, theirParams.finalKey, theirParams.delay, anchorTx.hash, anchorOutputIndex, theirRevocationHash, state)
|
||||
// then we build their commitment tx and sign it
|
||||
val theirCommitTx = makeCommitTx(theirParams.finalKey, ourParams.finalKey, ourParams.delay, anchorTx.hash, anchorOutputIndex, theirRevocationHash, state.reverse)
|
||||
//val theirCommitTx = makeCommitTx(theirParams.finalKey, ourParams.finalKey, ourParams.delay, anchorTx.hash, anchorOutputIndex, Crypto.sha256(ourRevocationHashPreimage), state.reverse)
|
||||
val ourSigForThem = bin2signature(Transaction.signInput(theirCommitTx, 0, multiSig2of2(ourParams.commitKey, theirParams.commitKey), SIGHASH_ALL, commitPrivKey))
|
||||
bob ! open_anchor(anchorTx.hash, 0, anchorInput.amount, ourSigForThem)
|
||||
node ! open_anchor(anchorTx.hash, 0, anchorInput.amount, ourSigForThem)
|
||||
expectMsgClass(classOf[open_commit_sig])
|
||||
expectMsgClass(classOf[Watch])
|
||||
bob ! BITCOIN_ANCHOR_DEPTHOK
|
||||
node ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[open_complete])
|
||||
bob ! open_complete(None)
|
||||
bob ! CMD_GETSTATE
|
||||
node ! open_complete(None)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_LOWPRIO)
|
||||
}
|
||||
|
||||
"successfuly open a channel in ANCHOR_WITHINPUT mode" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, Some(anchorInput))))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WONT_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
val their_open_anchor = expectMsgClass(classOf[open_anchor])
|
||||
// we fund the channel with the anchor tx, so the money is ours
|
||||
val state = ChannelState(them = ChannelOneSide(their_open_anchor.amount - our_commitment_fee, 0, Seq()), us = ChannelOneSide(0, 0, Seq()))
|
||||
// we build our commitment tx, leaving it unsigned
|
||||
val ourCommitTx = makeCommitTx(ourParams.finalKey, theirParams.finalKey, theirParams.delay, their_open_anchor.txid, their_open_anchor.outputIndex, Crypto.sha256(ourRevocationHashPreimage), state)
|
||||
// then we build their commitment tx and sign it
|
||||
val theirCommitTx = makeCommitTx(theirParams.finalKey, ourParams.finalKey, ourParams.delay, their_open_anchor.txid, their_open_anchor.outputIndex, theirRevocationHash, state.reverse)
|
||||
val ourSigForThem = bin2signature(Transaction.signInput(theirCommitTx, 0, multiSig2of2(ourParams.commitKey, theirParams.commitKey), SIGHASH_ALL, commitPrivKey))
|
||||
node ! open_commit_sig(ourSigForThem)
|
||||
expectMsgClass(classOf[Watch])
|
||||
expectMsgClass(classOf[Publish])
|
||||
node ! BITCOIN_ANCHOR_DEPTHOK
|
||||
expectMsgClass(classOf[open_complete])
|
||||
node ! open_complete(None)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(NORMAL_HIGHPRIO)
|
||||
}
|
||||
|
||||
"handle CMD_CLOSE in OPEN_WAIT_FOR_OPEN_NOANCHOR" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, None)))
|
||||
node ! INPUT_NONE
|
||||
expectMsgClass(classOf[open_channel])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_OPEN_NOANCHOR)
|
||||
node ! CMD_CLOSE(0)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(CLOSED)
|
||||
}
|
||||
|
||||
"handle CMD_CLOSE in OPEN_WAIT_FOR_OPEN_WITHANCHOR" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, Some(anchorInput))))
|
||||
node ! INPUT_NONE
|
||||
expectMsgClass(classOf[open_channel])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_OPEN_WITHANCHOR)
|
||||
node ! CMD_CLOSE(0)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(CLOSED)
|
||||
}
|
||||
|
||||
"handle CMD_CLOSE in OPEN_WAIT_FOR_ANCHOR" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, None)))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WILL_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_ANCHOR)
|
||||
node ! CMD_CLOSE(0)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(CLOSED)
|
||||
}
|
||||
|
||||
"handle CMD_CLOSE in OPEN_WAIT_FOR_COMMIT_SIG" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, Some(anchorInput))))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WONT_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
val their_open_anchor = expectMsgClass(classOf[open_anchor])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAIT_FOR_COMMIT_SIG)
|
||||
node ! CMD_CLOSE(0)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(CLOSED)
|
||||
}
|
||||
|
||||
/*"handle CMD_CLOSE in OPEN_WAITING_THEIRANCHOR" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, None)))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WILL_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
val anchorTx = makeAnchorTx(ourParams.commitKey, theirParams.commitKey, anchorInput.amount, anchorInput.previousTxOutput, anchorInput.signData)
|
||||
val anchorOutputIndex = 0
|
||||
// we fund the channel with the anchor tx, so the money is ours
|
||||
val state = ChannelState(them = ChannelOneSide(0, 0, Seq()), us = ChannelOneSide(anchorInput.amount - our_commitment_fee, 0, Seq()))
|
||||
// we build our commitment tx, leaving it unsigned
|
||||
val ourCommitTx = makeCommitTx(ourParams.finalKey, theirParams.finalKey, theirParams.delay, anchorTx.hash, anchorOutputIndex, Crypto.sha256(ourRevocationHashPreimage), state)
|
||||
// then we build their commitment tx and sign it
|
||||
val theirCommitTx = makeCommitTx(theirParams.finalKey, ourParams.finalKey, ourParams.delay, anchorTx.hash, anchorOutputIndex, theirRevocationHash, state.reverse)
|
||||
val ourSigForThem = bin2signature(Transaction.signInput(theirCommitTx, 0, multiSig2of2(ourParams.commitKey, theirParams.commitKey), SIGHASH_ALL, commitPrivKey))
|
||||
node ! open_anchor(anchorTx.hash, 0, anchorInput.amount, ourSigForThem)
|
||||
expectMsgClass(classOf[open_commit_sig])
|
||||
expectMsgClass(classOf[Watch])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAITING_THEIRANCHOR)
|
||||
node ! CMD_CLOSE(0)
|
||||
expectMsgClass(classOf[close_channel])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(WAIT_FOR_CLOSE_COMPLETE)
|
||||
// the only difference between their final tx and ours is the order of the outputs, because state is symmetric
|
||||
val theirFinalTx = makeFinalTx(ourCommitTx.txIn, theirParams.finalKey, ourParams.finalKey, state.reverse)
|
||||
val ourFinalSigForThem = bin2signature(Transaction.signInput(theirFinalTx, 0, multiSig2of2(ourParams.commitKey, theirParams.commitKey), SIGHASH_ALL, commitPrivKey))
|
||||
node ! close_channel_complete(ourFinalSigForThem)
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(CLOSED)
|
||||
}*/
|
||||
|
||||
/*"handle CMD_CLOSE in OPEN_WAITING_OURANCHOR" in {
|
||||
val node = system.actorOf(Props(new Node(self, bob_commit_priv, bob_final_priv, 2, Some(anchorInput))))
|
||||
node ! INPUT_NONE
|
||||
val their_open_channel = expectMsgClass(classOf[open_channel])
|
||||
val theirParams = ChannelParams(their_open_channel.delay, their_open_channel.commitKey, their_open_channel.finalKey, their_open_channel.minDepth.get, their_open_channel.commitmentFee)
|
||||
val theirRevocationHash = their_open_channel.revocationHash
|
||||
val ourRevocationHashPreimage = sha256_hash(4, 3, 2, 1)
|
||||
val ourRevocationHash = Crypto.sha256(ourRevocationHashPreimage)
|
||||
node ! open_channel(ourParams.delay, ourRevocationHash, ourParams.commitKey, ourParams.finalKey, WONT_CREATE_ANCHOR, Some(ourParams.minDepth), ourParams.commitmentFee)
|
||||
val their_open_anchor = expectMsgClass(classOf[open_anchor])
|
||||
// we fund the channel with the anchor tx, so the money is ours
|
||||
val state = ChannelState(them = ChannelOneSide(their_open_anchor.amount - our_commitment_fee, 0, Seq()), us = ChannelOneSide(0, 0, Seq()))
|
||||
// we build our commitment tx, leaving it unsigned
|
||||
val ourCommitTx = makeCommitTx(ourParams.finalKey, theirParams.finalKey, theirParams.delay, their_open_anchor.txid, their_open_anchor.outputIndex, Crypto.sha256(ourRevocationHashPreimage), state)
|
||||
// then we build their commitment tx and sign it
|
||||
val theirCommitTx = makeCommitTx(theirParams.finalKey, ourParams.finalKey, ourParams.delay, their_open_anchor.txid, their_open_anchor.outputIndex, theirRevocationHash, state.reverse)
|
||||
val ourSigForThem = bin2signature(Transaction.signInput(theirCommitTx, 0, multiSig2of2(ourParams.commitKey, theirParams.commitKey), SIGHASH_ALL, commitPrivKey))
|
||||
node ! open_commit_sig(ourSigForThem)
|
||||
expectMsgClass(classOf[Watch])
|
||||
expectMsgClass(classOf[Publish])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(OPEN_WAITING_OURANCHOR)
|
||||
node ! CMD_CLOSE(0)
|
||||
expectMsgClass(classOf[close_channel])
|
||||
node ! CMD_GETSTATE
|
||||
expectMsg(WAIT_FOR_CLOSE_COMPLETE)
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue