mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
2021 04 27 wallet fixtures config (#2980)
* Refactor MultiWalletTest to actually shutdown the walletAppConfigs * Remove 'implicit' modifier from getFreshWalletConfig. This is a problem as it can be used implicitly to bind resources (threads, files etc) that need to be cleaned up. Since it is implicitly passed, it is very hard to remember to clean up these resources * Cleanup TrezorAddressTest * Remove unecessary BitcoinSWalletTest.afterAll() * Fix docs * Removal of datadir race condition * Cleanup nodeTest to shutdown the transitive chainAppConfig required by NodeAppConfig * remove experimental tag on NeutrinoNodeTest * Remove extra line * Cleanup after BitcoindChainhandlerViaZmqTest * Push to github to force re-run of CI 2
This commit is contained in:
parent
6fbaf9f9ce
commit
77cd94ac41
@ -44,6 +44,7 @@ import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.fixtures._
|
||||
import org.bitcoins.testkit.wallet._
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
import akka.actor.ActorSystem
|
||||
import scala.concurrent.{ExecutionContext, Future, Await}
|
||||
import scala.concurrent.duration.DurationInt
|
||||
@ -55,6 +56,7 @@ import scala.concurrent.duration.DurationInt
|
||||
implicit val system: ActorSystem = ActorSystem(s"wallet-rescan-example")
|
||||
implicit val ec: ExecutionContext = system.dispatcher
|
||||
implicit val appConfig: BitcoinSAppConfig = BitcoinSTestAppConfig.getNeutrinoTestConfig()
|
||||
implicit val walletAppConfig: WalletAppConfig = appConfig.walletConf
|
||||
|
||||
val bip39PasswordOpt = None
|
||||
//ok now let's spin up a bitcoind and a bitcoin-s wallet with funds in it
|
||||
|
@ -19,7 +19,7 @@ class BroadcastTransactionTest extends NodeTestWithCachedBitcoindV19 {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNodeConnectedWithBitcoindV19
|
||||
|
||||
|
@ -2,24 +2,20 @@ package org.bitcoins.node
|
||||
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.node.NodeUnitTest
|
||||
import org.bitcoins.testkitcore.Implicits._
|
||||
import org.bitcoins.testkitcore.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.node.{CachedBitcoinSAppConfig, NodeUnitTest}
|
||||
import org.scalatest.FutureOutcome
|
||||
|
||||
class DisconnectedPeerTest extends NodeUnitTest with CachedBitcoinSAppConfig {
|
||||
class DisconnectedPeerTest extends NodeUnitTest {
|
||||
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
implicit override protected lazy val cachedConfig: BitcoinSAppConfig =
|
||||
getFreshConfig
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNode
|
||||
|
||||
def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||
withDisconnectedSpvNode(test)(system, cachedConfig)
|
||||
withDisconnectedSpvNode(test)(system, getFreshConfig)
|
||||
|
||||
it must "fail to broadcast a transaction when disconnected" in { node =>
|
||||
val tx = TransactionGenerators.transaction.sampleSome
|
||||
|
@ -4,7 +4,6 @@ import akka.actor.Cancellable
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.fixtures.UsesExperimentalBitcoind
|
||||
import org.bitcoins.testkit.node.fixture.NeutrinoNodeConnectedWithBitcoind
|
||||
import org.bitcoins.testkit.node.{
|
||||
NodeTestUtil,
|
||||
@ -35,7 +34,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindNewest {
|
||||
|
||||
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 for neutrino" in {
|
||||
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoind =>
|
||||
val node = nodeConnectedWithBitcoind.node
|
||||
|
||||
@ -62,7 +61,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindNewest {
|
||||
}
|
||||
}
|
||||
|
||||
it must "stay in sync with a bitcoind instance" taggedAs UsesExperimentalBitcoind in {
|
||||
it must "stay in sync with a bitcoind instance for neutrino" in {
|
||||
nodeConnectedWithBitcoind: NeutrinoNodeConnectedWithBitcoind =>
|
||||
val node = nodeConnectedWithBitcoind.node
|
||||
val bitcoind = nodeConnectedWithBitcoind.bitcoind
|
||||
|
@ -19,7 +19,7 @@ class SpvNodeTest extends NodeTestWithCachedBitcoindNewest {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNodeConnectedWithBitcoind
|
||||
|
||||
|
@ -19,7 +19,7 @@ class SpvNodeWithWalletTest extends NodeTestWithCachedBitcoindNewest {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNodeFundedWalletBitcoind
|
||||
|
||||
|
@ -16,7 +16,7 @@ class UpdateBloomFilterTest extends NodeTestWithCachedBitcoindNewest {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNodeFundedWalletBitcoind
|
||||
|
||||
|
@ -1,16 +1,10 @@
|
||||
package org.bitcoins.node.models
|
||||
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.fixtures.NodeDAOFixture
|
||||
import org.bitcoins.testkitcore.Implicits._
|
||||
import org.bitcoins.testkitcore.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.fixtures.NodeDAOFixture
|
||||
import org.bitcoins.testkit.{BitcoinSTestAppConfig, EmbeddedPg}
|
||||
|
||||
class BroadcastAbleTransactionDAOTest extends NodeDAOFixture with EmbeddedPg {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
class BroadcastAbleTransactionDAOTest extends NodeDAOFixture {
|
||||
|
||||
behavior of "BroadcastAbleTransactionDAO"
|
||||
|
||||
|
@ -21,7 +21,7 @@ class DataMessageHandlerTest extends NodeUnitTest {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
override type FixtureParam = SpvNodeConnectedWithBitcoindV19
|
||||
|
||||
|
@ -78,6 +78,10 @@ class MerkleBuffersTest extends BitcoinSAsyncTest with CachedBitcoinSAppConfig {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[CachedBitcoinSAppConfig].afterAll()
|
||||
super[BitcoinSAsyncTest].afterAll()
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ object BitcoinSTestAppConfig {
|
||||
|
||||
def getSpvWithEmbeddedDbTestConfig(
|
||||
pgUrl: () => Option[String],
|
||||
config: Config*)(implicit ec: ExecutionContext): BitcoinSAppConfig = {
|
||||
config: Vector[Config])(implicit
|
||||
ec: ExecutionContext): BitcoinSAppConfig = {
|
||||
val overrideConf = ConfigFactory
|
||||
.parseString {
|
||||
"""
|
||||
|
@ -580,7 +580,11 @@ object ChainUnitTest extends ChainVerificationLogger {
|
||||
val stopBitcoindF =
|
||||
BitcoindRpcTestUtil.stopServer(bitcoindChainHandler.bitcoindRpc)
|
||||
val dropTableF = ChainUnitTest.destroyAllTables()
|
||||
stopBitcoindF.flatMap(_ => dropTableF)
|
||||
val stoppedChainAppConfigF = dropTableF.flatMap(_ => chainAppConfig.stop())
|
||||
for {
|
||||
_ <- stopBitcoindF
|
||||
_ <- stoppedChainAppConfigF
|
||||
} yield ()
|
||||
}
|
||||
|
||||
def destroyBitcoind(bitcoind: BitcoindRpcClient)(implicit
|
||||
|
@ -1,7 +1,10 @@
|
||||
package org.bitcoins.testkit.fixtures
|
||||
|
||||
import org.bitcoins.chain.config.ChainAppConfig
|
||||
import org.bitcoins.node.config.NodeAppConfig
|
||||
import org.bitcoins.node.models.BroadcastAbleTransactionDAO
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||
import org.bitcoins.testkit.node.{CachedBitcoinSAppConfig, NodeUnitTest}
|
||||
import org.scalatest._
|
||||
|
||||
@ -12,6 +15,10 @@ case class NodeDAOs(txDAO: BroadcastAbleTransactionDAO)
|
||||
/** Provides a fixture where all DAOs used by the node projects are provided */
|
||||
trait NodeDAOFixture extends NodeUnitTest with CachedBitcoinSAppConfig {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, Vector.empty)
|
||||
|
||||
private lazy val daos = {
|
||||
val tx = BroadcastAbleTransactionDAO()
|
||||
NodeDAOs(tx)
|
||||
@ -21,17 +28,29 @@ trait NodeDAOFixture extends NodeUnitTest with CachedBitcoinSAppConfig {
|
||||
|
||||
def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
makeFixture(build = () => {
|
||||
cachedNodeConf
|
||||
.start()
|
||||
.map(_ => daos)
|
||||
for {
|
||||
_ <- cachedChainConf.start()
|
||||
_ <- cachedNodeConf.start()
|
||||
} yield daos
|
||||
},
|
||||
destroy = () => destroyAppConfig(cachedNodeConf))(test)
|
||||
destroy =
|
||||
() => destroyAppConfig(cachedChainConf, cachedNodeConf))(test)
|
||||
}
|
||||
|
||||
private def destroyAppConfig(nodeConfig: NodeAppConfig): Future[Unit] = {
|
||||
private def destroyAppConfig(
|
||||
chainConfig: ChainAppConfig,
|
||||
nodeConfig: NodeAppConfig): Future[Unit] = {
|
||||
|
||||
for {
|
||||
_ <- nodeConfig.dropAll()
|
||||
_ <- nodeConfig.stop()
|
||||
_ <- chainConfig.dropAll()
|
||||
_ <- chainConfig.stop()
|
||||
} yield ()
|
||||
}
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[CachedBitcoinSAppConfig].afterAll()
|
||||
super[NodeUnitTest].afterAll()
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package org.bitcoins.testkit.node
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import org.bitcoins.node.{Node, NodeType}
|
||||
import org.bitcoins.node.models.Peer
|
||||
import org.bitcoins.node.{Node, NodeType}
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.chain.ChainUnitTest
|
||||
import org.bitcoins.testkit.node.NodeUnitTest.{createPeer, syncNeutrinoNode}
|
||||
import org.bitcoins.testkit.node.fixture.{
|
||||
NeutrinoNodeConnectedWithBitcoind,
|
||||
@ -146,8 +145,6 @@ trait NodeTestWithCachedBitcoind extends BaseNodeTest { _: CachedBitcoind[_] =>
|
||||
val destroyNodeF = NodeUnitTest.destroyNode(node)
|
||||
for {
|
||||
_ <- destroyNodeF
|
||||
_ <- ChainUnitTest.destroyAllTables()(node.chainAppConfig,
|
||||
system.dispatcher)
|
||||
//need to stop chainAppConfig too since this is a test
|
||||
_ <- node.chainAppConfig.stop()
|
||||
} yield ()
|
||||
|
@ -246,6 +246,7 @@ object NodeUnitTest extends P2PLogger {
|
||||
def destroyNode(node: Node)(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
for {
|
||||
_ <- node.stop()
|
||||
_ <- node.chainAppConfig.stop()
|
||||
} yield {
|
||||
()
|
||||
}
|
||||
@ -303,6 +304,7 @@ object NodeUnitTest extends P2PLogger {
|
||||
require(appConfig.nodeType == NodeType.SpvNode)
|
||||
for {
|
||||
node <- createSpvNode(createPeer(bitcoind))
|
||||
_ <- appConfig.walletConf.start()
|
||||
fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(
|
||||
bitcoind,
|
||||
node,
|
||||
|
@ -14,7 +14,7 @@ import org.bitcoins.testkit.{BitcoinSTestAppConfig, EmbeddedPg}
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
import org.scalatest.AsyncTestSuite
|
||||
|
||||
import scala.concurrent.Future
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
/** Base test trait for all the tests in our walletTest module */
|
||||
trait BaseWalletTest extends EmbeddedPg { _: AsyncTestSuite =>
|
||||
@ -39,10 +39,10 @@ trait BaseWalletTest extends EmbeddedPg { _: AsyncTestSuite =>
|
||||
"00000000496dcc754fabd97f3e2df0a7337eab417d75537fecf97a7ebb0e7c75")
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
implicit protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl)
|
||||
protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BaseWalletTest.getFreshConfig(pgUrl, Vector.empty)
|
||||
|
||||
implicit protected def getFreshWalletAppConfig: WalletAppConfig = {
|
||||
protected def getFreshWalletAppConfig: WalletAppConfig = {
|
||||
getFreshConfig.walletConf
|
||||
}
|
||||
|
||||
@ -123,3 +123,19 @@ trait BaseWalletTest extends EmbeddedPg { _: AsyncTestSuite =>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object BaseWalletTest {
|
||||
|
||||
def getFreshConfig(pgUrl: () => Option[String], config: Vector[Config])(
|
||||
implicit ec: ExecutionContext): BitcoinSAppConfig = {
|
||||
BitcoinSTestAppConfig.getSpvWithEmbeddedDbTestConfig(pgUrl, config)
|
||||
}
|
||||
|
||||
def getFreshWalletAppConfig(
|
||||
pgUrl: () => Option[String],
|
||||
config: Vector[Config])(implicit
|
||||
ec: ExecutionContext): WalletAppConfig = {
|
||||
getFreshConfig(pgUrl, config).walletConf
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import org.bitcoins.testkit.EmbeddedPg
|
||||
import org.bitcoins.testkit.chain.SyncUtil
|
||||
import org.bitcoins.testkit.fixtures.BitcoinSFixture
|
||||
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil
|
||||
import org.bitcoins.testkit.util.FileUtil
|
||||
import org.bitcoins.testkit.wallet.FundWalletUtil.FundedWallet
|
||||
import org.bitcoins.testkitcore.Implicits.GeneratorOps
|
||||
import org.bitcoins.testkitcore.gen._
|
||||
@ -46,19 +45,13 @@ trait BitcoinSWalletTest
|
||||
with EmbeddedPg {
|
||||
import BitcoinSWalletTest._
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
Await.result(getFreshConfig.chainConf.stop(), 1.minute)
|
||||
Await.result(getFreshConfig.nodeConf.stop(), 1.minute)
|
||||
Await.result(getFreshConfig.walletConf.stop(), 1.minute)
|
||||
super.afterAll()
|
||||
}
|
||||
|
||||
def nodeApi: NodeApi = MockNodeApi
|
||||
|
||||
/** Lets you customize the parameters for the created wallet */
|
||||
val withNewConfiguredWallet: Config => OneArgAsyncTest => FutureOutcome = {
|
||||
walletConfig =>
|
||||
val newWalletConf = getFreshWalletAppConfig.withOverrides(walletConfig)
|
||||
implicit val newWalletConf =
|
||||
getFreshWalletAppConfig.withOverrides(walletConfig)
|
||||
val km = createNewKeyManager()(newWalletConf)
|
||||
val bip39PasswordOpt = KeyManagerTestUtil.bip39PasswordOpt
|
||||
makeDependentFixture(
|
||||
@ -75,9 +68,8 @@ trait BitcoinSWalletTest
|
||||
* peered with a bitcoind so the funds in the wallet are not tied to an
|
||||
* underlying blockchain
|
||||
*/
|
||||
def withFundedWallet(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
def withFundedWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String])(
|
||||
implicit walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
makeDependentFixture(
|
||||
build = () =>
|
||||
FundWalletUtil.createFundedWallet(nodeApi,
|
||||
@ -91,7 +83,8 @@ trait BitcoinSWalletTest
|
||||
|
||||
def withFundedSegwitWallet(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
makeDependentFixture(
|
||||
build = () =>
|
||||
FundWalletUtil.createFundedWallet(nodeApi,
|
||||
@ -114,9 +107,8 @@ trait BitcoinSWalletTest
|
||||
withNewConfiguredWallet(segwitWalletConf)(test)
|
||||
}
|
||||
|
||||
def withNewWallet(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome =
|
||||
def withNewWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String])(
|
||||
implicit walletAppConfig: WalletAppConfig): FutureOutcome =
|
||||
makeDependentFixture(
|
||||
build = { () =>
|
||||
createDefaultWallet(nodeApi, chainQueryApi, bip39PasswordOpt)
|
||||
@ -125,7 +117,8 @@ trait BitcoinSWalletTest
|
||||
|
||||
def withNewWallet2Accounts(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
makeDependentFixture(
|
||||
build = { () =>
|
||||
createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt)
|
||||
@ -133,7 +126,8 @@ trait BitcoinSWalletTest
|
||||
destroy = destroyWallet)(test)
|
||||
}
|
||||
|
||||
def withNewWalletAndBitcoind(test: OneArgAsyncTest): FutureOutcome = {
|
||||
def withNewWalletAndBitcoind(test: OneArgAsyncTest)(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap(
|
||||
builder = { () =>
|
||||
BitcoinSFixture.createBitcoindWithFunds()
|
||||
@ -150,7 +144,8 @@ trait BitcoinSWalletTest
|
||||
|
||||
def withNewWalletAndBitcoindV19(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap(
|
||||
builder = { () =>
|
||||
BitcoinSFixture
|
||||
@ -170,7 +165,8 @@ trait BitcoinSWalletTest
|
||||
|
||||
def withFundedWalletAndBitcoindV19(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoindV19] = { () =>
|
||||
for {
|
||||
bitcoind <-
|
||||
@ -192,30 +188,11 @@ trait BitcoinSWalletTest
|
||||
|
||||
def withWalletConfig(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val builder: () => Future[WalletAppConfig] = () => {
|
||||
val baseConf = getFreshConfig.walletConf
|
||||
val walletNameOpt = if (NumberGenerator.bool.sampleSome) {
|
||||
Some(StringGenerators.genNonEmptyString.sampleSome)
|
||||
} else None
|
||||
|
||||
val walletConf = walletNameOpt match {
|
||||
case Some(walletName) =>
|
||||
val walletNameOverride = ConfigFactory.parseString(
|
||||
s"bitcoin-s.wallet.walletName = $walletName"
|
||||
)
|
||||
|
||||
BitcoinSAppConfig(
|
||||
baseConf.baseDatadir,
|
||||
(walletNameOverride +: baseConf.configOverrides): _*).walletConf
|
||||
case None => baseConf
|
||||
}
|
||||
|
||||
walletConf.start().map(_ => walletConf)
|
||||
createWalletAppConfig(pgUrl, Vector.empty)
|
||||
}
|
||||
|
||||
val destroy: WalletAppConfig => Future[Unit] = walletAppConfig => {
|
||||
FileUtil.deleteTmpDir(walletAppConfig.datadir)
|
||||
walletAppConfig.stop()
|
||||
Future.unit
|
||||
destroyWalletAppConfig(walletAppConfig)
|
||||
}
|
||||
makeDependentFixture(builder, destroy = destroy)(test)
|
||||
}
|
||||
@ -299,6 +276,30 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
}
|
||||
}
|
||||
|
||||
def createWalletAppConfig(
|
||||
pgUrl: () => Option[String],
|
||||
configs: Vector[Config])(implicit
|
||||
ec: ExecutionContext): Future[WalletAppConfig] = {
|
||||
val baseConf = BaseWalletTest.getFreshWalletAppConfig(pgUrl, configs)
|
||||
val walletNameOpt = if (NumberGenerator.bool.sampleSome) {
|
||||
Some(StringGenerators.genNonEmptyString.sampleSome)
|
||||
} else None
|
||||
|
||||
val walletConf = walletNameOpt match {
|
||||
case Some(walletName) =>
|
||||
val walletNameOverride = ConfigFactory.parseString(
|
||||
s"bitcoin-s.wallet.walletName = $walletName"
|
||||
)
|
||||
|
||||
BitcoinSAppConfig(
|
||||
baseConf.baseDatadir,
|
||||
(walletNameOverride +: baseConf.configOverrides): _*).walletConf
|
||||
case None => baseConf
|
||||
}
|
||||
|
||||
walletConf.start().map(_ => walletConf)
|
||||
}
|
||||
|
||||
/** Returns a function that can be used to create a wallet fixture.
|
||||
* If you pass in a configuration to this method that configuration
|
||||
* is given to the wallet as user-provided overrides. You could for
|
||||
@ -311,13 +312,12 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
extraConfig: Option[Config],
|
||||
nodeApi: NodeApi,
|
||||
chainQueryApi: ChainQueryApi)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
ec: ExecutionContext): () => Future[Wallet] =
|
||||
() => {
|
||||
val defaultConf = config.walletConf
|
||||
val walletConfig = extraConfig match {
|
||||
case None => defaultConf
|
||||
case Some(c) => defaultConf.withOverrides(c)
|
||||
case None => config
|
||||
case Some(c) => config.withOverrides(c)
|
||||
}
|
||||
|
||||
// we want to check we're not overwriting
|
||||
@ -341,13 +341,13 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
chainQueryApi: ChainQueryApi,
|
||||
bip39PasswordOpt: Option[String],
|
||||
extraConfig: Option[Config] = None)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
ec: ExecutionContext): Future[Wallet] = {
|
||||
val newWalletConf = extraConfig match {
|
||||
case None =>
|
||||
config.walletConf
|
||||
config
|
||||
case Some(walletConf) =>
|
||||
config.walletConf.withOverrides(walletConf)
|
||||
config.withOverrides(walletConf)
|
||||
}
|
||||
val km =
|
||||
createNewKeyManager(bip39PasswordOpt = bip39PasswordOpt)(newWalletConf)
|
||||
@ -366,7 +366,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
bitcoind: BitcoindRpcClient,
|
||||
bip39PasswordOpt: Option[String],
|
||||
extraConfig: Option[Config] = None)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
system: ActorSystem): Future[WalletWithBitcoind] = {
|
||||
import system.dispatcher
|
||||
//we need to create a promise so we can inject the wallet with the callback
|
||||
@ -404,7 +404,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
chainQueryApi: ChainQueryApi,
|
||||
bip39PasswordOpt: Option[String],
|
||||
extraConfig: Option[Config] = None)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
system: ActorSystem): Future[Wallet] = {
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
|
||||
@ -440,7 +440,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
|
||||
def createWalletWithBitcoind(bitcoind: BitcoindRpcClient)(implicit
|
||||
system: ActorSystem,
|
||||
config: BitcoinSAppConfig): Future[WalletWithBitcoind] = {
|
||||
config: WalletAppConfig): Future[WalletWithBitcoind] = {
|
||||
createWalletWithBitcoindCallbacks(bitcoind, None)
|
||||
}
|
||||
|
||||
@ -460,7 +460,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
bitcoind: BitcoindV19RpcClient,
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
system: ActorSystem,
|
||||
config: BitcoinSAppConfig): Future[WalletWithBitcoindV19] = {
|
||||
config: WalletAppConfig): Future[WalletWithBitcoindV19] = {
|
||||
import system.dispatcher
|
||||
for {
|
||||
created <- createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt)
|
||||
@ -471,7 +471,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
bitcoind: BitcoindRpcClient,
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
system: ActorSystem,
|
||||
config: BitcoinSAppConfig): Future[WalletWithBitcoindRpc] = {
|
||||
config: WalletAppConfig): Future[WalletWithBitcoindRpc] = {
|
||||
import system.dispatcher
|
||||
for {
|
||||
created <- createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt)
|
||||
@ -583,10 +583,15 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
_ <- wallet.walletConfig.dropTable("flyway_schema_history")
|
||||
_ <- wallet.walletConfig.dropAll()
|
||||
_ <- wallet.stop()
|
||||
_ <- wallet.walletConfig.stop()
|
||||
_ <- destroyWalletAppConfig(wallet.walletConfig)
|
||||
} yield ()
|
||||
}
|
||||
|
||||
def destroyWalletAppConfig(walletAppConfig: WalletAppConfig): Future[Unit] = {
|
||||
val stoppedF = walletAppConfig.stop()
|
||||
stoppedF
|
||||
}
|
||||
|
||||
/** Constructs callbacks for the wallet from the node to process blocks and compact filters */
|
||||
def createNeutrinoNodeCallbacksForWallet(wallet: Wallet)(implicit
|
||||
ec: ExecutionContext): NodeCallbacks = {
|
||||
@ -624,7 +629,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
* [[BitcoinSWalletTest]]. This will future won't be completed until balances satisfy [[isSameWalletBalances()]]
|
||||
*/
|
||||
def awaitWalletBalances(fundedWallet: WalletWithBitcoind)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
system: ActorSystem): Future[Unit] = {
|
||||
AsyncUtil.retryUntilSatisfiedF(conditionF =
|
||||
() => isSameWalletBalances(fundedWallet),
|
||||
@ -632,11 +637,11 @@ object BitcoinSWalletTest extends WalletLogger {
|
||||
}
|
||||
|
||||
private def isSameWalletBalances(fundedWallet: WalletWithBitcoind)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
system: ActorSystem): Future[Boolean] = {
|
||||
import system.dispatcher
|
||||
val defaultAccount = config.walletConf.defaultAccount
|
||||
val hdAccount1 = WalletTestUtil.getHdAccount1(config.walletConf)
|
||||
val defaultAccount = config.defaultAccount
|
||||
val hdAccount1 = WalletTestUtil.getHdAccount1(config)
|
||||
val expectedDefaultAmt = BitcoinSWalletTest.expectedDefaultAmt
|
||||
val expectedAccount1Amt = BitcoinSWalletTest.expectedAccount1Amt
|
||||
val defaultBalanceF = fundedWallet.wallet.getBalance(defaultAccount)
|
||||
|
@ -17,6 +17,7 @@ import org.bitcoins.testkit.wallet.BitcoinSWalletTest.{
|
||||
destroyWallet,
|
||||
fundWalletWithBitcoind
|
||||
}
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
import org.scalatest.{FutureOutcome, Outcome}
|
||||
|
||||
import scala.concurrent.Future
|
||||
@ -42,7 +43,8 @@ trait BitcoinSWalletTestCachedBitcoind
|
||||
def withFundedWalletAndBitcoindCached(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String],
|
||||
bitcoind: BitcoindRpcClient): FutureOutcome = {
|
||||
bitcoind: BitcoindRpcClient)(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoind] = { () =>
|
||||
for {
|
||||
walletWithBitcoind <- createWalletWithBitcoindCallbacks(
|
||||
@ -65,7 +67,8 @@ trait BitcoinSWalletTestCachedBitcoind
|
||||
def withNewWalletAndBitcoindCached(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String],
|
||||
bitcoind: BitcoindRpcClient): FutureOutcome = {
|
||||
bitcoind: BitcoindRpcClient)(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap(
|
||||
builder = { () =>
|
||||
Future.successful(bitcoind)
|
||||
@ -86,7 +89,8 @@ trait BitcoinSWalletTestCachedBitcoind
|
||||
|
||||
def withFundedWalletAndBitcoind(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String]): FutureOutcome = {
|
||||
bip39PasswordOpt: Option[String])(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val bitcoindF = BitcoinSFixture
|
||||
.createBitcoindWithFunds(None)
|
||||
|
||||
@ -157,7 +161,8 @@ trait BitcoinSWalletTestCachedBitcoinV19
|
||||
def withFundedWalletAndBitcoindCachedV19(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String],
|
||||
bitcoind: BitcoindV19RpcClient): FutureOutcome = {
|
||||
bitcoind: BitcoindV19RpcClient)(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoindV19] = { () =>
|
||||
for {
|
||||
walletWithBitcoind <- createWalletWithBitcoindCallbacks(
|
||||
@ -183,7 +188,8 @@ trait BitcoinSWalletTestCachedBitcoinV19
|
||||
def withNewWalletAndBitcoindCachedV19(
|
||||
test: OneArgAsyncTest,
|
||||
bip39PasswordOpt: Option[String],
|
||||
bitcoind: BitcoindV19RpcClient): FutureOutcome = {
|
||||
bitcoind: BitcoindV19RpcClient)(implicit
|
||||
walletAppConfig: WalletAppConfig): FutureOutcome = {
|
||||
val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap(
|
||||
builder = { () =>
|
||||
Future.successful(bitcoind)
|
||||
@ -207,9 +213,10 @@ trait BitcoinSWalletTestCachedBitcoinV19
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withFundedWalletAndBitcoindCachedV19(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withFundedWalletAndBitcoindCachedV19(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -2,19 +2,19 @@ package org.bitcoins.testkit.wallet
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.api.chain.ChainQueryApi
|
||||
import org.bitcoins.core.api.node.NodeApi
|
||||
import org.bitcoins.core.currency.CurrencyUnit
|
||||
import org.bitcoins.core.hd.HDAccount
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.transaction.TransactionOutput
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
import org.bitcoins.testkit.wallet.FundWalletUtil.FundedWallet
|
||||
import org.bitcoins.testkitcore.util.TransactionTestUtil
|
||||
import org.bitcoins.wallet.Wallet
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
@ -129,7 +129,7 @@ object FundWalletUtil extends FundWalletUtil {
|
||||
chainQueryApi: ChainQueryApi,
|
||||
bip39PasswordOpt: Option[String],
|
||||
extraConfig: Option[Config] = None)(implicit
|
||||
config: BitcoinSAppConfig,
|
||||
config: WalletAppConfig,
|
||||
system: ActorSystem): Future[FundedWallet] = {
|
||||
|
||||
import system.dispatcher
|
||||
|
@ -0,0 +1,13 @@
|
||||
package org.bitcoins.testkit.wallet
|
||||
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.wallet.config.WalletAppConfig
|
||||
|
||||
sealed trait WalletAppConfigWithBitcoind {
|
||||
def bitcoind: BitcoindRpcClient
|
||||
def walletAppConfig: WalletAppConfig
|
||||
}
|
||||
|
||||
case class WalletAppConfigWithBitcoindRpc(
|
||||
walletAppConfig: WalletAppConfig,
|
||||
bitcoind: BitcoindRpcClient)
|
@ -0,0 +1,63 @@
|
||||
package org.bitcoins.testkit.wallet
|
||||
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.testkit.EmbeddedPg
|
||||
import org.bitcoins.testkit.rpc.{
|
||||
BitcoindFixturesCached,
|
||||
CachedBitcoind,
|
||||
CachedBitcoindNewest
|
||||
}
|
||||
import org.bitcoins.testkit.util.BitcoinSAsyncFixtureTest
|
||||
import org.scalatest.{FutureOutcome, Outcome}
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
trait WalletAppConfigWithBitcoindFixtures
|
||||
extends BitcoinSAsyncFixtureTest
|
||||
with BitcoindFixturesCached
|
||||
with EmbeddedPg { _: CachedBitcoind[_] =>
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[BitcoinSAsyncFixtureTest].afterAll()
|
||||
}
|
||||
}
|
||||
|
||||
trait WalletAppConfigWithBitcoindNewestFixtures
|
||||
extends WalletAppConfigWithBitcoindFixtures
|
||||
with CachedBitcoindNewest {
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[CachedBitcoindNewest].afterAll()
|
||||
super[WalletAppConfigWithBitcoindFixtures].afterAll()
|
||||
}
|
||||
|
||||
override type FixtureParam = WalletAppConfigWithBitcoindRpc
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withWalletAppConfigBitcoindCached(test, bitcoind)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
}
|
||||
|
||||
def withWalletAppConfigBitcoindCached(
|
||||
test: OneArgAsyncTest,
|
||||
bitcoind: BitcoindRpcClient): FutureOutcome = {
|
||||
makeDependentFixture[WalletAppConfigWithBitcoindRpc](
|
||||
() => {
|
||||
val walletConfig =
|
||||
BaseWalletTest.getFreshWalletAppConfig(pgUrl, Vector.empty)
|
||||
val model = WalletAppConfigWithBitcoindRpc(walletConfig, bitcoind)
|
||||
Future.successful(model)
|
||||
},
|
||||
{ case walletAppConfigWithBitcoindRpc =>
|
||||
BitcoinSWalletTest.destroyWalletAppConfig(
|
||||
walletAppConfigWithBitcoindRpc.walletAppConfig)
|
||||
}
|
||||
)(test)
|
||||
}
|
||||
}
|
||||
|
||||
object WalletAppConfigWithBitcoindFixtures {}
|
@ -21,7 +21,7 @@ class AddressHandlingTest extends BitcoinSWalletTest {
|
||||
type FixtureParam = FundedWallet
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
withFundedWallet(test, getBIP39PasswordOpt())
|
||||
withFundedWallet(test, getBIP39PasswordOpt())(getFreshWalletAppConfig)
|
||||
}
|
||||
|
||||
behavior of "AddressHandling"
|
||||
|
@ -18,7 +18,7 @@ class AddressTagIntegrationTest extends BitcoinSWalletTest {
|
||||
override type FixtureParam = WalletWithBitcoind
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||
withNewWalletAndBitcoind(test)
|
||||
withNewWalletAndBitcoind(test)(getFreshWalletAppConfig)
|
||||
|
||||
behavior of "Address Tag - integration test"
|
||||
|
||||
|
@ -2,43 +2,18 @@ package org.bitcoins.wallet
|
||||
|
||||
import org.bitcoins.commons.jsonmodels.wallet.SyncHeightDescriptor
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.db.AppConfig
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.server.{BitcoinSAppConfig, BitcoindRpcBackendUtil}
|
||||
import org.bitcoins.testkit.rpc.{
|
||||
BitcoindFixturesFundedCached,
|
||||
CachedBitcoindNewest
|
||||
import org.bitcoins.server.BitcoindRpcBackendUtil
|
||||
import org.bitcoins.testkit.wallet.{
|
||||
BitcoinSWalletTest,
|
||||
WalletAppConfigWithBitcoindNewestFixtures
|
||||
}
|
||||
import org.bitcoins.testkit.util.BitcoinSAsyncFixtureTest
|
||||
import org.bitcoins.testkit.wallet.BitcoinSWalletTest
|
||||
import org.bitcoins.testkit.{BitcoinSTestAppConfig, EmbeddedPg}
|
||||
|
||||
class BitcoindBackendTest
|
||||
extends BitcoinSAsyncFixtureTest
|
||||
with BitcoindFixturesFundedCached
|
||||
with CachedBitcoindNewest
|
||||
with EmbeddedPg {
|
||||
class BitcoindBackendTest extends WalletAppConfigWithBitcoindNewestFixtures {
|
||||
|
||||
override type FixtureParam = BitcoindRpcClient
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
|
||||
implicit protected def config: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
AppConfig.throwIfDefaultDatadir(config.walletConf)
|
||||
super[EmbeddedPg].beforeAll()
|
||||
}
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[CachedBitcoindNewest].afterAll()
|
||||
super[EmbeddedPg].afterAll()
|
||||
}
|
||||
|
||||
it must "correctly catch up to bitcoind" in { bitcoind =>
|
||||
it must "correctly catch up to bitcoind" in { walletAppConfigWithBitcoind =>
|
||||
val bitcoind = walletAppConfigWithBitcoind.bitcoind
|
||||
implicit val walletAppConfig = walletAppConfigWithBitcoind.walletAppConfig
|
||||
val amountToSend = Bitcoins.one
|
||||
|
||||
for {
|
||||
header <- bitcoind.getBestBlockHeader()
|
||||
|
||||
|
@ -2,77 +2,57 @@ package org.bitcoins.wallet
|
||||
|
||||
import org.bitcoins.asyncutil.AsyncUtil
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.db.AppConfig
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.server.{BitcoinSAppConfig, BitcoindRpcBackendUtil}
|
||||
import org.bitcoins.testkit.rpc.{
|
||||
BitcoindFixturesFundedCached,
|
||||
CachedBitcoindNewest
|
||||
import org.bitcoins.server.BitcoindRpcBackendUtil
|
||||
import org.bitcoins.testkit.wallet.{
|
||||
BitcoinSWalletTest,
|
||||
WalletAppConfigWithBitcoindNewestFixtures
|
||||
}
|
||||
import org.bitcoins.testkit.util.BitcoinSAsyncFixtureTest
|
||||
import org.bitcoins.testkit.wallet.BitcoinSWalletTest
|
||||
import org.bitcoins.testkit.{BitcoinSTestAppConfig, EmbeddedPg}
|
||||
|
||||
import scala.concurrent.duration.DurationInt
|
||||
|
||||
class BitcoindBlockPollingTest
|
||||
extends BitcoinSAsyncFixtureTest
|
||||
with BitcoindFixturesFundedCached
|
||||
with CachedBitcoindNewest
|
||||
with EmbeddedPg {
|
||||
extends WalletAppConfigWithBitcoindNewestFixtures {
|
||||
|
||||
override type FixtureParam = BitcoindRpcClient
|
||||
it must "properly setup and poll blocks from bitcoind" in {
|
||||
walletAppConfigWithBitcoind =>
|
||||
val bitcoind = walletAppConfigWithBitcoind.bitcoind
|
||||
implicit val walletAppConfig = walletAppConfigWithBitcoind.walletAppConfig
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
implicit protected def config: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
||||
val amountToSend = Bitcoins.one
|
||||
|
||||
override def beforeAll(): Unit = {
|
||||
AppConfig.throwIfDefaultDatadir(config.walletConf)
|
||||
super[EmbeddedPg].beforeAll()
|
||||
}
|
||||
for {
|
||||
// Setup wallet
|
||||
tmpWallet <-
|
||||
BitcoinSWalletTest.createDefaultWallet(bitcoind, bitcoind, None)
|
||||
wallet =
|
||||
BitcoindRpcBackendUtil.createWalletWithBitcoindCallbacks(bitcoind,
|
||||
tmpWallet)
|
||||
// Assert wallet is empty
|
||||
isEmpty <- wallet.isEmpty()
|
||||
_ = assert(isEmpty)
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
super[CachedBitcoindNewest].afterAll()
|
||||
super[EmbeddedPg].afterAll()
|
||||
}
|
||||
// Send to wallet
|
||||
addr <- wallet.getNewAddress()
|
||||
_ <- bitcoind.sendToAddress(addr, amountToSend)
|
||||
|
||||
it must "properly setup and poll blocks from bitcoind" in { bitcoind =>
|
||||
val amountToSend = Bitcoins.one
|
||||
// assert wallet hasn't seen it yet
|
||||
firstBalance <- wallet.getBalance()
|
||||
_ = assert(firstBalance == Satoshis.zero)
|
||||
|
||||
for {
|
||||
// Setup wallet
|
||||
tmpWallet <-
|
||||
BitcoinSWalletTest.createDefaultWallet(bitcoind, bitcoind, None)
|
||||
wallet =
|
||||
BitcoindRpcBackendUtil.createWalletWithBitcoindCallbacks(bitcoind,
|
||||
tmpWallet)
|
||||
// Assert wallet is empty
|
||||
isEmpty <- wallet.isEmpty()
|
||||
_ = assert(isEmpty)
|
||||
// Setup block polling
|
||||
_ = BitcoindRpcBackendUtil.startBitcoindBlockPolling(wallet,
|
||||
bitcoind,
|
||||
1.second)
|
||||
_ <- bitcoind.generateToAddress(6, addr)
|
||||
|
||||
// Send to wallet
|
||||
addr <- wallet.getNewAddress()
|
||||
_ <- bitcoind.sendToAddress(addr, amountToSend)
|
||||
// Wait for it to process
|
||||
_ <- AsyncUtil.awaitConditionF(
|
||||
() => wallet.getBalance().map(_ > Satoshis.zero),
|
||||
1.second)
|
||||
|
||||
// assert wallet hasn't seen it yet
|
||||
firstBalance <- wallet.getBalance()
|
||||
_ = assert(firstBalance == Satoshis.zero)
|
||||
|
||||
// Setup block polling
|
||||
_ = BitcoindRpcBackendUtil.startBitcoindBlockPolling(wallet,
|
||||
bitcoind,
|
||||
1.second)
|
||||
_ <- bitcoind.generateToAddress(6, addr)
|
||||
|
||||
// Wait for it to process
|
||||
_ <- AsyncUtil.awaitConditionF(
|
||||
() => wallet.getBalance().map(_ > Satoshis.zero),
|
||||
1.second)
|
||||
|
||||
balance <- wallet.getBalance()
|
||||
//clean up
|
||||
_ <- wallet.walletConfig.stop()
|
||||
} yield assert(balance == amountToSend)
|
||||
balance <- wallet.getBalance()
|
||||
//clean up
|
||||
_ <- wallet.walletConfig.stop()
|
||||
} yield assert(balance == amountToSend)
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,10 @@ class FundTransactionHandlingTest
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withFundedWalletAndBitcoindCached(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withFundedWalletAndBitcoindCached(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -7,6 +7,9 @@ import org.bitcoins.testkit.util.BitcoinSAsyncTest
|
||||
import org.bitcoins.testkit.wallet.BitcoinSWalletTest
|
||||
import org.bitcoins.testkit.wallet.BitcoinSWalletTest._
|
||||
import org.bitcoins.testkit.{BitcoinSTestAppConfig, EmbeddedPg}
|
||||
import org.scalatest.Assertion
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
class MultiWalletTest extends BitcoinSAsyncTest with EmbeddedPg {
|
||||
|
||||
@ -24,18 +27,26 @@ class MultiWalletTest extends BitcoinSAsyncTest with EmbeddedPg {
|
||||
val configA = BitcoinSAppConfig(dir, walletNameConfA.withFallback(dbConf))
|
||||
val configB = BitcoinSAppConfig(dir, walletNameConfB.withFallback(dbConf))
|
||||
|
||||
for {
|
||||
walletA <- BitcoinSWalletTest.createDefaultWallet(
|
||||
MockNodeApi,
|
||||
MockChainQueryApi,
|
||||
bip39PasswordOpt)(configA, system.dispatcher)
|
||||
val walletAF = BitcoinSWalletTest.createDefaultWallet(
|
||||
MockNodeApi,
|
||||
MockChainQueryApi,
|
||||
bip39PasswordOpt)(configA, system.dispatcher)
|
||||
|
||||
val walletBF = BitcoinSWalletTest.createDefaultWallet(
|
||||
MockNodeApi,
|
||||
MockChainQueryApi,
|
||||
bip39PasswordOpt)(configB, system.dispatcher)
|
||||
|
||||
val assertionF: Future[Assertion] = for {
|
||||
walletA <- walletAF
|
||||
accountA <- walletA.getDefaultAccount()
|
||||
|
||||
walletB <- BitcoinSWalletTest.createDefaultWallet(
|
||||
MockNodeApi,
|
||||
MockChainQueryApi,
|
||||
bip39PasswordOpt)(configB, system.dispatcher)
|
||||
walletB <- walletBF
|
||||
accountB <- walletB.getDefaultAccount()
|
||||
_ <- walletA.walletConfig.stop()
|
||||
_ <- walletB.walletConfig.stop()
|
||||
} yield assert(accountA.xpub != accountB.xpub)
|
||||
|
||||
assertionF
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,10 @@ class ProcessBlockTest extends BitcoinSWalletTestCachedBitcoinV19 {
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withNewWalletAndBitcoindCachedV19(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withNewWalletAndBitcoindCachedV19(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -14,7 +14,7 @@ class ProcessTransactionTest extends BitcoinSWalletTest {
|
||||
override type FixtureParam = WalletApi
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
withNewWallet(test, getBIP39PasswordOpt())
|
||||
withNewWallet(test, getBIP39PasswordOpt())(getFreshWalletAppConfig)
|
||||
}
|
||||
|
||||
behavior of "Wallet.processTransaction"
|
||||
|
@ -17,7 +17,7 @@ import scala.concurrent.Future
|
||||
class RescanHandlingTest extends BitcoinSWalletTestCachedBitcoinV19 {
|
||||
|
||||
/** Wallet config with data directory set to user temp directory */
|
||||
implicit override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
override protected def getFreshConfig: BitcoinSAppConfig =
|
||||
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl)
|
||||
|
||||
override type FixtureParam = WalletWithBitcoind
|
||||
|
@ -241,7 +241,7 @@ class TrezorAddressTest extends BitcoinSWalletTest with EmptyFixture {
|
||||
case other => fail(s"unknown purpose: $other")
|
||||
}
|
||||
|
||||
for {
|
||||
val assertionsF: Future[Seq[Assertion]] = for {
|
||||
wallet <- getWallet(conf)
|
||||
existingAccounts <- wallet.listAccounts(purpose)
|
||||
_ <- createNeededAccounts(wallet,
|
||||
@ -290,9 +290,11 @@ class TrezorAddressTest extends BitcoinSWalletTest with EmptyFixture {
|
||||
}
|
||||
nestedAssertions.flatten
|
||||
}
|
||||
assertions
|
||||
}
|
||||
|
||||
wallet.stop()
|
||||
assert(assertions.forall(_.isCompleted))
|
||||
assertionsF.flatMap { _ =>
|
||||
conf.stop().map(_ => succeed)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class UTXOHandlingTest extends BitcoinSWalletTest {
|
||||
override type FixtureParam = Wallet
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
withNewWallet(test, getBIP39PasswordOpt())
|
||||
withNewWallet(test, getBIP39PasswordOpt())(getFreshWalletAppConfig)
|
||||
}
|
||||
|
||||
it must "correctly update txo state based on confirmations" in { wallet =>
|
||||
|
@ -28,9 +28,10 @@ class UTXOLifeCycleTest extends BitcoinSWalletTestCachedBitcoindNewest {
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withFundedWalletAndBitcoindCached(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withFundedWalletAndBitcoindCached(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -19,9 +19,10 @@ class WalletBloomTest extends BitcoinSWalletTestCachedBitcoindNewest {
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withFundedWalletAndBitcoindCached(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withFundedWalletAndBitcoindCached(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -13,7 +13,7 @@ class WalletCallbackTest extends BitcoinSWalletTest {
|
||||
type FixtureParam = FundedWallet
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
withFundedWallet(test, getBIP39PasswordOpt())
|
||||
withFundedWallet(test, getBIP39PasswordOpt())(getFreshWalletAppConfig)
|
||||
}
|
||||
|
||||
behavior of "WalletCallbacks"
|
||||
|
@ -27,9 +27,10 @@ class WalletIntegrationTest extends BitcoinSWalletTestCachedBitcoindNewest {
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val f: Future[Outcome] = for {
|
||||
bitcoind <- cachedBitcoindWithFundsF
|
||||
futOutcome = withNewWalletAndBitcoindCached(test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)
|
||||
futOutcome = withNewWalletAndBitcoindCached(
|
||||
test,
|
||||
getBIP39PasswordOpt(),
|
||||
bitcoind)(getFreshWalletAppConfig)
|
||||
fut <- futOutcome.toFuture
|
||||
} yield fut
|
||||
new FutureOutcome(f)
|
||||
|
@ -33,7 +33,7 @@ class WalletSendingTest extends BitcoinSWalletTest {
|
||||
override type FixtureParam = FundedWallet
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||
withFundedWallet(test, getBIP39PasswordOpt())
|
||||
withFundedWallet(test, getBIP39PasswordOpt())(getFreshWalletAppConfig)
|
||||
|
||||
behavior of "Wallet"
|
||||
|
||||
|
@ -24,7 +24,7 @@ class WalletUnitTest extends BitcoinSWalletTest {
|
||||
override type FixtureParam = Wallet
|
||||
|
||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||
withNewWallet(test, bip39PasswordOpt)
|
||||
withNewWallet(test, bip39PasswordOpt)(getFreshWalletAppConfig)
|
||||
|
||||
behavior of "Wallet - unit test"
|
||||
|
||||
@ -163,9 +163,13 @@ class WalletUnitTest extends BitcoinSWalletTest {
|
||||
|
||||
it must "be able to call initialize twice without throwing an exception if we have the same key manager" in {
|
||||
wallet: Wallet =>
|
||||
val twiceF = Wallet.initialize(wallet, bip39PasswordOpt).flatMap { _ =>
|
||||
Wallet.initialize(wallet, bip39PasswordOpt)
|
||||
}
|
||||
val twiceF = Wallet
|
||||
.initialize(wallet, bip39PasswordOpt)(wallet.walletConfig,
|
||||
executionContext)
|
||||
.flatMap { _ =>
|
||||
Wallet.initialize(wallet, bip39PasswordOpt)(wallet.walletConfig,
|
||||
executionContext)
|
||||
}
|
||||
|
||||
twiceF.map(_ => succeed)
|
||||
|
||||
@ -174,12 +178,17 @@ class WalletUnitTest extends BitcoinSWalletTest {
|
||||
it must "be able to detect an incompatible key manager with a wallet" in {
|
||||
wallet: Wallet =>
|
||||
recoverToSucceededIf[RuntimeException] {
|
||||
Wallet.initialize(wallet, bip39PasswordOpt).flatMap { _ =>
|
||||
//use a BIP39 password to make the key-managers different
|
||||
Wallet.initialize(
|
||||
wallet,
|
||||
Some("random-password-to-make-key-managers-different"))
|
||||
}
|
||||
Wallet
|
||||
.initialize(wallet, bip39PasswordOpt)(wallet.walletConfig,
|
||||
executionContext)
|
||||
.flatMap { _ =>
|
||||
//use a BIP39 password to make the key-managers different
|
||||
Wallet.initialize(
|
||||
wallet,
|
||||
Some("random-password-to-make-key-managers-different"))(
|
||||
wallet.walletConfig,
|
||||
executionContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user