From fa5627b779c2b80529fb844f5a54c13481d32ce0 Mon Sep 17 00:00:00 2001 From: eugene Date: Thu, 22 Apr 2021 12:19:12 -0400 Subject: [PATCH] lnwallet/chanfunding: non-segwit spend Verify test Also fixes error-handling in the Verify test when expectedErr == "" --- lnwallet/chanfunding/psbt_assembler_test.go | 39 ++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lnwallet/chanfunding/psbt_assembler_test.go b/lnwallet/chanfunding/psbt_assembler_test.go index cc40887a..775f87cc 100644 --- a/lnwallet/chanfunding/psbt_assembler_test.go +++ b/lnwallet/chanfunding/psbt_assembler_test.go @@ -340,8 +340,8 @@ func TestPsbtVerify(t *testing.T) { }, }, { - name: "input correct", - expectedErr: "", + name: "missing witness-utxo field", + expectedErr: "not all inputs are segwit spends", doVerify: func(amt int64, p *psbt.Packet, i *PsbtIntent) error { @@ -370,6 +370,33 @@ func TestPsbtVerify(t *testing.T) { 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 @@ -401,9 +428,11 @@ func TestPsbtVerify(t *testing.T) { } err = tc.doVerify(amt, pendingPsbt, psbtIntent) - if err != nil && tc.expectedErr != "" && - err.Error() != tc.expectedErr { - + if err != nil && 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 "+ "'%v'", err, tc.expectedErr) }