mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 13:35:17 +01:00
Refactor test case to be more idiomatic in hopes this kills CI failures (#2524)
This commit is contained in:
parent
abc1fdd23f
commit
8c918ac0a7
2 changed files with 17 additions and 73 deletions
|
@ -9,6 +9,7 @@ import org.bitcoins.rpc.util.RpcUtil
|
||||||
import org.bitcoins.server.BitcoinSAppConfig
|
import org.bitcoins.server.BitcoinSAppConfig
|
||||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||||
import org.bitcoins.testkit.fixtures.UsesExperimentalBitcoind
|
import org.bitcoins.testkit.fixtures.UsesExperimentalBitcoind
|
||||||
|
import org.bitcoins.testkit.node.fixture.NeutrinoNodeConnectedWithBitcoind
|
||||||
import org.bitcoins.testkit.node.{
|
import org.bitcoins.testkit.node.{
|
||||||
NeutrinoNodeFundedWalletBitcoind,
|
NeutrinoNodeFundedWalletBitcoind,
|
||||||
NodeTestUtil,
|
NodeTestUtil,
|
||||||
|
@ -25,46 +26,18 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
||||||
implicit override protected def getFreshConfig: BitcoinSAppConfig =
|
implicit override protected def getFreshConfig: BitcoinSAppConfig =
|
||||||
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
||||||
|
|
||||||
override type FixtureParam = NeutrinoNodeFundedWalletBitcoind
|
override type FixtureParam = NeutrinoNodeConnectedWithBitcoind
|
||||||
|
|
||||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||||
withNeutrinoNodeFundedWalletBitcoind(test,
|
withNeutrinoNodeConnectedToBitcoind(test, Some(BitcoindVersion.V21))
|
||||||
getBIP39PasswordOpt(),
|
|
||||||
Some(BitcoindVersion.V21))
|
|
||||||
|
|
||||||
private var assertionP: Promise[Boolean] = Promise()
|
|
||||||
after {
|
|
||||||
//reset assertion after a test runs, because we
|
|
||||||
//are doing mutation to work around our callback
|
|
||||||
//limitations, we can't currently modify callbacks
|
|
||||||
//after a NeutrinoNode is constructed :-(
|
|
||||||
assertionP = Promise()
|
|
||||||
}
|
|
||||||
//what is going on here??
|
|
||||||
private val utxos: Set[ScriptPubKey] = Set.empty
|
|
||||||
|
|
||||||
private def blockCallback(block: Block): Future[Unit] = {
|
|
||||||
val scriptPubKeys =
|
|
||||||
block.transactions.flatMap(tx => tx.outputs.map(_.scriptPubKey)).toSet
|
|
||||||
assertionP
|
|
||||||
//is this trivially false always?
|
|
||||||
.success(utxos.intersect(scriptPubKeys) == utxos)
|
|
||||||
.future
|
|
||||||
.map(_ => ())
|
|
||||||
}
|
|
||||||
|
|
||||||
def callbacks: NodeCallbacks = {
|
|
||||||
NodeCallbacks(onBlockReceived = Vector(blockCallback(_)))
|
|
||||||
}
|
|
||||||
|
|
||||||
behavior of "NeutrinoNode"
|
behavior of "NeutrinoNode"
|
||||||
|
|
||||||
it must "receive notification that a block occurred on the p2p network" taggedAs UsesExperimentalBitcoind in {
|
it must "receive notification that a block occurred on the p2p network" taggedAs UsesExperimentalBitcoind in {
|
||||||
nodeConnectedWithBitcoind: NeutrinoNodeFundedWalletBitcoind =>
|
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoind =>
|
||||||
val node = nodeConnectedWithBitcoind.node
|
val node = nodeConnectedWithBitcoind.node
|
||||||
|
|
||||||
val _ = node.nodeAppConfig.addCallbacks(callbacks)
|
val bitcoind = nodeConnectedWithBitcoind.bitcoind
|
||||||
val bitcoind = nodeConnectedWithBitcoind.bitcoindRpc
|
|
||||||
|
|
||||||
val assert1F = for {
|
val assert1F = for {
|
||||||
_ <- node.isConnected.map(assert(_))
|
_ <- node.isConnected.map(assert(_))
|
||||||
|
@ -75,12 +48,10 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
||||||
.flatMap(bitcoind.generateToAddress(1, _))
|
.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
.map(_.head)
|
.map(_.head)
|
||||||
|
|
||||||
//sync our spv node expecting to get that generated hash
|
|
||||||
val syncF = for {
|
val syncF = for {
|
||||||
_ <- assert1F
|
_ <- assert1F
|
||||||
_ <- hashF
|
_ <- hashF
|
||||||
sync <- node.sync()
|
} yield ()
|
||||||
} yield sync
|
|
||||||
|
|
||||||
syncF.flatMap { _ =>
|
syncF.flatMap { _ =>
|
||||||
NodeTestUtil
|
NodeTestUtil
|
||||||
|
@ -90,9 +61,9 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
it must "stay in sync with a bitcoind instance" taggedAs UsesExperimentalBitcoind in {
|
it must "stay in sync with a bitcoind instance" taggedAs UsesExperimentalBitcoind in {
|
||||||
nodeConnectedWithBitcoind: NeutrinoNodeFundedWalletBitcoind =>
|
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoind =>
|
||||||
val node = nodeConnectedWithBitcoind.node
|
val node = nodeConnectedWithBitcoind.node
|
||||||
val bitcoind = nodeConnectedWithBitcoind.bitcoindRpc
|
val bitcoind = nodeConnectedWithBitcoind.bitcoind
|
||||||
|
|
||||||
//we need to generate 1 block for bitcoind to consider
|
//we need to generate 1 block for bitcoind to consider
|
||||||
//itself out of IBD. bitcoind will not sendheaders
|
//itself out of IBD. bitcoind will not sendheaders
|
||||||
|
@ -105,9 +76,7 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
||||||
//both our spv node and our bitcoind node _should_ both be at the genesis block (regtest)
|
//both our spv node and our bitcoind node _should_ both be at the genesis block (regtest)
|
||||||
//at this point so no actual syncing is happening
|
//at this point so no actual syncing is happening
|
||||||
val initSyncF = gen1F.flatMap { hashes =>
|
val initSyncF = gen1F.flatMap { hashes =>
|
||||||
val syncF = node.sync()
|
|
||||||
for {
|
for {
|
||||||
_ <- syncF
|
|
||||||
_ <- NodeTestUtil.awaitBestHash(hashes.head, node)
|
_ <- NodeTestUtil.awaitBestHash(hashes.head, node)
|
||||||
} yield ()
|
} yield ()
|
||||||
}
|
}
|
||||||
|
@ -123,39 +92,8 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
||||||
startGenF.flatMap { cancellable =>
|
startGenF.flatMap { cancellable =>
|
||||||
//we should expect 5 headers have been announced to us via
|
//we should expect 5 headers have been announced to us via
|
||||||
//the send headers message.
|
//the send headers message.
|
||||||
val ExpectedCount = 119
|
|
||||||
|
|
||||||
def hasBlocksF =
|
|
||||||
RpcUtil.retryUntilSatisfiedF(conditionF = () => {
|
|
||||||
node
|
|
||||||
.chainApiFromDb()
|
|
||||||
.flatMap(_.getBlockCount())
|
|
||||||
.map(_ == ExpectedCount)
|
|
||||||
},
|
|
||||||
interval = 1000.millis)
|
|
||||||
|
|
||||||
def hasFilterHeadersF =
|
|
||||||
RpcUtil.retryUntilSatisfiedF(conditionF = () => {
|
|
||||||
node
|
|
||||||
.chainApiFromDb()
|
|
||||||
.flatMap(_.getFilterHeaderCount())
|
|
||||||
.map(_ == ExpectedCount)
|
|
||||||
},
|
|
||||||
interval = 1000.millis)
|
|
||||||
|
|
||||||
def hasFiltersF =
|
|
||||||
RpcUtil.retryUntilSatisfiedF(conditionF = () => {
|
|
||||||
node
|
|
||||||
.chainApiFromDb()
|
|
||||||
.flatMap(_.getFilterCount())
|
|
||||||
.map(_ == ExpectedCount)
|
|
||||||
},
|
|
||||||
interval = 1000.millis)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- hasBlocksF
|
_ <- NodeTestUtil.awaitSync(node, bitcoind)
|
||||||
_ <- hasFilterHeadersF
|
|
||||||
_ <- hasFiltersF
|
|
||||||
} yield {
|
} yield {
|
||||||
val isCancelled = cancellable.cancel()
|
val isCancelled = cancellable.cancel()
|
||||||
if (!isCancelled) {
|
if (!isCancelled) {
|
||||||
|
|
|
@ -35,7 +35,11 @@ import org.bitcoins.testkit.EmbeddedPg
|
||||||
import org.bitcoins.testkit.chain.ChainUnitTest
|
import org.bitcoins.testkit.chain.ChainUnitTest
|
||||||
import org.bitcoins.testkit.fixtures.BitcoinSFixture
|
import org.bitcoins.testkit.fixtures.BitcoinSFixture
|
||||||
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil
|
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil
|
||||||
import org.bitcoins.testkit.node.NodeUnitTest.{createPeer, emptyPeer}
|
import org.bitcoins.testkit.node.NodeUnitTest.{
|
||||||
|
createPeer,
|
||||||
|
emptyPeer,
|
||||||
|
syncNeutrinoNode
|
||||||
|
}
|
||||||
import org.bitcoins.testkit.node.fixture.{
|
import org.bitcoins.testkit.node.fixture.{
|
||||||
NeutrinoNodeConnectedWithBitcoind,
|
NeutrinoNodeConnectedWithBitcoind,
|
||||||
NodeConnectedWithBitcoind,
|
NodeConnectedWithBitcoind,
|
||||||
|
@ -262,7 +266,9 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg {
|
||||||
node <- NodeUnitTest.createNeutrinoNode(bitcoind)(system,
|
node <- NodeUnitTest.createNeutrinoNode(bitcoind)(system,
|
||||||
appConfig.chainConf,
|
appConfig.chainConf,
|
||||||
appConfig.nodeConf)
|
appConfig.nodeConf)
|
||||||
} yield NeutrinoNodeConnectedWithBitcoind(node, bitcoind)
|
startedNode <- node.start()
|
||||||
|
syncedNode <- syncNeutrinoNode(startedNode, bitcoind)
|
||||||
|
} yield NeutrinoNodeConnectedWithBitcoind(syncedNode, bitcoind)
|
||||||
}
|
}
|
||||||
makeDependentFixture(
|
makeDependentFixture(
|
||||||
build = nodeWithBitcoindBuilder,
|
build = nodeWithBitcoindBuilder,
|
||||||
|
|
Loading…
Add table
Reference in a new issue