sweep: add test to make sure fee estimation is correct

This commit is contained in:
Oliver Gugger 2019-10-09 17:14:22 +02:00
parent e64493fe5b
commit 4190146066
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

49
sweep/txgenerator_test.go Normal file

@ -0,0 +1,49 @@
package sweep
import (
"testing"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/input"
)
var (
witnessTypes = []input.WitnessType{
input.CommitmentTimeLock,
input.HtlcAcceptedSuccessSecondLevel,
input.HtlcOfferedRemoteTimeout,
input.WitnessKeyHash,
}
expectedWeight = int64(1459)
expectedCsv = 2
expectedCltv = 1
)
// TestWeightEstimate tests that the estimated weight and number of CSVs/CLTVs
// used is correct for a transaction that uses inputs with the witness types
// defined in witnessTypes.
func TestWeightEstimate(t *testing.T) {
t.Parallel()
var inputs []input.Input
for _, witnessType := range witnessTypes {
inputs = append(inputs, input.NewBaseInput(
&wire.OutPoint{}, witnessType,
&input.SignDescriptor{}, 0,
))
}
_, weight, csv, cltv := getWeightEstimate(inputs)
if weight != expectedWeight {
t.Fatalf("unexpected weight. expected %d but got %d.",
expectedWeight, weight)
}
if csv != expectedCsv {
t.Fatalf("unexpected csv count. expected %d but got %d.",
expectedCsv, csv)
}
if cltv != expectedCltv {
t.Fatalf("unexpected cltv count. expected %d but got %d.",
expectedCltv, cltv)
}
}