2019-10-09 18:14:22 +03:00
|
|
|
package sweep
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-19 18:51:32 +03:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2019-10-09 18:14:22 +03:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
|
|
"github.com/lightningnetwork/lnd/input"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
witnessTypes = []input.WitnessType{
|
|
|
|
input.CommitmentTimeLock,
|
|
|
|
input.HtlcAcceptedSuccessSecondLevel,
|
|
|
|
input.HtlcOfferedRemoteTimeout,
|
|
|
|
input.WitnessKeyHash,
|
|
|
|
}
|
2020-03-06 18:11:45 +03:00
|
|
|
expectedWeight = int64(1462)
|
2020-03-19 18:51:32 +03:00
|
|
|
expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " +
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " +
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " +
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000003:13 (WitnessKeyHash)"
|
2019-10-09 18:14:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2020-03-19 18:51:32 +03:00
|
|
|
for i, witnessType := range witnessTypes {
|
2019-10-09 18:14:22 +03:00
|
|
|
inputs = append(inputs, input.NewBaseInput(
|
2020-03-19 18:51:32 +03:00
|
|
|
&wire.OutPoint{
|
|
|
|
Hash: chainhash.Hash{byte(i)},
|
|
|
|
Index: uint32(i) + 10,
|
|
|
|
}, witnessType,
|
2019-10-09 18:14:22 +03:00
|
|
|
&input.SignDescriptor{}, 0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2019-10-23 14:00:25 +03:00
|
|
|
_, weight := getWeightEstimate(inputs)
|
2019-10-09 18:14:22 +03:00
|
|
|
if weight != expectedWeight {
|
|
|
|
t.Fatalf("unexpected weight. expected %d but got %d.",
|
|
|
|
expectedWeight, weight)
|
|
|
|
}
|
2019-10-23 14:00:25 +03:00
|
|
|
summary := inputTypeSummary(inputs)
|
|
|
|
if summary != expectedSummary {
|
|
|
|
t.Fatalf("unexpected summary. expected %s but got %s.",
|
|
|
|
expectedSummary, summary)
|
2019-10-09 18:14:22 +03:00
|
|
|
}
|
|
|
|
}
|