2023 12 13 mv connectioncount check fixtures (#5324)

* Move peer connection count checks into test fixtures

* Add connection count check in another test fixture

* scalafmt
This commit is contained in:
Chris Stewart 2023-12-14 06:19:47 -06:00 committed by GitHub
parent 7f337073c9
commit 01537185bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -51,10 +51,6 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
def peers = peerManager.peers
val connAndInit = for {
_ <- AsyncUtil
.retryUntilSatisfied(peers.size == 2,
maxTries = 30,
interval = 1.second)
_ <- Future
.sequence(peers.map(peerManager.isConnected))
.flatMap(p => assert(p.forall(_ == true)))
@ -144,10 +140,6 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
//assert connected to 2 peers and both initialised and connected
val assertConnAndInit = for {
_ <- AsyncUtil
.retryUntilSatisfied(peers.size == 2,
interval = 1.second,
maxTries = 30)
_ <- Future
.sequence(peers.map(peerManager.isConnected))
.flatMap(p => assert(p.forall(_ == true)))
@ -178,10 +170,6 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
def peers = peerManager.peers
val assert1F = for {
_ <- AsyncUtil
.retryUntilSatisfied(peers.size == 2,
interval = 1.second,
maxTries = 30)
_ <- Future
.sequence(peers.map(peerManager.isConnected))
.flatMap(p => assert(p.forall(_ == true)))

View File

@ -1,6 +1,7 @@
package org.bitcoins.testkit.node
import akka.actor.ActorSystem
import org.bitcoins.asyncutil.AsyncUtil
import org.bitcoins.core.api.node.{NodeType, Peer}
import org.bitcoins.node.Node
import org.bitcoins.rpc.client.common.BitcoindRpcClient
@ -22,6 +23,7 @@ import org.bitcoins.wallet.callback.WalletCallbacks
import org.scalatest.FutureOutcome
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
/** Test trait for using a bitcoin-s [[Node]] that requires a cached bitcoind.
* The cached bitcoind will be share across tests in the test suite that extends
@ -44,6 +46,10 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
appConfig.chainConf,
appConfig.nodeConf)
started <- node.start()
_ <- AsyncUtil.retryUntilSatisfied(
node.peerManager.connectedPeerCount == 1,
interval = 1.second,
maxTries = 30)
} yield NeutrinoNodeConnectedWithBitcoind(started, bitcoind)
}
@ -92,6 +98,10 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
appConfig.chainConf,
appConfig.nodeConf)
startedNode <- node.start()
_ <- AsyncUtil.retryUntilSatisfied(
node.peerManager.connectedPeerCount == 1,
interval = 1.second,
maxTries = 30)
} yield NeutrinoNodeConnectedWithBitcoinds(startedNode, bitcoinds)
}
makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds](
@ -116,6 +126,10 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest with CachedTor {
appConfig.chainConf,
appConfig.nodeConf)
startedNode <- node.start()
_ <- AsyncUtil
.retryUntilSatisfied(node.peerManager.connectedPeerCount == 2,
interval = 1.second,
maxTries = 30)
} yield NeutrinoNodeConnectedWithBitcoinds(startedNode, bitcoinds)
}
makeDependentFixture[NeutrinoNodeConnectedWithBitcoinds](

View File

@ -20,6 +20,7 @@ import org.scalatest.FutureOutcome
import java.net.InetSocketAddress
import java.time.Instant
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
trait NodeUnitTest extends BaseNodeTest {
@ -300,6 +301,10 @@ object NodeUnitTest extends P2PLogger {
walletCallbacks = walletCallbacks)
startedNode <- node.start()
_ <- AsyncUtil
.retryUntilSatisfied(node.peerManager.connectedPeerCount == 1,
interval = 1.second,
maxTries = 30)
//callbacks are executed asynchronously, which is how we fund the wallet
//so we need to wait until the wallet balances are correct
_ <- BitcoinSWalletTest.awaitWalletBalances(fundedWallet)(