From 8f5f3bcab25ba987ea70e9a5ede70cd42df1f7e8 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 26 Jul 2018 21:34:43 -0700 Subject: [PATCH] chainntnfs/interface_test: remove code found within helper functions --- chainntnfs/interface_test.go | 61 ++---------------------------------- 1 file changed, 3 insertions(+), 58 deletions(-) diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index 90f31a01..c9c83c20 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -867,69 +867,14 @@ func testSpendBeforeNtfnRegistration(miner *rpctest.Harness, // concrete implementations. // // To do so, we first create a new output to our test target address. - txid, err := getTestTxId(miner) - if err != nil { - t.Fatalf("unable to create test addr: %v", err) - } + outpoint, pkScript := createSpendableOutput(miner, t) - err = waitForMempoolTx(miner, txid) - if err != nil { - t.Fatalf("tx not relayed to miner: %v", err) - } - - // Mine a single block which should include that txid above. - if _, err := miner.Node.Generate(1); err != nil { - t.Fatalf("unable to generate single block: %v", err) - } - - // Now that we have the txid, fetch the transaction itself. - wrappedTx, err := miner.Node.GetRawTransaction(txid) - if err != nil { - t.Fatalf("unable to get new tx: %v", err) - } - tx := wrappedTx.MsgTx() - - // Locate the output index sent to us. We need this so we can construct - // a spending txn below. - outIndex := -1 - var pkScript []byte - for i, txOut := range tx.TxOut { - if bytes.Contains(txOut.PkScript, testAddr.ScriptAddress()) { - pkScript = txOut.PkScript - outIndex = i - break - } - } - if outIndex == -1 { - t.Fatalf("unable to locate new output") - } - - // Now that we've found the output index, register for a spentness - // notification for the newly created output. - outpoint := wire.NewOutPoint(txid, uint32(outIndex)) - - // Next, create a new transaction spending that output. - spendingTx := wire.NewMsgTx(1) - spendingTx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *outpoint, - }) - spendingTx.AddTxOut(&wire.TxOut{ - Value: 1e8, - PkScript: pkScript, - }) - sigScript, err := txscript.SignatureScript(spendingTx, 0, pkScript, - txscript.SigHashAll, privKey, true) - if err != nil { - t.Fatalf("unable to sign tx: %v", err) - } - spendingTx.TxIn[0].SignatureScript = sigScript - - // Broadcast our spending transaction. + // We'll then spend this output and broadcast the spend transaction. + spendingTx := createSpendTx(outpoint, pkScript, t) spenderSha, err := miner.Node.SendRawTransaction(spendingTx, true) if err != nil { t.Fatalf("unable to broadcast tx: %v", err) } - err = waitForMempoolTx(miner, spenderSha) if err != nil { t.Fatalf("tx not relayed to miner: %v", err)