diff --git a/docs/wallet/wallet-rescan.md b/docs/wallet/wallet-rescan.md index 62f9a41fd5..4f9c685b3c 100644 --- a/docs/wallet/wallet-rescan.md +++ b/docs/wallet/wallet-rescan.md @@ -32,10 +32,11 @@ implicit val system: ActorSystem = ActorSystem(s"wallet-rescan-example") implicit val ec: ExecutionContext = system.dispatcher implicit val appConfig: BitcoinSAppConfig = BitcoinSTestAppConfig.getNeutrinoTestConfig() +val bip39PasswordOpt = None //ok now let's spin up a bitcoind and a bitcoin-s wallet with funds in it val walletWithBitcoindF = for { bitcoind <- BitcoinSFixture.createBitcoindWithFunds() - walletWithBitcoind <- BitcoinSWalletTest.createWalletWithBitcoindCallbacks(bitcoind) + walletWithBitcoind <- BitcoinSWalletTest.createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt) } yield walletWithBitcoind val walletF = walletWithBitcoindF.map(_.wallet) diff --git a/node-test/src/test/scala/org/bitcoins/node/BroadcastTransactionTest.scala b/node-test/src/test/scala/org/bitcoins/node/BroadcastTransactionTest.scala index 49eec0809d..4b4dcb1e0b 100644 --- a/node-test/src/test/scala/org/bitcoins/node/BroadcastTransactionTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/BroadcastTransactionTest.scala @@ -7,8 +7,11 @@ import org.bitcoins.rpc.BitcoindException import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig import org.bitcoins.testkit.async.TestAsyncUtil -import org.bitcoins.testkit.node.NodeUnitTest.SpvNodeFundedWalletBitcoind -import org.bitcoins.testkit.node.{NodeTestUtil, NodeUnitTest} +import org.bitcoins.testkit.node.{ + NodeTestUtil, + NodeUnitTest, + SpvNodeFundedWalletBitcoind +} import org.scalatest.FutureOutcome import scala.concurrent.Future @@ -23,7 +26,9 @@ class BroadcastTransactionTest extends NodeUnitTest { override type FixtureParam = SpvNodeFundedWalletBitcoind def withFixture(test: OneArgAsyncTest): FutureOutcome = - withSpvNodeFundedWalletBitcoind(test, NodeCallbacks.empty) + withSpvNodeFundedWalletBitcoind(test, + NodeCallbacks.empty, + getBIP39PasswordOpt()) private val sendAmount = 1.bitcoin @@ -31,7 +36,7 @@ class BroadcastTransactionTest extends NodeUnitTest { BitcoinAddress("2NFyxovf6MyxfHqtVjstGzs6HeLqv92Nq4U") it must "broadcast a transaction" in { param => - val SpvNodeFundedWalletBitcoind(node, wallet, rpc) = param + val SpvNodeFundedWalletBitcoind(node, wallet, rpc, _) = param def hasSeenTx(transaction: Transaction): Future[Boolean] = { rpc 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 98c7f086fe..0e7c1731c7 100644 --- a/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeTest.scala @@ -8,8 +8,11 @@ import org.bitcoins.rpc.util.RpcUtil import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig import org.bitcoins.testkit.fixtures.UsesExperimentalBitcoind -import org.bitcoins.testkit.node.NodeUnitTest.NeutrinoNodeFundedWalletBitcoind -import org.bitcoins.testkit.node.{NodeTestUtil, NodeUnitTest} +import org.bitcoins.testkit.node.{ + NeutrinoNodeFundedWalletBitcoind, + NodeTestUtil, + NodeUnitTest +} import org.scalatest.{DoNotDiscover, FutureOutcome} import scala.concurrent.duration.DurationInt @@ -27,6 +30,7 @@ class NeutrinoNodeTest extends NodeUnitTest { override def withFixture(test: OneArgAsyncTest): FutureOutcome = withNeutrinoNodeFundedWalletBitcoind(test, callbacks, + getBIP39PasswordOpt(), Some(BitcoindVersion.Experimental)) private val testTimeout = 30.seconds diff --git a/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeWithWalletTest.scala b/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeWithWalletTest.scala index 9312f8bd27..2341bd599c 100644 --- a/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeWithWalletTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/NeutrinoNodeWithWalletTest.scala @@ -8,8 +8,11 @@ import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig import org.bitcoins.testkit.fixtures.UsesExperimentalBitcoind -import org.bitcoins.testkit.node.NodeUnitTest.NeutrinoNodeFundedWalletBitcoind -import org.bitcoins.testkit.node.{NodeTestUtil, NodeUnitTest} +import org.bitcoins.testkit.node.{ + NeutrinoNodeFundedWalletBitcoind, + NodeTestUtil, + NodeUnitTest +} import org.bitcoins.testkit.wallet.BitcoinSWalletTest import org.bitcoins.wallet.api.WalletApi import org.scalatest.FutureOutcome @@ -31,9 +34,11 @@ class NeutrinoNodeWithWalletTest extends NodeUnitTest { if (EnvUtil.isCI && !EnvUtil.isLinux) { FutureOutcome.succeeded } else { - withNeutrinoNodeFundedWalletBitcoind(test, - callbacks, - Some(BitcoindVersion.Experimental)) + withNeutrinoNodeFundedWalletBitcoind( + test = test, + callbacks = callbacks, + bip39PasswordOpt = getBIP39PasswordOpt(), + versionOpt = Some(BitcoindVersion.Experimental)) } } @@ -74,7 +79,7 @@ class NeutrinoNodeWithWalletTest extends NodeUnitTest { it must "receive information about received payments" taggedAs (UsesExperimentalBitcoind) in { param => - val NeutrinoNodeFundedWalletBitcoind(node, wallet, bitcoind) = param + val NeutrinoNodeFundedWalletBitcoind(node, wallet, bitcoind, _) = param walletP.success(wallet) @@ -145,7 +150,7 @@ class NeutrinoNodeWithWalletTest extends NodeUnitTest { it must "rescan and receive information about received payments" taggedAs (UsesExperimentalBitcoind) in { param => - val NeutrinoNodeFundedWalletBitcoind(node, wallet, bitcoind) = param + val NeutrinoNodeFundedWalletBitcoind(node, wallet, bitcoind, _) = param walletP.success(wallet) diff --git a/node-test/src/test/scala/org/bitcoins/node/SpvNodeWithWalletTest.scala b/node-test/src/test/scala/org/bitcoins/node/SpvNodeWithWalletTest.scala index 7b4dc8e13b..e8f6848bc7 100644 --- a/node-test/src/test/scala/org/bitcoins/node/SpvNodeWithWalletTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/SpvNodeWithWalletTest.scala @@ -5,8 +5,11 @@ import org.bitcoins.core.currency._ import org.bitcoins.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig -import org.bitcoins.testkit.node.NodeUnitTest.SpvNodeFundedWalletBitcoind -import org.bitcoins.testkit.node.{NodeTestUtil, NodeUnitTest} +import org.bitcoins.testkit.node.{ + NodeTestUtil, + NodeUnitTest, + SpvNodeFundedWalletBitcoind +} import org.bitcoins.wallet.api.WalletApi import org.scalatest.FutureOutcome import org.scalatest.exceptions.TestFailedException @@ -23,7 +26,7 @@ class SpvNodeWithWalletTest extends NodeUnitTest { override type FixtureParam = SpvNodeFundedWalletBitcoind def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withSpvNodeFundedWalletBitcoind(test, callbacks) + withSpvNodeFundedWalletBitcoind(test, callbacks, getBIP39PasswordOpt()) } private val assertionP: Promise[Boolean] = Promise() @@ -61,7 +64,7 @@ class SpvNodeWithWalletTest extends NodeUnitTest { it must "load a bloom filter and receive information about received payments" in { param => - val SpvNodeFundedWalletBitcoind(spv, wallet, rpc) = param + val SpvNodeFundedWalletBitcoind(spv, wallet, rpc, _) = param walletP.success(wallet) diff --git a/node-test/src/test/scala/org/bitcoins/node/UpdateBloomFilterTest.scala b/node-test/src/test/scala/org/bitcoins/node/UpdateBloomFilterTest.scala index 2ffa155694..f508158b02 100644 --- a/node-test/src/test/scala/org/bitcoins/node/UpdateBloomFilterTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/UpdateBloomFilterTest.scala @@ -10,8 +10,11 @@ import org.bitcoins.node.networking.peer.DataMessageHandler import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig -import org.bitcoins.testkit.node.NodeUnitTest.SpvNodeFundedWalletBitcoind -import org.bitcoins.testkit.node.{NodeTestUtil, NodeUnitTest} +import org.bitcoins.testkit.node.{ + NodeTestUtil, + NodeUnitTest, + SpvNodeFundedWalletBitcoind +} import org.scalatest.exceptions.TestFailedException import org.scalatest.{BeforeAndAfter, FutureOutcome} @@ -27,7 +30,7 @@ class UpdateBloomFilterTest extends NodeUnitTest with BeforeAndAfter { override type FixtureParam = SpvNodeFundedWalletBitcoind def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withSpvNodeFundedWalletBitcoind(test, callbacks) + withSpvNodeFundedWalletBitcoind(test, callbacks, getBIP39PasswordOpt()) } val testTimeout = 30.seconds @@ -82,7 +85,7 @@ class UpdateBloomFilterTest extends NodeUnitTest with BeforeAndAfter { } it must "update the bloom filter with a TX" in { param => - val SpvNodeFundedWalletBitcoind(spv, wallet, rpc) = param + val SpvNodeFundedWalletBitcoind(spv, wallet, rpc, _) = param // we want to schedule a runnable that aborts // the test after a timeout, but then @@ -132,7 +135,7 @@ class UpdateBloomFilterTest extends NodeUnitTest with BeforeAndAfter { } it must "update the bloom filter with an address" in { param => - val SpvNodeFundedWalletBitcoind(spv, wallet, rpc) = param + val SpvNodeFundedWalletBitcoind(spv, wallet, rpc, _) = param // we want to schedule a runnable that aborts // the test after a timeout, but then diff --git a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeFundedWalletBitcoind.scala b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeFundedWalletBitcoind.scala new file mode 100644 index 0000000000..8ab0e1aa6f --- /dev/null +++ b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeFundedWalletBitcoind.scala @@ -0,0 +1,31 @@ +package org.bitcoins.testkit.node + +import org.bitcoins.node.{NeutrinoNode, Node, SpvNode} +import org.bitcoins.rpc.client.common.BitcoindRpcClient +import org.bitcoins.wallet.Wallet + +/** + * Creates + * 1. a funded bitcoind wallet + * 2. a funded bitcoin-s wallet + * 3. a chain handler with the appropriate tables created + * 4. a spv node that is connected to the bitcoin instance -- but not started! */ +trait NodeFundedWalletBitcoind { + def node: Node + def wallet: Wallet + def bitcoindRpc: BitcoindRpcClient + def bip39PasswordOpt: Option[String] +} +case class SpvNodeFundedWalletBitcoind( + node: SpvNode, + wallet: Wallet, + bitcoindRpc: BitcoindRpcClient, + bip39PasswordOpt: Option[String]) + extends NodeFundedWalletBitcoind +case class NeutrinoNodeFundedWalletBitcoind( + node: NeutrinoNode, + wallet: Wallet, + bitcoindRpc: BitcoindRpcClient, + bip39PasswordOpt: Option[String]) + extends NodeFundedWalletBitcoind + 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 1d0f3a7eb8..44589a8692 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala @@ -10,12 +10,7 @@ import org.bitcoins.db.AppConfig import org.bitcoins.node._ import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.node.models.Peer -import org.bitcoins.node.networking.peer.{ - PeerHandler, - PeerMessageReceiver, - PeerMessageReceiverState, - PeerMessageSender -} +import org.bitcoins.node.networking.peer.{PeerHandler, PeerMessageReceiver, PeerMessageReceiverState, PeerMessageSender} import org.bitcoins.rpc.client.common.BitcoindVersion.V18 import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} import org.bitcoins.server.BitcoinSAppConfig @@ -23,15 +18,10 @@ import org.bitcoins.server.BitcoinSAppConfig._ import org.bitcoins.testkit.EmbeddedPg import org.bitcoins.testkit.chain.ChainUnitTest import org.bitcoins.testkit.fixtures.BitcoinSFixture -import org.bitcoins.testkit.node.NodeUnitTest.NodeFundedWalletBitcoind -import org.bitcoins.testkit.node.fixture.{ - NeutrinoNodeConnectedWithBitcoind, - NodeConnectedWithBitcoind, - SpvNodeConnectedWithBitcoind -} +import org.bitcoins.testkit.keymanager.KeyManagerTestUtil +import org.bitcoins.testkit.node.fixture.{NeutrinoNodeConnectedWithBitcoind, NodeConnectedWithBitcoind, SpvNodeConnectedWithBitcoind} import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil -import org.bitcoins.testkit.wallet.BitcoinSWalletTest -import org.bitcoins.wallet.Wallet +import org.bitcoins.testkit.wallet.{BitcoinSWalletTest, WalletWithBitcoindRpc} import org.scalatest.FutureOutcome import scala.concurrent.duration._ @@ -110,13 +100,16 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg { def withSpvNodeFundedWalletBitcoind( test: OneArgAsyncTest, - callbacks: NodeCallbacks)( + callbacks: NodeCallbacks, + bip39PasswordOpt: Option[String])( implicit system: ActorSystem, appConfig: BitcoinSAppConfig): FutureOutcome = { makeDependentFixture( build = () => - NodeUnitTest.createSpvNodeFundedWalletBitcoind(callbacks, Option(V18))( + NodeUnitTest.createSpvNodeFundedWalletBitcoind(callbacks = callbacks, + bip39PasswordOpt = bip39PasswordOpt, + versionOpt = Option(V18))( system, // Force V18 because Spv is disabled on versions after appConfig), destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind( @@ -127,6 +120,7 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg { def withNeutrinoNodeFundedWalletBitcoind( test: OneArgAsyncTest, callbacks: NodeCallbacks, + bip39PasswordOpt: Option[String], versionOpt: Option[BitcoindVersion] = None)( implicit system: ActorSystem, appConfig: BitcoinSAppConfig): FutureOutcome = { @@ -134,7 +128,7 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg { makeDependentFixture( build = () => NodeUnitTest - .createNeutrinoNodeFundedWalletBitcoind(callbacks, versionOpt)( + .createNeutrinoNodeFundedWalletBitcoind(callbacks, bip39PasswordOpt, versionOpt)( system, appConfig), destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind( @@ -162,32 +156,12 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg { system.scheduler.scheduleAtFixedRate(2.second, interval)(genBlock) () } + + def getBIP39PasswordOpt(): Option[String] = KeyManagerTestUtil.bip39PasswordOpt } object NodeUnitTest extends P2PLogger { - /** - * Creates - * 1. a funded bitcoind wallet - * 2. a funded bitcoin-s wallet - * 3. a chain handler with the appropriate tables created - * 4. a spv node that is connected to the bitcoin instance -- but not started! */ - trait NodeFundedWalletBitcoind { - def node: Node - def wallet: Wallet - def bitcoindRpc: BitcoindRpcClient - } - case class SpvNodeFundedWalletBitcoind( - node: SpvNode, - wallet: Wallet, - bitcoindRpc: BitcoindRpcClient) - extends NodeFundedWalletBitcoind - case class NeutrinoNodeFundedWalletBitcoind( - node: NeutrinoNode, - wallet: Wallet, - bitcoindRpc: BitcoindRpcClient) - extends NodeFundedWalletBitcoind - def buildPeerMessageReceiver(chainApi: ChainApi, peer: Peer)( implicit appConfig: BitcoinSAppConfig, system: ActorSystem): Future[PeerMessageReceiver] = { @@ -252,6 +226,7 @@ object NodeUnitTest extends P2PLogger { /** Creates a spv node, a funded bitcoin-s wallet, all of which are connected to bitcoind */ def createSpvNodeFundedWalletBitcoind( callbacks: NodeCallbacks, + bip39PasswordOpt: Option[String], versionOpt: Option[BitcoindVersion] = None)( implicit system: ActorSystem, appConfig: BitcoinSAppConfig): Future[SpvNodeFundedWalletBitcoind] = { @@ -262,17 +237,20 @@ object NodeUnitTest extends P2PLogger { node <- createSpvNode(bitcoind, callbacks) fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(bitcoind, node, - node) + node, + bip39PasswordOpt) } yield { SpvNodeFundedWalletBitcoind(node = node, wallet = fundedWallet.wallet, - bitcoindRpc = fundedWallet.bitcoind) + bitcoindRpc = fundedWallet.bitcoind, + bip39PasswordOpt) } } /** Creates a neutrino node, a funded bitcoin-s wallet, all of which are connected to bitcoind */ def createNeutrinoNodeFundedWalletBitcoind( callbacks: NodeCallbacks, + bip39PasswordOpt: Option[String], versionOpt: Option[BitcoindVersion])( implicit system: ActorSystem, appConfig: BitcoinSAppConfig): Future[NeutrinoNodeFundedWalletBitcoind] = { @@ -281,13 +259,15 @@ object NodeUnitTest extends P2PLogger { for { bitcoind <- BitcoinSFixture.createBitcoindWithFunds(versionOpt) node <- createNeutrinoNode(bitcoind, callbacks) - fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(bitcoind, - node, - node) + fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(bitcoindRpcClient = bitcoind, + nodeApi = node, + chainQueryApi = node, + bip39PasswordOpt = bip39PasswordOpt) } yield { NeutrinoNodeFundedWalletBitcoind(node = node, wallet = fundedWallet.wallet, - bitcoindRpc = fundedWallet.bitcoind) + bitcoindRpc = fundedWallet.bitcoind, + bip39PasswordOpt = bip39PasswordOpt) } } @@ -297,7 +277,7 @@ object NodeUnitTest extends P2PLogger { appConfig: BitcoinSAppConfig): Future[Unit] = { import system.dispatcher val walletWithBitcoind = { - BitcoinSWalletTest.WalletWithBitcoindRpc(fundedWalletBitcoind.wallet, + WalletWithBitcoindRpc(fundedWalletBitcoind.wallet, fundedWalletBitcoind.bitcoindRpc) } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala index ba0e2a3b99..b41f0da96e 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala @@ -157,20 +157,21 @@ trait BitcoinSWalletTest /** Creates a wallet that is funded with some bitcoin, this wallet is NOT * peered with a bitcoind so the funds in the wallet are not tied to an * underlying blockchain */ - def withFundedWallet(test: OneArgAsyncTest): FutureOutcome = { + def withFundedWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { makeDependentFixture( - build = () => FundWalletUtil.createFundedWallet(nodeApi, chainQueryApi), + build = () => FundWalletUtil.createFundedWallet(nodeApi, chainQueryApi, bip39PasswordOpt), destroy = { funded: FundedWallet => destroyWallet(funded.wallet) } )(test) } - def withFundedSegwitWallet(test: OneArgAsyncTest): FutureOutcome = { + def withFundedSegwitWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { makeDependentFixture( build = () => FundWalletUtil.createFundedWallet(nodeApi, chainQueryApi, + bip39PasswordOpt, Some(segwitWalletConf)), destroy = { funded: FundedWallet => destroyWallet(funded.wallet) @@ -188,14 +189,14 @@ trait BitcoinSWalletTest withNewConfiguredWallet(segwitWalletConf)(test) } - def withNewWallet(test: OneArgAsyncTest): FutureOutcome = + def withNewWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = makeDependentFixture(build = { () => - createDefaultWallet(nodeApi, chainQueryApi) + createDefaultWallet(nodeApi, chainQueryApi, bip39PasswordOpt) }, destroy = destroyWallet)(test) - def withNewWallet2Accounts(test: OneArgAsyncTest): FutureOutcome = { + def withNewWallet2Accounts(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { makeDependentFixture(build = { () => - createWallet2Accounts(nodeApi, chainQueryApi) + createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt) }, destroy = destroyWallet)(test) } @@ -214,7 +215,7 @@ trait BitcoinSWalletTest makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) } - def withNewWalletAndBitcoindV19(test: OneArgAsyncTest): FutureOutcome = { + def withNewWalletAndBitcoindV19(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap( builder = { () => BitcoinSFixture @@ -222,7 +223,7 @@ trait BitcoinSWalletTest .map(_.asInstanceOf[BitcoindV19RpcClient]) }, dependentBuilder = { (bitcoind: BitcoindV19RpcClient) => - createWalletWithBitcoindV19(bitcoind) + createWalletWithBitcoindV19(bitcoind, bip39PasswordOpt) }, wrap = (_: BitcoindV19RpcClient, walletWithBitcoind: WalletWithBitcoindV19) => @@ -232,12 +233,13 @@ trait BitcoinSWalletTest makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) } - def withFundedWalletAndBitcoind(test: OneArgAsyncTest): FutureOutcome = { + def withFundedWalletAndBitcoind(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { val builder: () => Future[WalletWithBitcoind] = { () => for { bitcoind <- BitcoinSFixture .createBitcoindWithFunds(None) - wallet <- createWalletWithBitcoindCallbacks(bitcoind) + wallet <- createWalletWithBitcoindCallbacks(bitcoind = bitcoind, + bip39PasswordOpt = bip39PasswordOpt) fundedWallet <- fundWalletWithBitcoind(wallet) } yield fundedWallet } @@ -245,13 +247,13 @@ trait BitcoinSWalletTest makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) } - def withFundedWalletAndBitcoindV19(test: OneArgAsyncTest): FutureOutcome = { + def withFundedWalletAndBitcoindV19(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { val builder: () => Future[WalletWithBitcoindV19] = { () => for { bitcoind <- BitcoinSFixture .createBitcoindWithFunds(Some(BitcoindVersion.V19)) .map(_.asInstanceOf[BitcoindV19RpcClient]) - wallet <- createWalletWithBitcoindCallbacks(bitcoind) + wallet <- createWalletWithBitcoindCallbacks(bitcoind,bip39PasswordOpt) fundedWallet <- fundWalletWithBitcoind(wallet) } yield { WalletWithBitcoindV19(fundedWallet.wallet, bitcoind) @@ -275,6 +277,8 @@ trait BitcoinSWalletTest makeDependentFixture(builder, destroy = destroy)(test) } + + def getBIP39PasswordOpt(): Option[String] = KeyManagerTestUtil.bip39PasswordOpt } object BitcoinSWalletTest extends WalletLogger { @@ -328,17 +332,6 @@ object BitcoinSWalletTest extends WalletLogger { Future.successful(0) } - sealed trait WalletWithBitcoind { - def wallet: Wallet - def bitcoind: BitcoindRpcClient - } - case class WalletWithBitcoindRpc(wallet: Wallet, bitcoind: BitcoindRpcClient) - extends WalletWithBitcoind - case class WalletWithBitcoindV19( - wallet: Wallet, - bitcoind: BitcoindV19RpcClient) - extends WalletWithBitcoind - private def createNewKeyManager( bip39PasswordOpt: Option[String] = KeyManagerTestUtil.bip39PasswordOpt)( implicit config: WalletAppConfig): BIP39KeyManager = { @@ -369,7 +362,7 @@ object BitcoinSWalletTest extends WalletLogger { * example use this to override the default data directory, network * or account type. */ - private def createNewWallet( + private def createNewWallet( keyManager: BIP39KeyManager, bip39PasswordOpt: Option[String], extraConfig: Option[Config], @@ -403,10 +396,10 @@ object BitcoinSWalletTest extends WalletLogger { def createDefaultWallet( nodeApi: NodeApi, chainQueryApi: ChainQueryApi, + bip39PasswordOpt: Option[String], extraConfig: Option[Config] = None)( implicit config: BitcoinSAppConfig, ec: ExecutionContext): Future[Wallet] = { - val bip39PasswordOpt = KeyManagerTestUtil.bip39PasswordOpt val newWalletConf = extraConfig match { case None => @@ -428,6 +421,7 @@ object BitcoinSWalletTest extends WalletLogger { * is implemented by bitcoind */ def createWalletWithBitcoindCallbacks( bitcoind: BitcoindRpcClient, + bip39PasswordOpt: Option[String], extraConfig: Option[Config] = None)( implicit config: BitcoinSAppConfig, system: ActorSystem): Future[WalletWithBitcoind] = { @@ -439,6 +433,7 @@ object BitcoinSWalletTest extends WalletLogger { val walletWithBitcoindF = for { wallet <- BitcoinSWalletTest.createWallet2Accounts(bitcoind, bitcoind, + bip39PasswordOpt = bip39PasswordOpt, extraConfig) _ = wallet.stopWalletThread() @@ -465,13 +460,14 @@ object BitcoinSWalletTest extends WalletLogger { def createWallet2Accounts( nodeApi: NodeApi, chainQueryApi: ChainQueryApi, + bip39PasswordOpt: Option[String], extraConfig: Option[Config] = None)( implicit config: BitcoinSAppConfig, system: ActorSystem): Future[Wallet] = { implicit val ec: ExecutionContextExecutor = system.dispatcher val defaultWalletF = - createDefaultWallet(nodeApi, chainQueryApi, extraConfig) + createDefaultWallet(nodeApi, chainQueryApi, bip39PasswordOpt, extraConfig) for { wallet <- defaultWalletF account1 = WalletTestUtil.getHdAccount1(wallet.walletConfig) @@ -518,12 +514,12 @@ object BitcoinSWalletTest extends WalletLogger { created.bitcoind.asInstanceOf[BitcoindV19RpcClient]) } - def createWalletWithBitcoindV19(bitcoind: BitcoindV19RpcClient)( + def createWalletWithBitcoindV19(bitcoind: BitcoindV19RpcClient, bip39PasswordOpt: Option[String])( implicit system: ActorSystem, config: BitcoinSAppConfig): Future[WalletWithBitcoindV19] = { import system.dispatcher for { - created <- createWalletWithBitcoindCallbacks(bitcoind) + created <- createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt) } yield WalletWithBitcoindV19(created.wallet, bitcoind) } @@ -539,12 +535,13 @@ object BitcoinSWalletTest extends WalletLogger { def fundedWalletAndBitcoind( versionOpt: Option[BitcoindVersion], nodeApi: NodeApi, + bip39PasswordOpt: Option[String], chainQueryApi: ChainQueryApi)( implicit config: BitcoinSAppConfig, system: ActorSystem): Future[WalletWithBitcoind] = { import system.dispatcher for { - wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi, chainQueryApi) + wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt) withBitcoind <- createWalletWithBitcoind(wallet, versionOpt) funded <- fundWalletWithBitcoind(withBitcoind) } yield funded @@ -553,12 +550,16 @@ object BitcoinSWalletTest extends WalletLogger { def fundedWalletAndBitcoind( bitcoindRpcClient: BitcoindRpcClient, nodeApi: NodeApi, - chainQueryApi: ChainQueryApi)( + chainQueryApi: ChainQueryApi, + bip39PasswordOpt: Option[String])( implicit config: BitcoinSAppConfig, system: ActorSystem): Future[WalletWithBitcoind] = { import system.dispatcher for { - wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi, chainQueryApi) + wallet <- BitcoinSWalletTest.createWallet2Accounts( + nodeApi = nodeApi, + chainQueryApi = chainQueryApi, + bip39PasswordOpt = bip39PasswordOpt) withBitcoind <- createWalletWithBitcoind(wallet, bitcoindRpcClient) funded <- fundWalletWithBitcoind(withBitcoind) } yield funded diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/FundWalletUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/FundWalletUtil.scala index 55abf3c380..305093b6e4 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/wallet/FundWalletUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/FundWalletUtil.scala @@ -128,15 +128,17 @@ object FundWalletUtil extends FundWalletUtil { def createFundedWallet( nodeApi: NodeApi, chainQueryApi: ChainQueryApi, + bip39PasswordOpt: Option[String], extraConfig: Option[Config] = None)( implicit config: BitcoinSAppConfig, system: ActorSystem): Future[FundedWallet] = { import system.dispatcher for { - wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi, - chainQueryApi, - extraConfig) + wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi = nodeApi, + chainQueryApi = chainQueryApi, + bip39PasswordOpt = bip39PasswordOpt, + extraConfig = extraConfig) funded <- FundWalletUtil.fundWallet(wallet) } yield funded } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletWithBitcoind.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletWithBitcoind.scala new file mode 100644 index 0000000000..db60802179 --- /dev/null +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/WalletWithBitcoind.scala @@ -0,0 +1,17 @@ +package org.bitcoins.testkit.wallet + +import org.bitcoins.rpc.client.common.BitcoindRpcClient +import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient +import org.bitcoins.wallet.Wallet + + +sealed trait WalletWithBitcoind { + def wallet: Wallet + def bitcoind: BitcoindRpcClient +} +case class WalletWithBitcoindRpc(wallet: Wallet, bitcoind: BitcoindRpcClient) + extends WalletWithBitcoind +case class WalletWithBitcoindV19( + wallet: Wallet, + bitcoind: BitcoindV19RpcClient) + extends WalletWithBitcoind diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/AddressHandlingTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/AddressHandlingTest.scala index 19d91a68ab..82b20a95c0 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/AddressHandlingTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/AddressHandlingTest.scala @@ -14,7 +14,7 @@ class AddressHandlingTest extends BitcoinSWalletTest { type FixtureParam = FundedWallet override def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withFundedWallet(test) + withFundedWallet(test, getBIP39PasswordOpt()) } behavior of "AddressHandling" diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/FundTransactionHandlingTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/FundTransactionHandlingTest.scala index 55b5d99c45..603a70eb60 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/FundTransactionHandlingTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/FundTransactionHandlingTest.scala @@ -5,15 +5,18 @@ import org.bitcoins.core.protocol.transaction.TransactionOutput import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte import org.bitcoins.core.wallet.utxo.TxoState import org.bitcoins.testkit.util.TestUtil -import org.bitcoins.testkit.wallet.BitcoinSWalletTest.WalletWithBitcoind -import org.bitcoins.testkit.wallet.{BitcoinSWalletTest, WalletTestUtil} +import org.bitcoins.testkit.wallet.{ + BitcoinSWalletTest, + WalletTestUtil, + WalletWithBitcoind +} import org.scalatest.FutureOutcome class FundTransactionHandlingTest extends BitcoinSWalletTest { override type FixtureParam = WalletWithBitcoind override def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withFundedWalletAndBitcoind(test) + withFundedWalletAndBitcoind(test, getBIP39PasswordOpt()) } val destination = TransactionOutput(Bitcoins(0.5), TestUtil.p2pkhScriptPubKey) diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/ProcessTransactionTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/ProcessTransactionTest.scala index 8a2de57c4d..59ff816adb 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/ProcessTransactionTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/ProcessTransactionTest.scala @@ -14,7 +14,7 @@ class ProcessTransactionTest extends BitcoinSWalletTest { override type FixtureParam = WalletApi def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withNewWallet(test) + withNewWallet(test, getBIP39PasswordOpt()) } behavior of "Wallet.processTransaction" diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/RescanHandlingTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/RescanHandlingTest.scala index 1619da18a1..93a126cdd9 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/RescanHandlingTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/RescanHandlingTest.scala @@ -5,8 +5,8 @@ import org.bitcoins.core.protocol.BlockStamp import org.bitcoins.core.util.FutureUtil import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig -import org.bitcoins.testkit.wallet.BitcoinSWalletTest -import org.bitcoins.testkit.wallet.BitcoinSWalletTest.{ +import org.bitcoins.testkit.wallet.{ + BitcoinSWalletTest, WalletWithBitcoind, WalletWithBitcoindV19 } @@ -20,7 +20,7 @@ class RescanHandlingTest extends BitcoinSWalletTest { override type FixtureParam = WalletWithBitcoind override def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withFundedWalletAndBitcoindV19(test) + withFundedWalletAndBitcoindV19(test, getBIP39PasswordOpt()) } behavior of "Wallet rescans" diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/UTXOLifeCycleTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/UTXOLifeCycleTest.scala index 1d07aace39..043d235b3c 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/UTXOLifeCycleTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/UTXOLifeCycleTest.scala @@ -6,8 +6,8 @@ import org.bitcoins.core.protocol.script.EmptyScriptPubKey import org.bitcoins.core.protocol.transaction.TransactionOutput import org.bitcoins.core.wallet.fee.{SatoshisPerByte, SatoshisPerVirtualByte} import org.bitcoins.core.wallet.utxo.TxoState -import org.bitcoins.testkit.wallet.BitcoinSWalletTest -import org.bitcoins.testkit.wallet.BitcoinSWalletTest.{ +import org.bitcoins.testkit.wallet.{ + BitcoinSWalletTest, WalletWithBitcoind, WalletWithBitcoindRpc } @@ -24,7 +24,7 @@ class UTXOLifeCycleTest extends BitcoinSWalletTest { .fromString("bcrt1qlhctylgvdsvaanv539rg7hyn0sjkdm23y70kgq") override def withFixture(test: OneArgAsyncTest): FutureOutcome = { - withFundedWalletAndBitcoind(test) + withFundedWalletAndBitcoind(test, getBIP39PasswordOpt()) } it should "track a utxo state change to pending spent" in { param => diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletBloomTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletBloomTest.scala index c84f303b54..4e0813ca43 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletBloomTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletBloomTest.scala @@ -2,8 +2,8 @@ package org.bitcoins.wallet import org.bitcoins.core.util.FutureUtil import org.bitcoins.testkit.Implicits._ -import org.bitcoins.testkit.wallet.BitcoinSWalletTest -import org.bitcoins.testkit.wallet.BitcoinSWalletTest.{ +import org.bitcoins.testkit.wallet.{ + BitcoinSWalletTest, WalletWithBitcoind, WalletWithBitcoindRpc } @@ -15,7 +15,7 @@ class WalletBloomTest extends BitcoinSWalletTest { override type FixtureParam = WalletWithBitcoind override def withFixture(test: OneArgAsyncTest): FutureOutcome = - withFundedWalletAndBitcoind(test) + withFundedWalletAndBitcoind(test, getBIP39PasswordOpt()) it should "generate a bloom filter that matches the pubkeys in our wallet" in { param => diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletIntegrationTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletIntegrationTest.scala index 6cf948f262..bb8e683144 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletIntegrationTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletIntegrationTest.scala @@ -3,8 +3,8 @@ package org.bitcoins.wallet import org.bitcoins.core.currency._ import org.bitcoins.core.hd.HDChainType import org.bitcoins.core.wallet.fee.SatoshisPerByte -import org.bitcoins.testkit.wallet.BitcoinSWalletTest -import org.bitcoins.testkit.wallet.BitcoinSWalletTest.{ +import org.bitcoins.testkit.wallet.{ + BitcoinSWalletTest, WalletWithBitcoind, WalletWithBitcoindRpc } diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletSendingTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletSendingTest.scala index efc1272ece..3719db74d0 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletSendingTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletSendingTest.scala @@ -21,7 +21,7 @@ class WalletSendingTest extends BitcoinSWalletTest { override type FixtureParam = FundedWallet override def withFixture(test: OneArgAsyncTest): FutureOutcome = - withFundedWallet(test) + withFundedWallet(test, getBIP39PasswordOpt()) behavior of "Wallet" diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletUnitTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletUnitTest.scala index 43a75da638..4110b5e4d0 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletUnitTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletUnitTest.scala @@ -24,7 +24,7 @@ class WalletUnitTest extends BitcoinSWalletTest { override type FixtureParam = WalletApi override def withFixture(test: OneArgAsyncTest): FutureOutcome = - withNewWallet(test) + withNewWallet(test, getBIP39PasswordOpt()) behavior of "Wallet - unit test"