lnwallet/test: pass in test channel type

This commit is contained in:
Joost Jager 2020-03-10 09:33:38 +01:00
parent b03c3c2df3
commit 30fc03d84d
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
5 changed files with 208 additions and 88 deletions

@ -35,7 +35,9 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
const numChans = 10
var channels []*channeldb.OpenChannel
for i := 0; i < numChans; i++ {
lChannel, _, cleanup, err := lnwallet.CreateTestChannels(true)
lChannel, _, cleanup, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatal(err)
}
@ -149,7 +151,9 @@ func TestResolveContract(t *testing.T) {
// With the DB created, we'll make a new channel, and mark it as
// pending open within the database.
newChannel, _, cleanup, err := lnwallet.CreateTestChannels(true)
newChannel, _, cleanup, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to make new test channel: %v", err)
}

@ -63,7 +63,9 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
// First, we'll create two channels which already have established a
// commitment contract between themselves.
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -150,7 +152,9 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
// First, we'll create two channels which already have established a
// commitment contract between themselves.
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -274,7 +278,7 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
// First, we'll create two channels which already have
// established a commitment contract between themselves.
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
false,
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
@ -443,7 +447,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
// First, we'll create two channels which already have
// established a commitment contract between themselves.
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
false,
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)

@ -2005,7 +2005,7 @@ func TestRemoteCloseInitiator(t *testing.T) {
// First, create alice's channel.
alice, _, cleanUp, err := lnwallet.CreateTestChannels(
true,
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v",

@ -60,7 +60,12 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(tweakless)
chanType := channeldb.SingleFunderTweaklessBit
if !tweakless {
chanType = channeldb.SingleFunderBit
}
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(chanType)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -390,7 +395,9 @@ func TestCheckCommitTxSize(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -449,7 +456,9 @@ func TestCooperativeChannelClosure(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -522,7 +531,9 @@ func TestForceClose(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -808,7 +819,9 @@ func TestForceCloseDustOutput(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -926,7 +939,9 @@ func TestDustHTLCFees(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -970,7 +985,7 @@ func TestDustHTLCFees(t *testing.T) {
// The commitment fee paid should be the same, as there have been no
// new material outputs added.
defaultFee := calcStaticFee(0)
defaultFee := calcStaticFee(channeldb.SingleFunderTweaklessBit, 0)
if aliceChannel.channelState.LocalCommitment.CommitFee != defaultFee {
t.Fatalf("dust htlc amounts not subtracted from commitment fee "+
"expected %v, got %v", defaultFee,
@ -1003,7 +1018,9 @@ func TestHTLCDustLimit(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1046,7 +1063,7 @@ func TestHTLCDustLimit(t *testing.T) {
t.Fatalf("incorrect # of outputs: expected %v, got %v",
2, len(bobCommitment.txn.TxOut))
}
defaultFee := calcStaticFee(0)
defaultFee := calcStaticFee(channeldb.SingleFunderTweaklessBit, 0)
if bobChannel.channelState.LocalCommitment.CommitFee != defaultFee {
t.Fatalf("dust htlc amount was subtracted from commitment fee "+
"expected %v, got %v", defaultFee,
@ -1092,7 +1109,9 @@ func TestHTLCSigNumber(t *testing.T) {
// Create a test channel funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC. Alice's dustlimit is 200 sat, while
// Bob has 1300 sat.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1266,7 +1285,9 @@ func TestChannelBalanceDustLimit(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1280,7 +1301,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
// This amount should leave an amount larger than Alice's dust limit
// once fees have been subtracted, but smaller than Bob's dust limit.
// We account in fees for the HTLC we will be adding.
defaultFee := calcStaticFee(1)
defaultFee := calcStaticFee(channeldb.SingleFunderTweaklessBit, 1)
aliceBalance := aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis()
htlcSat := aliceBalance - defaultFee
htlcSat += HtlcSuccessFee(
@ -1337,7 +1358,9 @@ func TestStateUpdatePersistence(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1678,7 +1701,9 @@ func TestCancelHTLC(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1711,7 +1736,7 @@ func TestCancelHTLC(t *testing.T) {
// With the HTLC committed, Alice's balance should reflect the clearing
// of the new HTLC.
aliceExpectedBalance := btcutil.Amount(btcutil.SatoshiPerBitcoin*4) -
calcStaticFee(1)
calcStaticFee(channeldb.SingleFunderTweaklessBit, 1)
if aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis() !=
aliceExpectedBalance {
t.Fatalf("Alice's balance is wrong: expected %v, got %v",
@ -1756,12 +1781,13 @@ func TestCancelHTLC(t *testing.T) {
}
expectedBalance := btcutil.Amount(btcutil.SatoshiPerBitcoin * 5)
staticFee := calcStaticFee(channeldb.SingleFunderTweaklessBit, 0)
if aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis() !=
expectedBalance-calcStaticFee(0) {
expectedBalance-staticFee {
t.Fatalf("balance is wrong: expected %v, got %v",
aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis(),
expectedBalance-calcStaticFee(0))
expectedBalance-staticFee)
}
if aliceChannel.channelState.LocalCommitment.RemoteBalance.ToSatoshis() !=
expectedBalance {
@ -1778,11 +1804,11 @@ func TestCancelHTLC(t *testing.T) {
expectedBalance)
}
if bobChannel.channelState.LocalCommitment.RemoteBalance.ToSatoshis() !=
expectedBalance-calcStaticFee(0) {
expectedBalance-staticFee {
t.Fatalf("balance is wrong: expected %v, got %v",
bobChannel.channelState.LocalCommitment.RemoteBalance.ToSatoshis(),
expectedBalance-calcStaticFee(0))
expectedBalance-staticFee)
}
}
@ -1792,7 +1818,9 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -1957,7 +1985,9 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
func TestUpdateFeeAdjustments(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2012,7 +2042,9 @@ func TestUpdateFeeAdjustments(t *testing.T) {
func TestUpdateFeeFail(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2046,7 +2078,9 @@ func TestUpdateFeeFail(t *testing.T) {
func TestUpdateFeeConcurrentSig(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2132,7 +2166,9 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2254,7 +2290,9 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2403,7 +2441,9 @@ func TestUpdateFeeReceiverSendsUpdate(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2432,7 +2472,9 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2552,7 +2594,9 @@ func TestAddHTLCNegativeBalance(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, _, cleanUp, err := CreateTestChannels(true)
aliceChannel, _, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2633,7 +2677,9 @@ func TestChanSyncFullySynced(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -2753,7 +2799,9 @@ func TestChanSyncOweCommitment(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -3064,7 +3112,9 @@ func TestChanSyncOweCommitmentPendingRemote(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -3187,7 +3237,9 @@ func TestChanSyncOweRevocation(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -3377,7 +3429,9 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -3546,7 +3600,9 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -3775,7 +3831,9 @@ func TestChanSyncFailure(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(false)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4028,7 +4086,9 @@ func TestFeeUpdateRejectInsaneFee(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, _, cleanUp, err := CreateTestChannels(true)
aliceChannel, _, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4056,7 +4116,9 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4245,7 +4307,9 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4472,7 +4536,9 @@ func TestChanSyncUnableToSync(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(false)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4509,7 +4575,9 @@ func TestChanSyncInvalidLastSecret(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(false)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4599,7 +4667,9 @@ func TestChanAvailableBandwidth(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4735,7 +4805,9 @@ func TestChanAvailableBalanceNearHtlcFee(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4915,7 +4987,9 @@ func TestSignCommitmentFailNotLockedIn(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, _, cleanUp, err := CreateTestChannels(true)
aliceChannel, _, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -4940,7 +5014,9 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
t.Parallel()
// First, we'll make a channel between Alice and Bob.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5254,7 +5330,9 @@ func TestInvalidCommitSigError(t *testing.T) {
t.Parallel()
// First, we'll make a channel between Alice and Bob.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5301,7 +5379,9 @@ func TestChannelUnilateralCloseHtlcResolution(t *testing.T) {
// Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5460,7 +5540,7 @@ func TestChannelUnilateralClosePendingCommit(t *testing.T) {
// unittest. The channel will be funded evenly with Alice having 5 BTC,
// and Bob having 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
false,
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
@ -5587,7 +5667,9 @@ func TestDesyncHTLCs(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5654,7 +5736,9 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5786,7 +5870,9 @@ func TestMaxAsynchronousHtlcs(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -5921,7 +6007,9 @@ func TestMaxPendingAmount(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6005,7 +6093,7 @@ func TestChanReserve(t *testing.T) {
// We'll kick off the test by creating our channels which both
// are loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
true,
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
@ -6214,7 +6302,7 @@ func TestChanReserveRemoteInitiator(t *testing.T) {
// We start out with a channel where both parties have 5 BTC.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
true,
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatal(err)
@ -6267,7 +6355,7 @@ func TestChanReserveLocalInitiatorDustHtlc(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
true,
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatal(err)
@ -6313,7 +6401,9 @@ func TestMinHTLC(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6366,7 +6456,9 @@ func TestNewBreachRetributionSkipsDustHtlcs(t *testing.T) {
// We'll kick off the test by creating our channels which both are
// loaded with 5 BTC each.
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6538,7 +6630,9 @@ func compareLogs(a, b *updateLog) error {
func TestChannelRestoreUpdateLogs(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6707,7 +6801,9 @@ func restoreAndAssert(t *testing.T, channel *LightningChannel, numAddsLocal,
func TestChannelRestoreUpdateLogsFailedHTLC(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6830,7 +6926,9 @@ func TestChannelRestoreUpdateLogsFailedHTLC(t *testing.T) {
func TestDuplicateFailRejection(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6908,7 +7006,9 @@ func TestDuplicateFailRejection(t *testing.T) {
func TestDuplicateSettleRejection(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -6989,7 +7089,9 @@ func TestDuplicateSettleRejection(t *testing.T) {
func TestChannelRestoreCommitHeight(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(true)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -7176,7 +7278,9 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
func TestForceCloseFailLocalDataLoss(t *testing.T) {
t.Parallel()
aliceChannel, _, cleanUp, err := CreateTestChannels(false)
aliceChannel, _, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -7207,7 +7311,9 @@ func TestForceCloseFailLocalDataLoss(t *testing.T) {
func TestForceCloseBorkedState(t *testing.T) {
t.Parallel()
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(false)
aliceChannel, bobChannel, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
@ -7284,7 +7390,9 @@ func TestForceCloseBorkedState(t *testing.T) {
func TestChannelMaxFeeRate(t *testing.T) {
t.Parallel()
aliceChannel, _, cleanUp, err := CreateTestChannels(true)
aliceChannel, _, cleanUp, err := CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}

@ -91,7 +91,7 @@ var (
// the test has been finalized. The clean up function will remote all temporary
// files created. If tweaklessCommits is true, then the commits within the
// channels will use the new format, otherwise the legacy format.
func CreateTestChannels(tweaklessCommits bool) (
func CreateTestChannels(chanType channeldb.ChannelType) (
*LightningChannel, *LightningChannel, func(), error) {
channelCapacity, err := btcutil.NewAmount(10)
@ -206,11 +206,6 @@ func CreateTestChannels(tweaklessCommits bool) (
}
aliceCommitPoint := input.ComputeCommitmentPoint(aliceFirstRevoke[:])
chanType := channeldb.SingleFunderTweaklessBit
if !tweaklessCommits {
chanType = channeldb.SingleFunderBit
}
aliceCommitTx, bobCommitTx, err := CreateCommitmentTxns(
channelBal, channelBal, &aliceCfg, &bobCfg, aliceCommitPoint,
bobCommitPoint, *fundingTxIn, chanType,
@ -244,12 +239,21 @@ func CreateTestChannels(tweaklessCommits bool) (
if err != nil {
return nil, nil, nil, err
}
commitFee := calcStaticFee(0)
commitFee := calcStaticFee(chanType, 0)
var anchorAmt btcutil.Amount
if chanType.HasAnchors() {
anchorAmt += 2 * anchorSize
}
aliceBalance := lnwire.NewMSatFromSatoshis(
channelBal - commitFee - anchorAmt,
)
bobBalance := lnwire.NewMSatFromSatoshis(channelBal)
aliceCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
LocalBalance: aliceBalance,
RemoteBalance: bobBalance,
CommitFee: commitFee,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: aliceCommitTx,
@ -257,8 +261,8 @@ func CreateTestChannels(tweaklessCommits bool) (
}
bobCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
LocalBalance: bobBalance,
RemoteBalance: aliceBalance,
CommitFee: commitFee,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: bobCommitTx,
@ -449,14 +453,14 @@ func txFromHex(txHex string) (*btcutil.Tx, error) {
// calculations into account.
//
// TODO(bvu): Refactor when dynamic fee estimation is added.
func calcStaticFee(numHTLCs int) btcutil.Amount {
func calcStaticFee(chanType channeldb.ChannelType, numHTLCs int) btcutil.Amount {
const (
commitWeight = btcutil.Amount(724)
htlcWeight = 172
feePerKw = btcutil.Amount(24/4) * 1000
htlcWeight = 172
feePerKw = btcutil.Amount(24/4) * 1000
)
return feePerKw * (commitWeight +
btcutil.Amount(htlcWeight*numHTLCs)) / 1000
return feePerKw *
(btcutil.Amount(CommitWeight(chanType) +
htlcWeight*int64(numHTLCs))) / 1000
}
// ForceStateTransition executes the necessary interaction between the two