From 41065a45382ef731eee5f5669ba40e4e7539470a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 15 Dec 2015 15:25:22 -0600 Subject: [PATCH] check signatures in test itself, test-node infra not set up --- wallet/wallet_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index d6ef68541..c4cdac530 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -345,6 +345,35 @@ func TestBasicWalletReservationWorkFlow(t *testing.T) { // * all sigs valid for all inputs // The funding tx should now be valid and complete. + // Check each input and ensure all scripts are fully valid. + var zeroHash wire.ShaHash + fundingTx := chanReservation.fundingTx + for i, input := range chanReservation.fundingTx.TxIn { + var pkscript []byte + // Bob's txin + if bytes.Equal(input.PreviousOutPoint.Hash.Bytes(), + zeroHash.Bytes()) { + pkscript = bobNode.changeOutputs[0].PkScript + } else { + // Does the wallet know about the txin? + txDetail, _ := lnwallet.wallet.TxStore.TxDetails(&input.PreviousOutPoint.Hash) + if txDetail == nil { + panic(fmt.Errorf("not found!")) + } + prevIndex := input.PreviousOutPoint.Index + pkscript = txDetail.TxRecord.MsgTx.TxOut[prevIndex].PkScript + } + + vm, err := txscript.NewEngine(pkscript, + fundingTx, i, txscript.StandardVerifyFlags, nil) + if err != nil { + // TODO(roasbeef): cancel at this stage if invalid sigs? + t.Fatalf("cannot create script engine: %s", err) + } + if err = vm.Execute(); err != nil { + t.Fatalf("cannot validate transaction: %s", err) + } + } } func TestFundingTransactionTxFees(t *testing.T) {