lnwallet/chanfunding: non-segwit spend Verify test

Also fixes error-handling in the Verify test when expectedErr == ""
This commit is contained in:
eugene 2021-04-22 12:19:12 -04:00
parent b3f14d66f0
commit fa5627b779
No known key found for this signature in database
GPG Key ID: 118759E83439A9B1

@ -340,8 +340,8 @@ func TestPsbtVerify(t *testing.T) {
}, },
}, },
{ {
name: "input correct", name: "missing witness-utxo field",
expectedErr: "", expectedErr: "not all inputs are segwit spends",
doVerify: func(amt int64, p *psbt.Packet, doVerify: func(amt int64, p *psbt.Packet,
i *PsbtIntent) error { i *PsbtIntent) error {
@ -370,6 +370,33 @@ func TestPsbtVerify(t *testing.T) {
return i.Verify(p) return i.Verify(p)
}, },
}, },
{
name: "input correct",
expectedErr: "",
doVerify: func(amt int64, p *psbt.Packet,
i *PsbtIntent) error {
txOut := &wire.TxOut{
Value: int64(chanCapacity/2) + 1,
}
p.UnsignedTx.TxIn = []*wire.TxIn{
{},
{
PreviousOutPoint: wire.OutPoint{
Index: 0,
},
},
}
p.Inputs = []psbt.PInput{
{
WitnessUtxo: txOut,
},
{
WitnessUtxo: txOut,
}}
return i.Verify(p)
},
},
} }
// Create a simple assembler and ask it to provision a channel to get // Create a simple assembler and ask it to provision a channel to get
@ -401,9 +428,11 @@ func TestPsbtVerify(t *testing.T) {
} }
err = tc.doVerify(amt, pendingPsbt, psbtIntent) err = tc.doVerify(amt, pendingPsbt, psbtIntent)
if err != nil && tc.expectedErr != "" && if err != nil && tc.expectedErr == "" {
err.Error() != tc.expectedErr { t.Fatalf("unexpected error, got '%v' wanted "+
"'%v'", err, tc.expectedErr)
}
if err != nil && err.Error() != tc.expectedErr {
t.Fatalf("unexpected error, got '%v' wanted "+ t.Fatalf("unexpected error, got '%v' wanted "+
"'%v'", err, tc.expectedErr) "'%v'", err, tc.expectedErr)
} }