lnwallet tests: update tests to new FeeEstimator and fee rate types

This commit is contained in:
Johan T. Halseth committed 2018-02-26 22:42:25 +01:00
1 parent 1f839d2526
commit d7834ca4eb
3 files changed
+69 -65

No files matched your search

+40 -40
View File
@@ -231,11 +231,11 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
}
estimator := &StaticFeeEstimator{24}
feePerWeight, err := estimator.EstimateFeePerWeight(1)
feePerVSize, err := estimator.EstimateFeePerVSize(1)
if err != nil {
return nil, nil, nil, err
}
feePerKw := feePerWeight * 1000
feePerKw := feePerVSize.FeePerKWeight()
commitFee := calcStaticFee(0)
aliceCommit := channeldb.ChannelCommitment{
@@ -243,7 +243,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal),
CommitFee: commitFee,
FeePerKw: feePerKw,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
}
@@ -252,7 +252,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
LocalBalance: lnwire.NewMSatFromSatoshis(channelBal),
RemoteBalance: lnwire.NewMSatFromSatoshis(channelBal - commitFee),
CommitFee: commitFee,
FeePerKw: feePerKw,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: bobCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
}
@@ -747,12 +747,12 @@ func TestCooperativeChannelClosure(t *testing.T) {
aliceDeliveryScript := bobsPrivKey[:]
bobDeliveryScript := testHdSeed[:]
aliceFeeRate := uint64(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := uint64(bobChannel.channelState.LocalCommitment.FeePerKw)
aliceFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw)
// We'll store with both Alice and Bob creating a new close proposal
// with the same fee.
aliceFee := btcutil.Amount(aliceChannel.CalcFee(aliceFeeRate))
aliceFee := aliceChannel.CalcFee(aliceFeeRate)
aliceSig, _, _, err := aliceChannel.CreateCloseProposal(
aliceFee, aliceDeliveryScript, bobDeliveryScript,
)
@@ -761,7 +761,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
}
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate))
bobFee := bobChannel.CalcFee(bobFeeRate)
bobSig, _, _, err := bobChannel.CreateCloseProposal(
bobFee, bobDeliveryScript, aliceDeliveryScript,
)
@@ -889,8 +889,8 @@ func TestForceClose(t *testing.T) {
// Factoring in the fee rate, Alice's amount should properly reflect
// that we've added two additional HTLC to the commitment transaction.
totalCommitWeight := CommitWeight + (HtlcWeight * 2)
feePerKw := aliceChannel.channelState.LocalCommitment.FeePerKw
commitFee := btcutil.Amount((int64(feePerKw) * totalCommitWeight) / 1000)
feePerKw := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
commitFee := feePerKw.FeeForWeight(totalCommitWeight)
expectedAmount := (aliceChannel.Capacity / 2) - htlcAmount.ToSatoshis() - commitFee
if aliceCommitResolution.SelfOutputSignDesc.Output.Value != int64(expectedAmount) {
t.Fatalf("alice incorrect output value in SelfOutputSignDesc, "+
@@ -1297,8 +1297,8 @@ func TestHTLCDustLimit(t *testing.T) {
// The amount of the HTLC should be above Alice's dust limit and below
// Bob's dust limit.
htlcSat := (btcutil.Amount(500) +
htlcTimeoutFee(aliceChannel.channelState.LocalCommitment.FeePerKw))
htlcSat := (btcutil.Amount(500) + htlcTimeoutFee(
SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)))
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
htlc, preimage := createHTLC(0, htlcAmount)
@@ -1392,7 +1392,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
aliceBalance := aliceChannel.channelState.LocalCommitment.LocalBalance.ToSatoshis()
htlcSat := aliceBalance - defaultFee
htlcSat += htlcSuccessFee(
aliceChannel.channelState.LocalCommitment.FeePerKw,
SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw),
)
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
@@ -1853,8 +1853,8 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
}
defer cleanUp()
aliceFeeRate := uint64(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := uint64(bobChannel.channelState.LocalCommitment.FeePerKw)
aliceFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
bobFeeRate := SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw)
setDustLimit := func(dustVal btcutil.Amount) {
aliceChannel.channelState.LocalChanCfg.DustLimit = dustVal
@@ -2069,7 +2069,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
}
// Simulate Alice sending update fee message to bob.
fee := btcutil.Amount(111)
fee := SatPerKWeight(111)
aliceChannel.UpdateFee(fee)
bobChannel.ReceiveUpdateFee(fee)
@@ -2089,7 +2089,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("bob unable to process alice's new commitment: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in")
}
@@ -2100,7 +2100,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in")
}
@@ -2125,7 +2125,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in")
}
@@ -2136,7 +2136,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("alice's feePerKw was not locked in")
}
@@ -2181,7 +2181,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
}
// Simulate Alice sending update fee message to bob
fee := btcutil.Amount(111)
fee := SatPerKWeight(111)
aliceChannel.UpdateFee(fee)
bobChannel.ReceiveUpdateFee(fee)
@@ -2228,7 +2228,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in")
}
@@ -2240,7 +2240,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in")
}
@@ -2264,7 +2264,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in")
}
@@ -2275,7 +2275,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("Alice's feePerKw was not locked in")
}
@@ -2302,7 +2302,7 @@ func TestUpdateFeeReceiverSendsUpdate(t *testing.T) {
// Since Alice is the channel initiator, she should fail when receiving
// fee update
fee := btcutil.Amount(111)
fee := SatPerKWeight(111)
err = aliceChannel.ReceiveUpdateFee(fee)
if err == nil {
t.Fatalf("expected alice to fail receiving fee update")
@@ -2330,9 +2330,9 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
defer cleanUp()
// Simulate Alice sending update fee message to bob.
fee1 := btcutil.Amount(111)
fee2 := btcutil.Amount(222)
fee := btcutil.Amount(333)
fee1 := SatPerKWeight(111)
fee2 := SatPerKWeight(222)
fee := SatPerKWeight(333)
aliceChannel.UpdateFee(fee1)
aliceChannel.UpdateFee(fee2)
aliceChannel.UpdateFee(fee)
@@ -2357,15 +2357,15 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("bob unable to process alice's new commitment: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("bob's feePerKw was unexpectedly locked in")
}
// Alice sending more fee updates now should not mess up the old fee
// they both committed to.
fee3 := btcutil.Amount(444)
fee4 := btcutil.Amount(555)
fee5 := btcutil.Amount(666)
fee3 := SatPerKWeight(444)
fee4 := SatPerKWeight(555)
fee5 := SatPerKWeight(666)
aliceChannel.UpdateFee(fee3)
aliceChannel.UpdateFee(fee4)
aliceChannel.UpdateFee(fee5)
@@ -2380,7 +2380,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("unable to generate bob revocation: %v", err)
}
if bobChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("bob's feePerKw was not locked in")
}
@@ -2404,7 +2404,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("alice unable to process bob's new commitment: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw == fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) == fee {
t.Fatalf("alice's feePerKw was unexpectedly locked in")
}
@@ -2415,7 +2415,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
t.Fatalf("unable to revoke alice channel: %v", err)
}
if aliceChannel.channelState.LocalCommitment.FeePerKw != fee {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != fee {
t.Fatalf("alice's feePerKw was not locked in")
}
@@ -3498,7 +3498,7 @@ func TestFeeUpdateRejectInsaneFee(t *testing.T) {
// Next, we'll try to add a fee rate to Alice which is 1,000,000x her
// starting fee rate.
startingFeeRate := aliceChannel.channelState.LocalCommitment.FeePerKw
startingFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
newFeeRate := startingFeeRate * 1000000
// Both Alice and Bob should reject this new fee rate as it it far too
@@ -3524,7 +3524,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
// First, we'll fetch the current fee rate present within the
// commitment transactions.
startingFeeRate := aliceChannel.channelState.LocalCommitment.FeePerKw
startingFeeRate := SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw)
// Next, we'll start a commitment update, with Alice sending a new
// update to double the fee rate of the commitment.
@@ -3664,10 +3664,10 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
}
// Both parties should now have the latest fee rate locked-in.
if aliceChannel.channelState.LocalCommitment.FeePerKw != newFeeRate {
if SatPerKWeight(aliceChannel.channelState.LocalCommitment.FeePerKw) != newFeeRate {
t.Fatalf("alice's feePerKw was not locked in")
}
if bobChannel.channelState.LocalCommitment.FeePerKw != newFeeRate {
if SatPerKWeight(bobChannel.channelState.LocalCommitment.FeePerKw) != newFeeRate {
t.Fatalf("bob's feePerKw was not locked in")
}