From 669133449b90255e63ec8383e3484623bdf2899f Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Mon, 31 Oct 2022 11:46:05 +0100 Subject: [PATCH] BitcoindRegtest: Mine initial regtest block on startup --- .../BitcoindPsbtMultiSigIntegrationTests.java | 2 -- ...BitcoindSendAndListTxsIntegrationTests.java | 1 - ...oindSendAndListUnspentIntegrationTests.java | 1 - .../bitcoind/BitcoindSendIntegrationTests.java | 1 - ...coindSendUnconfirmedTxIntegrationTests.java | 3 +-- .../BitcoindZeroMqRawTxIntegrationTests.java | 3 +-- .../electrum/MacLinuxElectrumRegtestSetup.java | 2 +- .../electrum/WindowsElectrumRegtestSetup.java | 5 +---- .../electrumx/ElectrumXServerRegtestSetup.java | 2 +- .../SharedElementsdInstanceTests.java | 4 +--- .../bitcoind/BitcoindRegtestBlockMiner.java | 5 ----- .../regtest/bitcoind/BitcoindRegtestSetup.java | 10 +--------- .../regtest/bitcoind/RemoteBitcoind.java | 18 ++++++------------ 13 files changed, 13 insertions(+), 44 deletions(-) diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindPsbtMultiSigIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindPsbtMultiSigIntegrationTests.java index 0df4ee7aec..eea02038ba 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindPsbtMultiSigIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindPsbtMultiSigIntegrationTests.java @@ -54,8 +54,6 @@ public BitcoindPsbtMultiSigIntegrationTests(BitcoindRegtestSetup regtestSetup) { @Test public void psbtMultiSigTest() throws MalformedURLException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); - var aliceWallet = regtestSetup.createAndInitializeNewWallet("alice_wallet"); var bobWallet = regtestSetup.createAndInitializeNewWallet("bob_wallet"); var charlieWallet = regtestSetup.createAndInitializeNewWallet("charlie_wallet"); diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java index a3a1b530d7..2064d89e21 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java @@ -42,7 +42,6 @@ public BitcoindSendAndListTxsIntegrationTests(BitcoindRegtestSetup regtestSetup) @Test public void sendBtcAndListTxs() throws MalformedURLException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); BitcoindWallet minerWallet = regtestSetup.getMinerWallet(); var receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet"); diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListUnspentIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListUnspentIntegrationTests.java index fc2984a202..dd12723312 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListUnspentIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendAndListUnspentIntegrationTests.java @@ -42,7 +42,6 @@ public BitcoindSendAndListUnspentIntegrationTests(BitcoindRegtestSetup regtestSe @Test public void listUnspent() throws MalformedURLException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); BitcoindWallet minerWallet = regtestSetup.getMinerWallet(); BitcoindWallet receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet_list_unspent"); diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendIntegrationTests.java index 79f9162929..05d9872634 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendIntegrationTests.java @@ -42,7 +42,6 @@ public BitcoindSendIntegrationTests(BitcoindRegtestSetup regtestSetup) { @Test public void sendOneBtcToAddress() throws MalformedURLException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); BitcoindWallet receiverBackend = regtestSetup.createAndInitializeNewWallet("receiver_wallet_send_one_btc"); String receiverAddress = receiverBackend.getNewAddress(AddressType.BECH32, ""); diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendUnconfirmedTxIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendUnconfirmedTxIntegrationTests.java index a9e30e6b5e..777811bb46 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendUnconfirmedTxIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/BitcoindSendUnconfirmedTxIntegrationTests.java @@ -51,8 +51,7 @@ public BitcoindSendUnconfirmedTxIntegrationTests(BitcoindRegtestSetup regtestSet } @BeforeAll - public void start() throws IOException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); + public void start() throws IOException { receiverWallet = regtestSetup.createAndInitializeNewWallet("receiver_wallet_send_check_unconfirmed_balance"); } diff --git a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/zmq/BitcoindZeroMqRawTxIntegrationTests.java b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/zmq/BitcoindZeroMqRawTxIntegrationTests.java index 631fdc0544..db89c58bc5 100644 --- a/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/zmq/BitcoindZeroMqRawTxIntegrationTests.java +++ b/wallets/bitcoind/src/test/java/bisq/wallets/bitcoind/zmq/BitcoindZeroMqRawTxIntegrationTests.java @@ -47,8 +47,7 @@ public BitcoindZeroMqRawTxIntegrationTests(BitcoindRegtestSetup regtestSetup) { } @BeforeAll - public void start() throws IOException, InterruptedException { - regtestSetup.mineInitialRegtestBlocks(); + public void start() throws IOException { receiverWallet = regtestSetup.createAndInitializeNewWallet("receiver_wallet"); } diff --git a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/MacLinuxElectrumRegtestSetup.java b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/MacLinuxElectrumRegtestSetup.java index 7d2c3e1423..f214113580 100644 --- a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/MacLinuxElectrumRegtestSetup.java +++ b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/MacLinuxElectrumRegtestSetup.java @@ -32,7 +32,7 @@ public class MacLinuxElectrumRegtestSetup extends ElectrumRegtestSetup { @Getter - private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(true); + private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(); private final int electrumXServerPort = NetworkUtils.findFreeSystemPort(); private final ElectrumXServerRegtestProcess electrumXServerRegtestProcess = diff --git a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/WindowsElectrumRegtestSetup.java b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/WindowsElectrumRegtestSetup.java index d1fdf5be36..fe95a653f7 100644 --- a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/WindowsElectrumRegtestSetup.java +++ b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrum/WindowsElectrumRegtestSetup.java @@ -17,7 +17,6 @@ package bisq.wallets.electrum.regtest.electrum; -import bisq.common.util.FileUtils; import bisq.wallets.core.RpcConfig; import bisq.wallets.regtest.bitcoind.BitcoindRegtestSetup; import bisq.wallets.regtest.bitcoind.RemoteBitcoind; @@ -25,7 +24,6 @@ import lombok.Getter; import java.io.IOException; -import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.Objects; @@ -46,8 +44,7 @@ public WindowsElectrumRegtestSetup() throws IOException { public WindowsElectrumRegtestSetup(boolean doCreateWallet) throws IOException { RpcConfig bitcoindRpcConfig = createBitcoindRpcConfigFromEnvironmentVars(); - Path tmpDirPath = FileUtils.createTempDir(); - this.remoteBitcoind = new RemoteBitcoind(bitcoindRpcConfig, true); + this.remoteBitcoind = new RemoteBitcoind(bitcoindRpcConfig); RpcConfig electrumXRpcConfig = createElectrumXRpcConfigFromEnvironmentVars(); this.electrumRegtest = new ElectrumRegtest( diff --git a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrumx/ElectrumXServerRegtestSetup.java b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrumx/ElectrumXServerRegtestSetup.java index dd9c73a343..d00d0e8bf1 100644 --- a/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrumx/ElectrumXServerRegtestSetup.java +++ b/wallets/electrum/src/test/java/bisq/wallets/electrum/regtest/electrumx/ElectrumXServerRegtestSetup.java @@ -31,7 +31,7 @@ public class ElectrumXServerRegtestSetup extends AbstractRegtestSetup { @Getter - private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(true); + private final BitcoindRegtestSetup bitcoindRegtestSetup = new BitcoindRegtestSetup(); private final int electrumXServerPort = NetworkUtils.findFreeSystemPort(); @Getter diff --git a/wallets/elementsd/src/test/java/bisq/wallets/elementsd/SharedElementsdInstanceTests.java b/wallets/elementsd/src/test/java/bisq/wallets/elementsd/SharedElementsdInstanceTests.java index 89f50842b0..8a7c41be11 100644 --- a/wallets/elementsd/src/test/java/bisq/wallets/elementsd/SharedElementsdInstanceTests.java +++ b/wallets/elementsd/src/test/java/bisq/wallets/elementsd/SharedElementsdInstanceTests.java @@ -54,11 +54,9 @@ public AbstractRegtestSetup createRegtestSetup() throws @BeforeAll public void start() throws IOException, InterruptedException { super.start(); - bitcoindRegtestSetup = elementsdRegtestSetup.getBitcoindRegtestSetup(); - bitcoindRegtestSetup.mineInitialRegtestBlocks(); - bitcoindDaemon = bitcoindRegtestSetup.getDaemon(); + elementsdDaemon = elementsdRegtestSetup.getDaemon(); elementsdMinerWallet = elementsdRegtestSetup.getMinerWallet(); } diff --git a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestBlockMiner.java b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestBlockMiner.java index 3d289d9183..e3c6057276 100644 --- a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestBlockMiner.java +++ b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestBlockMiner.java @@ -24,7 +24,6 @@ import bisq.wallets.core.model.AddressType; import bisq.wallets.process.BisqProcess; -import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -57,10 +56,6 @@ public void shutdown() { zmqListeners.unregisterNewBlockMinedListener(newBlockMinedListener); } - public void mineInitialRegtestBlocks() throws InterruptedException { - mineBlocks(101); - } - public List mineBlocks(int numberOfBlocks) throws InterruptedException { String minerAddress = minerWallet.getNewAddress(AddressType.BECH32, ""); List blockHashes = daemon.generateToAddress(numberOfBlocks, minerAddress); diff --git a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestSetup.java b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestSetup.java index 1ae3494128..1eab34b27d 100644 --- a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestSetup.java +++ b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestSetup.java @@ -45,14 +45,10 @@ public class BitcoindRegtestSetup private final RemoteBitcoind remoteBitcoind; public BitcoindRegtestSetup() throws IOException { - this(false); - } - - public BitcoindRegtestSetup(boolean doMineInitialRegtestBlocks) throws IOException { super(); rpcConfig = createRpcConfig(); bitcoindProcess = createBitcoindProcess(); - remoteBitcoind = new RemoteBitcoind(rpcConfig, doMineInitialRegtestBlocks); + remoteBitcoind = new RemoteBitcoind(rpcConfig); } @Override @@ -66,10 +62,6 @@ public BitcoindWallet createAndInitializeNewWallet(String walletName) throws Mal return remoteBitcoind.createAndInitializeNewWallet(walletName); } - public void mineInitialRegtestBlocks() throws InterruptedException { - remoteBitcoind.mineInitialRegtestBlocks(); - } - @Override public List mineOneBlock() throws InterruptedException { return mineBlocks(1); diff --git a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/RemoteBitcoind.java b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/RemoteBitcoind.java index ddcbc81dd0..05865c9934 100644 --- a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/RemoteBitcoind.java +++ b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/RemoteBitcoind.java @@ -46,7 +46,6 @@ public class RemoteBitcoind implements BisqProcess { private final RpcConfig rpcConfig; @Getter private final BitcoindDaemon daemon; - private final boolean doMineInitialRegtestBlocks; @Getter private final ZmqListeners zmqListeners = new ZmqListeners(); @Getter @@ -55,11 +54,9 @@ public class RemoteBitcoind implements BisqProcess { private final List loadedWallets = new ArrayList<>(); private ZmqConnection bitcoindZeroMq; - public RemoteBitcoind(RpcConfig rpcConfig, - boolean doMineInitialRegtestBlocks) throws MalformedURLException { + public RemoteBitcoind(RpcConfig rpcConfig) throws MalformedURLException { this.rpcConfig = rpcConfig; this.daemon = createBitcoindDaemon(); - this.doMineInitialRegtestBlocks = doMineInitialRegtestBlocks; this.minerWallet = new BitcoindWallet(daemon, rpcConfig, MINER_WALLET_NAME); this.blockMiner = new BitcoindRegtestBlockMiner(daemon, minerWallet, zmqListeners); } @@ -69,10 +66,7 @@ public void start() throws InterruptedException { blockMiner.start(); initializeZmqListeners(); initializeWallet(minerWallet); - - if (doMineInitialRegtestBlocks) { - mineInitialRegtestBlocks(); - } + mineInitialRegtestBlocks(); } @Override @@ -88,10 +82,6 @@ public BitcoindWallet createAndInitializeNewWallet(String walletName) throws Mal return bitcoindWallet; } - public void mineInitialRegtestBlocks() throws InterruptedException { - blockMiner.mineInitialRegtestBlocks(); - } - public List mineBlocks(int numberOfBlocks) throws InterruptedException { return blockMiner.mineBlocks(numberOfBlocks); } @@ -137,4 +127,8 @@ private void initializeWallet(BitcoindWallet wallet) { wallet.initialize(Optional.of(WALLET_PASSPHRASE)); loadedWallets.add(wallet); } + + private void mineInitialRegtestBlocks() throws InterruptedException { + blockMiner.mineBlocks(101); + } }