Remove need for wallet from BroadcastTransactionTest (#1666)

* Remove need for wallet from BroadcastTransactionTest

* Move balance call, remove extra broadcast call
This commit is contained in:
Ben Carman 2020-07-13 14:03:29 -05:00 committed by GitHub
parent 26f9f6d519
commit 1cd3a9b296

View file

@ -8,11 +8,8 @@ import org.bitcoins.testkit.BitcoinSTestAppConfig
import org.bitcoins.testkit.Implicits._ import org.bitcoins.testkit.Implicits._
import org.bitcoins.testkit.async.TestAsyncUtil import org.bitcoins.testkit.async.TestAsyncUtil
import org.bitcoins.testkit.core.gen.TransactionGenerators import org.bitcoins.testkit.core.gen.TransactionGenerators
import org.bitcoins.testkit.node.{ import org.bitcoins.testkit.node.NodeUnitTest
NodeTestUtil, import org.bitcoins.testkit.node.fixture.SpvNodeConnectedWithBitcoind
NodeUnitTest,
SpvNodeFundedWalletBitcoind
}
import org.scalatest.FutureOutcome import org.scalatest.FutureOutcome
import scala.concurrent.Future import scala.concurrent.Future
@ -25,17 +22,15 @@ class BroadcastTransactionTest extends NodeUnitTest {
implicit override protected def config: BitcoinSAppConfig = implicit override protected def config: BitcoinSAppConfig =
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl) BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
override type FixtureParam = SpvNodeFundedWalletBitcoind override type FixtureParam = SpvNodeConnectedWithBitcoind
def withFixture(test: OneArgAsyncTest): FutureOutcome = def withFixture(test: OneArgAsyncTest): FutureOutcome =
withSpvNodeFundedWalletBitcoind(test, withSpvNodeConnectedToBitcoind(test)
NodeCallbacks.empty,
getBIP39PasswordOpt())
private val sendAmount = 1.bitcoin private val sendAmount = 1.bitcoin
it must "safely broadcast a transaction twice" in { param => it must "safely broadcast a transaction twice" in { param =>
val SpvNodeFundedWalletBitcoind(node, _, _, _) = param val node = param.node
val tx = TransactionGenerators.transaction.sampleSome val tx = TransactionGenerators.transaction.sampleSome
@ -51,7 +46,7 @@ class BroadcastTransactionTest extends NodeUnitTest {
} }
it must "broadcast a transaction" in { param => it must "broadcast a transaction" in { param =>
val SpvNodeFundedWalletBitcoind(node, wallet, rpc, _) = param val SpvNodeConnectedWithBitcoind(node, rpc) = param
def hasSeenTx(transaction: Transaction): Future[Boolean] = { def hasSeenTx(transaction: Transaction): Future[Boolean] = {
rpc rpc
@ -78,20 +73,16 @@ class BroadcastTransactionTest extends NodeUnitTest {
} yield () } yield ()
} }
val addrF = rpc.getNewAddress
val balanceF = rpc.getBalance
for { for {
_ <- wallet.getBloomFilter() // fund bitcoind
_ <- node.sync() _ <- rpc.getNewAddress.flatMap(rpc.generateToAddress(101, _))
_ <- NodeTestUtil.awaitSync(node, rpc) bitcoindBalancePreBroadcast <- rpc.getBalance
address <- addrF rawTx <-
tx <- rpc.createRawTransaction(Vector.empty, Map(junkAddress -> sendAmount))
wallet fundedTx <- rpc.fundRawTransaction(rawTx)
.sendToAddress(address, sendAmount, None) tx <- rpc.signRawTransactionWithWallet(fundedTx.hex).map(_.hex)
bitcoindBalancePreBroadcast <- balanceF
_ <- attemptBroadcast(tx) _ <- attemptBroadcast(tx)
.recoverWith { .recoverWith {
case NonFatal(_) => case NonFatal(_) =>
@ -101,8 +92,7 @@ class BroadcastTransactionTest extends NodeUnitTest {
bitcoindBalancePostBroadcast <- rpc.getBalance bitcoindBalancePostBroadcast <- rpc.getBalance
} yield assert( } yield assert(
// pre-balance + sent amount + 1 block reward maturing // pre-balance - sent amount + 1 block reward maturing +/- fees
bitcoindBalancePreBroadcast + sendAmount + 50.bitcoins == bitcoindBalancePostBroadcast) (bitcoindBalancePreBroadcast - sendAmount + 50.bitcoins).satoshis.toLong === bitcoindBalancePostBroadcast.satoshis.toLong +- 5000)
} }
} }