mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 06:57:51 +01:00
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:
parent
26f9f6d519
commit
1cd3a9b296
1 changed files with 15 additions and 25 deletions
|
@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue