diff --git a/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala b/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala index e559a0623a..8a917593f3 100644 --- a/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala @@ -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))) diff --git a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeTestWithCachedBitcoind.scala b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeTestWithCachedBitcoind.scala index c39726fc14..53e4d8c977 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeTestWithCachedBitcoind.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeTestWithCachedBitcoind.scala @@ -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]( diff --git a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala index 076943ae9d..390c3132db 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala @@ -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)(