Skip to content

Commit

Permalink
Extract shared test tags
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Feb 3, 2021
1 parent 0b4f50b commit 9fa6fa5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ trait StateTestsBase extends StateTestsHelperMethods with FixtureTestSuite with

}

object StateTestsTags {
/** If set, channels will use option_static_remotekey. */
val StaticRemoteKey = "static_remotekey"
/** If set, channels will use option_anchor_outputs. */
val AnchorOutputs = "anchor_outputs"
/** If set, channels will be public (otherwise we don't announce them by default). */
val ChannelsPublic = "channels_public"
/** If set, no amount will be pushed when opening a channel (by default we push a small amount). */
val NoPushMsat = "no_push_msat"
}

trait StateTestsHelperMethods extends TestKitBase {

case class SetupFixture(alice: TestFSMRef[State, Data, Channel],
Expand Down Expand Up @@ -87,12 +98,12 @@ trait StateTestsHelperMethods extends TestKitBase {

def reachNormal(setup: SetupFixture, tags: Set[String] = Set.empty): Unit = {
import setup._
val channelFlags = if (tags.contains("channels_public")) ChannelFlags.AnnounceChannel else ChannelFlags.Empty
val pushMsat = if (tags.contains("no_push_msat")) 0.msat else TestConstants.pushMsat
val (aliceParams, bobParams, channelVersion) = if (tags.contains("anchor_outputs")) {
val channelFlags = if (tags.contains(StateTestsTags.ChannelsPublic)) ChannelFlags.AnnounceChannel else ChannelFlags.Empty
val pushMsat = if (tags.contains(StateTestsTags.NoPushMsat)) 0.msat else TestConstants.pushMsat
val (aliceParams, bobParams, channelVersion) = if (tags.contains(StateTestsTags.AnchorOutputs)) {
val features = Features(Set(ActivatedFeature(Features.StaticRemoteKey, FeatureSupport.Mandatory), ActivatedFeature(Features.AnchorOutputs, FeatureSupport.Optional)))
(Alice.channelParams.copy(features = features), Bob.channelParams.copy(features = features), ChannelVersion.ANCHOR_OUTPUTS)
} else if (tags.contains("static_remotekey")) {
} else if (tags.contains(StateTestsTags.StaticRemoteKey)) {
val features = Features(Set(ActivatedFeature(Features.StaticRemoteKey, FeatureSupport.Optional)))
val aliceParams = Alice.channelParams.copy(features = features, walletStaticPaymentBasepoint = Some(Helpers.getWalletPaymentBasepoint(wallet)))
val bobParams = Bob.channelParams.copy(features = features, walletStaticPaymentBasepoint = Some(Helpers.getWalletPaymentBasepoint(wallet)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import fr.acinq.eclair.blockchain._
import fr.acinq.eclair.blockchain.fee.{FeeratePerKw, FeeratesPerKw}
import fr.acinq.eclair.channel.Channel._
import fr.acinq.eclair.channel._
import fr.acinq.eclair.channel.states.StateTestsBase
import fr.acinq.eclair.channel.states.{StateTestsBase, StateTestsTags}
import fr.acinq.eclair.crypto.Sphinx
import fr.acinq.eclair.io.Peer
import fr.acinq.eclair.payment.OutgoingPacket
Expand Down Expand Up @@ -198,7 +198,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
bob2alice.expectNoMsg(200 millis)
}

test("recv CMD_ADD_HTLC (increasing balance but still below reserve)", Tag("no_push_msat")) { f =>
test("recv CMD_ADD_HTLC (increasing balance but still below reserve)", Tag(StateTestsTags.NoPushMsat)) { f =>
import f._
val sender = TestProbe()
// channel starts with all funds on alice's side, alice sends some funds to bob, but not enough to make it go above reserve
Expand All @@ -219,7 +219,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
alice2bob.expectNoMsg(200 millis)
}

test("recv CMD_ADD_HTLC (insufficient funds) (anchor outputs)", Tag("anchor_outputs")) { f =>
test("recv CMD_ADD_HTLC (insufficient funds) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) { f =>
import f._
val sender = TestProbe()
val initialState = alice.stateData.asInstanceOf[DATA_NORMAL]
Expand Down Expand Up @@ -488,7 +488,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
bob2blockchain.expectMsgType[WatchConfirmed]
}

test("recv UpdateAddHtlc (insufficient funds w/ pending htlcs) (anchor outputs)", Tag("anchor_outputs")) { f =>
test("recv UpdateAddHtlc (insufficient funds w/ pending htlcs) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) { f =>
import f._
val tx = bob.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
alice2bob.forward(bob, UpdateAddHtlc(ByteVector32.Zeroes, 0, 400000000 msat, randomBytes32, CltvExpiryDelta(144).toCltvExpiry(currentBlockHeight), TestConstants.emptyOnionPacket))
Expand Down Expand Up @@ -722,7 +722,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(alice.stateData.asInstanceOf[DATA_NORMAL].commitments.remoteNextCommitInfo === Left(waitForRevocation.copy(reSignAsap = true)))
}

test("recv CMD_SIGN (going above reserve)", Tag("no_push_msat")) { f =>
test("recv CMD_SIGN (going above reserve)", Tag(StateTestsTags.NoPushMsat)) { f =>
import f._
val sender = TestProbe()
// channel starts with all funds on alice's side, so channel will be initially disabled on bob's side
Expand Down Expand Up @@ -1149,11 +1149,11 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(initialToRemoteScript == aliceToRemoteScript())
}

test("recv RevokeAndAck (one htlc sent, static_remotekey)", Tag("static_remotekey")) {
test("recv RevokeAndAck (one htlc sent, static_remotekey)", Tag(StateTestsTags.StaticRemoteKey)) {
testRevokeAndAckHtlcStaticRemoteKey _
}

test("recv RevokeAndAck (one htlc sent, anchor outputs)", Tag("anchor_outputs")) {
test("recv RevokeAndAck (one htlc sent, anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testRevokeAndAckHtlcStaticRemoteKey _
}

Expand Down Expand Up @@ -1191,11 +1191,11 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testReceiveCmdFulfillHtlc _
}

test("recv CMD_FULFILL_HTLC (static_remotekey)", Tag("static_remotekey")) {
test("recv CMD_FULFILL_HTLC (static_remotekey)", Tag(StateTestsTags.StaticRemoteKey)) {
testReceiveCmdFulfillHtlc _
}

test("recv CMD_FULFILL_HTLC (anchor_outputs)", Tag("anchor_outputs")) {
test("recv CMD_FULFILL_HTLC (anchor_outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testReceiveCmdFulfillHtlc _
}

Expand Down Expand Up @@ -1280,7 +1280,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testUpdateFulfillHtlc _
}

test("recv UpdateFulfillHtlc (anchor_outputs)", Tag("anchor_outputs")) {
test("recv UpdateFulfillHtlc (anchor_outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testUpdateFulfillHtlc _
}

Expand Down Expand Up @@ -1356,11 +1356,11 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testCmdFailHtlc _
}

test("recv CMD_FAIL_HTLC (static_remotekey)", Tag("static_remotekey")) {
test("recv CMD_FAIL_HTLC (static_remotekey)", Tag(StateTestsTags.StaticRemoteKey)) {
testCmdFailHtlc _
}

test("recv CMD_FAIL_HTLC (anchor_outputs)", Tag("anchor_outputs")) {
test("recv CMD_FAIL_HTLC (anchor_outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testCmdFailHtlc _
}

Expand Down Expand Up @@ -1452,11 +1452,11 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testUpdateFailHtlc _
}

test("recv UpdateFailHtlc (static_remotekey)", Tag("static_remotekey")) {
test("recv UpdateFailHtlc (static_remotekey)", Tag(StateTestsTags.StaticRemoteKey)) {
testUpdateFailHtlc _
}

test("recv UpdateFailHtlc (anchor_outputs)", Tag("anchor_outputs")) {
test("recv UpdateFailHtlc (anchor_outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testUpdateFailHtlc _
}

Expand Down Expand Up @@ -1563,7 +1563,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testCmdUpdateFee _
}

test("recv CMD_UPDATE_FEE (anchor outputs)", Tag("anchor_outputs")) {
test("recv CMD_UPDATE_FEE (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testCmdUpdateFee _
}

Expand Down Expand Up @@ -1597,7 +1597,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
awaitCond(bob.stateData == initialData.copy(commitments = initialData.commitments.copy(remoteChanges = initialData.commitments.remoteChanges.copy(proposed = initialData.commitments.remoteChanges.proposed :+ fee), remoteNextHtlcId = 0)))
}

test("recv UpdateFee (anchor outputs)", Tag("anchor_outputs")) { f =>
test("recv UpdateFee (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) { f =>
import f._
val initialData = bob.stateData.asInstanceOf[DATA_NORMAL]
val fee = UpdateFee(ByteVector32.Zeroes, FeeratePerKw(8000 sat))
Expand Down Expand Up @@ -1645,7 +1645,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
bob2blockchain.expectMsgType[WatchConfirmed]
}

test("recv UpdateFee (sender can't afford it) (anchor outputs)", Tag("anchor_outputs")) { f =>
test("recv UpdateFee (sender can't afford it) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) { f =>
import f._
val tx = bob.stateData.asInstanceOf[DATA_NORMAL].commitments.localCommit.publishableTxs.commitTx.tx
// This feerate is just above the threshold: (800000 (alice balance) - 20000 (reserve) - 660 (anchors)) / 1124 (commit tx weight) = 693363
Expand Down Expand Up @@ -1732,7 +1732,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testCmdClose _
}

test("recv CMD_CLOSE (no pending htlcs) (anchor outputs)", Tag("anchor_outputs")) {
test("recv CMD_CLOSE (no pending htlcs) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testCmdClose _
}

Expand Down Expand Up @@ -1826,7 +1826,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testShutdown _
}

test("recv Shutdown (no pending htlcs) (anchor outputs)", Tag("anchor_outputs")) {
test("recv Shutdown (no pending htlcs) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testShutdown _
}

Expand Down Expand Up @@ -1904,7 +1904,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
testShutdownWithHtlcs _
}

test("recv Shutdown (with signed htlcs) (anchor outputs)", Tag("anchor_outputs")) {
test("recv Shutdown (with signed htlcs) (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testShutdownWithHtlcs _
}

Expand Down Expand Up @@ -2450,7 +2450,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(localCommitPublished.claimHtlcDelayedTxs.size == 3)
}

test("recv Error (nothing at stake)", Tag("no_push_msat")) { f =>
test("recv Error (nothing at stake)", Tag(StateTestsTags.NoPushMsat)) { f =>
import f._

// when receiving an error bob should publish its commitment even if it has nothing at stake, because alice could
Expand All @@ -2469,7 +2469,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(localCommitPublished.commitTx == bobCommitTx)
}

test("recv BITCOIN_FUNDING_DEEPLYBURIED", Tag("channels_public")) { f =>
test("recv BITCOIN_FUNDING_DEEPLYBURIED", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
val annSigs = alice2bob.expectMsgType[AnnouncementSignatures]
Expand All @@ -2480,7 +2480,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
channelUpdateListener.expectNoMsg(1 second)
}

test("recv BITCOIN_FUNDING_DEEPLYBURIED (short channel id changed)", Tag("channels_public")) { f =>
test("recv BITCOIN_FUNDING_DEEPLYBURIED (short channel id changed)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400001, 22, null)
val annSigs = alice2bob.expectMsgType[AnnouncementSignatures]
Expand Down Expand Up @@ -2512,7 +2512,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
channelUpdateListener.expectNoMsg(1 second)
}

test("recv AnnouncementSignatures", Tag("channels_public")) { f =>
test("recv AnnouncementSignatures", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
val initialState = alice.stateData.asInstanceOf[DATA_NORMAL]
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand All @@ -2530,7 +2530,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(channelUpdateListener.expectMsgType[LocalChannelUpdate].channelAnnouncement_opt === Some(channelAnn))
}

test("recv AnnouncementSignatures (re-send)", Tag("channels_public")) { f =>
test("recv AnnouncementSignatures (re-send)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
val initialState = alice.stateData.asInstanceOf[DATA_NORMAL]
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 42, 10, null)
Expand All @@ -2549,7 +2549,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
alice2bob.expectMsg(annSigsA)
}

test("recv AnnouncementSignatures (invalid)", Tag("channels_public")) { f =>
test("recv AnnouncementSignatures (invalid)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
val channelId = alice.stateData.asInstanceOf[DATA_NORMAL].channelId
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand All @@ -2565,7 +2565,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
awaitCond(alice.stateName == CLOSING)
}

test("recv BroadcastChannelUpdate", Tag("channels_public")) { f =>
test("recv BroadcastChannelUpdate", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
bob ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand All @@ -2580,7 +2580,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
assert(update1.channelUpdate.timestamp < update2.channelUpdate.timestamp)
}

test("recv BroadcastChannelUpdate (no changes)", Tag("channels_public")) { f =>
test("recv BroadcastChannelUpdate (no changes)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
bob ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand Down Expand Up @@ -2629,7 +2629,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
awaitCond(alice.stateName == OFFLINE)
}

test("recv INPUT_DISCONNECTED (public channel)", Tag("channels_public")) { f =>
test("recv INPUT_DISCONNECTED (public channel)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
bob ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand All @@ -2644,7 +2644,7 @@ class NormalStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
channelUpdateListener.expectNoMsg(1 second)
}

test("recv INPUT_DISCONNECTED (public channel, with pending unsigned htlcs)", Tag("channels_public")) { f =>
test("recv INPUT_DISCONNECTED (public channel, with pending unsigned htlcs)", Tag(StateTestsTags.ChannelsPublic)) { f =>
import f._
val sender = TestProbe()
alice ! WatchEventConfirmed(BITCOIN_FUNDING_DEEPLYBURIED, 400000, 42, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import fr.acinq.eclair.blockchain._
import fr.acinq.eclair.blockchain.fee.{FeeratePerKw, FeeratesPerKw}
import fr.acinq.eclair.channel.Helpers.Closing
import fr.acinq.eclair.channel._
import fr.acinq.eclair.channel.states.StateTestsBase
import fr.acinq.eclair.channel.states.{StateTestsBase, StateTestsTags}
import fr.acinq.eclair.wire.{ClosingSigned, Error, Shutdown}
import fr.acinq.eclair.{CltvExpiry, MilliSatoshiLong, TestConstants, TestKitBaseClass}
import org.scalatest.funsuite.FixtureAnyFunSuiteLike
Expand Down Expand Up @@ -111,7 +111,7 @@ class NegotiatingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike
testClosingSigned _
}

test("recv ClosingSigned (anchor outputs)", Tag("anchor_outputs")) {
test("recv ClosingSigned (anchor outputs)", Tag(StateTestsTags.AnchorOutputs)) {
testClosingSigned _
}

Expand All @@ -136,7 +136,7 @@ class NegotiatingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike
testFeeConverge(f)
}

test("recv ClosingSigned (nothing at stake)", Tag("no_push_msat")) { f =>
test("recv ClosingSigned (nothing at stake)", Tag(StateTestsTags.NoPushMsat)) { f =>
import f._
val aliceCloseFee = alice2bob.expectMsgType[ClosingSigned].feeSatoshis
alice2bob.forward(bob)
Expand Down
Loading

0 comments on commit 9fa6fa5

Please sign in to comment.