github.com/decred/dcrlnd@v0.7.6/sweep/txgenerator_test.go (about)

     1  package sweep
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/decred/dcrd/chaincfg/chainhash"
     7  	"github.com/decred/dcrd/wire"
     8  	"github.com/decred/dcrlnd/input"
     9  )
    10  
    11  var (
    12  	witnessTypes = []input.WitnessType{
    13  		input.CommitmentTimeLock,
    14  		input.HtlcAcceptedSuccessSecondLevel,
    15  		input.HtlcOfferedRemoteTimeout,
    16  		input.PublicKeyHash,
    17  	}
    18  	expectedSize    = int64(923)
    19  	expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " +
    20  		"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " +
    21  		"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " +
    22  		"0000000000000000000000000000000000000000000000000000000000000003:13 (PublicKeyHash)"
    23  )
    24  
    25  // TestWeightEstimate tests that the estimated weight and number of CSVs/CLTVs
    26  // used is correct for a transaction that uses inputs with the witness types
    27  // defined in witnessTypes.
    28  func TestWeightEstimate(t *testing.T) {
    29  	t.Parallel()
    30  
    31  	var inputs []input.Input
    32  	for i, witnessType := range witnessTypes {
    33  		inputs = append(inputs, input.NewBaseInput(
    34  			&wire.OutPoint{
    35  				Hash:  chainhash.Hash{byte(i)},
    36  				Index: uint32(i) + 10,
    37  			}, witnessType,
    38  			&input.SignDescriptor{}, 0,
    39  		))
    40  	}
    41  
    42  	_, estimator := getSizeEstimate(inputs, nil, 0)
    43  	size := int64(estimator.size())
    44  	if size != expectedSize {
    45  		t.Fatalf("unexpected size. expected %d but got %d.",
    46  			expectedSize, size)
    47  	}
    48  	summary := inputTypeSummary(inputs)
    49  	if summary != expectedSummary {
    50  		t.Fatalf("unexpected summary. expected %s but got %s.",
    51  			expectedSummary, summary)
    52  	}
    53  }