From f8e5ac19ba7477acaeb4c5b7f5c217d8c43ac358 Mon Sep 17 00:00:00 2001 From: Torkel Rogstad Date: Thu, 27 Jun 2019 11:57:09 +0200 Subject: [PATCH] Add TX generator for non-empty output TXs --- .../testkit/core/gen/TransactionGenerators.scala | 4 ++++ .../org/bitcoins/testkit/wallet/WalletTestUtil.scala | 10 +--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala index 5f4ac6bb49..c64d92b06d 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala @@ -135,6 +135,10 @@ object TransactionGenerators extends BitcoinSLogger { def transactionTo(spk: ScriptPubKey) = Gen.oneOf(baseTransactionTo(spk), witnessTransactionTo(spk)) + /** Generates a transaction with at least one output */ + def nonEmptyOutputTransaction: Gen[Transaction] = + TransactionGenerators.transaction.suchThat(_.outputs.nonEmpty) + def baseTransaction: Gen[BaseTransaction] = for { version <- NumberGenerator.int32s diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletTestUtil.scala index 2b51f069d6..8c750ee79f 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletTestUtil.scala @@ -16,7 +16,6 @@ import scodec.bits.HexStringSyntax import org.bitcoins.core.hd._ import org.bitcoins.core.protocol.script.ScriptWitness import org.bitcoins.core.protocol.script.P2WPKHWitnessV0 -import org.bitcoins.core.protocol.transaction.Transaction import org.bitcoins.testkit.core.gen.TransactionGenerators import scala.concurrent.Future import org.bitcoins.wallet.models.AddressDb @@ -117,13 +116,6 @@ object WalletTestUtil { val WalletDAOs(accountDAO, addressDAO, txoDAO, _, utxoDAO) = daos - /** Get a TX with outputs */ - def getTx: Transaction = - TransactionGenerators.transaction - .suchThat(_.outputs.nonEmpty) - .sample - .getOrElse(getTx) - val account = WalletTestUtil.firstAccountDb val address = { @@ -137,7 +129,7 @@ object WalletTestUtil { AddressDbHelper.getAddress(pub, path, RegTest) } - val tx = getTx + val tx = TransactionGenerators.nonEmptyOutputTransaction.sampleSome val txoDb = IncomingWalletTXO(confirmations = 3, txid = tx.txIdBE, spent = false,