wallet/size test: add vsize test for non-segwit tx
This commit is contained in:
parent
d626036401
commit
8bcd56fc27
1 changed files with 34 additions and 14 deletions
|
@ -67,8 +67,9 @@ func TestEstimateVirtualSize(t *testing.T) {
|
|||
|
||||
type estimateVSizeTest struct {
|
||||
tx func() (*wire.MsgTx, error)
|
||||
p2wkhIns int
|
||||
nestedP2wkhIns int
|
||||
p2wpkhIns int
|
||||
nestedp2wpkhIns int
|
||||
p2pkhIns int
|
||||
change bool
|
||||
result int
|
||||
}
|
||||
|
@ -91,7 +92,7 @@ func TestEstimateVirtualSize(t *testing.T) {
|
|||
|
||||
return tx, nil
|
||||
},
|
||||
p2wkhIns: 1,
|
||||
p2wpkhIns: 1,
|
||||
result: 147,
|
||||
},
|
||||
{
|
||||
|
@ -110,7 +111,7 @@ func TestEstimateVirtualSize(t *testing.T) {
|
|||
|
||||
return tx, nil
|
||||
},
|
||||
nestedP2wkhIns: 1,
|
||||
nestedp2wpkhIns: 1,
|
||||
result: 170,
|
||||
},
|
||||
{
|
||||
|
@ -132,10 +133,29 @@ func TestEstimateVirtualSize(t *testing.T) {
|
|||
tx.TxOut = []*wire.TxOut{tx.TxOut[0]}
|
||||
return tx, nil
|
||||
},
|
||||
p2wkhIns: 1,
|
||||
p2wpkhIns: 1,
|
||||
change: true,
|
||||
result: 144,
|
||||
},
|
||||
{
|
||||
// Spending one P2PKH to two P2PKH outputs (no witness data).
|
||||
tx: func() (*wire.MsgTx, error) {
|
||||
txHex := "0100000001a4c91c9720157a5ee582a7966471d9c70d0a860fa7757b4c42a535a12054a4c9000000006c493046022100d49c452a00e5b1213ac84d92269510a05a584a4d0949bd7d0ad4e3408ac8e80a022100bf98707ffaf1eb9dff146f7da54e68651c0a27e3653ec3882b7a95202328579c01210332d98672a4246fe917b9c724c339e757d46b1ffde3fb27fdc680b4bb29b6ad59ffffffff02a0860100000000001976a9144fb55ee0524076acd4c14e7773561e4c298c8e2788ac20688a0b000000001976a914cb7f6bb8e95a2cd06423932cfbbce73d16a18df088ac00000000"
|
||||
b, err := hex.DecodeString(txHex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tx := &wire.MsgTx{}
|
||||
err = tx.Deserialize(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tx, nil
|
||||
},
|
||||
p2pkhIns: 1,
|
||||
result: 227,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@ -144,8 +164,8 @@ func TestEstimateVirtualSize(t *testing.T) {
|
|||
t.Fatalf("unable to get test tx: %v", err)
|
||||
}
|
||||
|
||||
est := EstimateVirtualSize(0, test.p2wkhIns,
|
||||
test.nestedP2wkhIns, tx.TxOut, test.change)
|
||||
est := EstimateVirtualSize(test.p2pkhIns, test.p2wpkhIns,
|
||||
test.nestedp2wpkhIns, tx.TxOut, test.change)
|
||||
|
||||
if est != test.result {
|
||||
t.Fatalf("expected estimated vsize to be %d, "+
|
||||
|
|
Loading…
Reference in a new issue