lnd.xprv/sweep/txgenerator_test.go
Johan T. Halseth 8c0deb81c2
input+lnwallet: Add scripts for CSV delayed HTLC outputs
We also increase the witness size for these types to account for the 3
extra bytes. The size won't be correct in all cases, but it is just an
upper bound in any case.
2020-03-09 12:10:58 +01:00

48 lines
1.2 KiB
Go

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(1462)
expectedSummary = "1 CommitmentTimeLock, 1 " +
"HtlcAcceptedSuccessSecondLevel, 1 HtlcOfferedRemoteTimeout, " +
"1 WitnessKeyHash"
)
// 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 := getWeightEstimate(inputs)
if weight != expectedWeight {
t.Fatalf("unexpected weight. expected %d but got %d.",
expectedWeight, weight)
}
summary := inputTypeSummary(inputs)
if summary != expectedSummary {
t.Fatalf("unexpected summary. expected %s but got %s.",
expectedSummary, summary)
}
}