diff --git a/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/regtest/ElementsdRegtestProcess.java b/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/regtest/ElementsdRegtestProcess.java index e5998f7532..59ea561bcf 100644 --- a/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/regtest/ElementsdRegtestProcess.java +++ b/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/regtest/ElementsdRegtestProcess.java @@ -37,7 +37,7 @@ public class ElementsdRegtestProcess extends BitcoindRegtestProcess { private final ElementsdConfig elementsdConfig; public ElementsdRegtestProcess(ElementsdConfig elementsdConfig, Path dataDir) { - super(elementsdConfig.elementsdRpcConfig(), dataDir); + super(null, elementsdConfig.elementsdRpcConfig(), dataDir); this.elementsdConfig = elementsdConfig; } diff --git a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestProcess.java b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestProcess.java index f9d8346b20..8c37458290 100644 --- a/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestProcess.java +++ b/wallets/regtest/src/main/java/bisq/wallets/regtest/bitcoind/BitcoindRegtestProcess.java @@ -38,12 +38,14 @@ @Slf4j public class BitcoindRegtestProcess extends DaemonProcess { + private final Path binaryPath; @Getter protected final RpcConfig rpcConfig; private final BitcoindDaemon bitcoindDaemon; - public BitcoindRegtestProcess(RpcConfig rpcConfig, Path dataDir) { + public BitcoindRegtestProcess(Path binaryPath, RpcConfig rpcConfig, Path dataDir) { super(dataDir); + this.binaryPath = binaryPath; this.rpcConfig = rpcConfig; JsonRpcClient rpcClient = RpcClientFactory.createDaemonRpcClient(rpcConfig); bitcoindDaemon = new BitcoindDaemon(rpcClient); @@ -53,7 +55,7 @@ public BitcoindRegtestProcess(RpcConfig rpcConfig, Path dataDir) { public ProcessConfig createProcessConfig() { int zmqPort = NetworkUtils.findFreeSystemPort(); return ProcessConfig.builder() - .name("bitcoind") + .name(binaryPath.toAbsolutePath().toString()) .args(List.of( "-regtest", "-datadir=" + dataDir.toAbsolutePath(), 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 5d49e5f872..af3a8717b6 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 @@ -17,6 +17,7 @@ package bisq.wallets.regtest.bitcoind; +import bisq.common.platform.OS; import bisq.common.util.NetworkUtils; import bisq.wallets.bitcoind.rpc.BitcoindDaemon; import bisq.wallets.bitcoind.rpc.BitcoindWallet; @@ -27,7 +28,10 @@ import bisq.wallets.regtest.process.MultiProcessCoordinator; import lombok.Getter; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Objects; @@ -101,9 +105,13 @@ private RpcConfig createRpcConfig() { return createRpcConfig("127.0.0.1", port); } - private BitcoindRegtestProcess createBitcoindProcess() { + private BitcoindRegtestProcess createBitcoindProcess() throws IOException { + Path bitcoindBinaryDir = tmpDirPath.resolve("bitcoind_binary"); + Path bitcoindPath = installBitcoind(bitcoindBinaryDir); + Path bitcoindDataDir = tmpDirPath.resolve("bitcoind_data_dir"); return new BitcoindRegtestProcess( + bitcoindPath, rpcConfig, bitcoindDataDir ); @@ -124,4 +132,40 @@ public BitcoindWallet getMinerWallet() { public ZmqListeners getZmqListeners() { return remoteBitcoind.getZmqListeners(); } + + private Path installBitcoind(Path bitcoindBinaryDir) throws IOException { + File bitcoindBinaryDirFile = bitcoindBinaryDir.toFile(); + boolean isSuccess = bitcoindBinaryDirFile.mkdirs(); + if (!isSuccess) { + throw new IllegalStateException("Couldn't create " + bitcoindBinaryDir.toAbsolutePath() + " for " + + "bitcoind installation."); + } + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream("bitcoind"); + + if (inputStream == null) { + throw new IllegalStateException("Can't read bitcoind binary from resources."); + } + + Path bitcoindPath = bitcoindBinaryDir.resolve("bitcoind"); + try (inputStream) { + Files.copy(inputStream, bitcoindPath); + + boolean endOfStreamReached = inputStream.available() == 0; + if (!endOfStreamReached) { + throw new IllegalStateException("Couldn't extract bitcoind binary."); + } + + if (OS.isLinux() || OS.isMacOs()) { + isSuccess = bitcoindPath.toFile().setExecutable(true); + if (!isSuccess) { + throw new IllegalStateException("Couldn't set executable bit on bitcoind binary."); + } + } + + return bitcoindPath; + } + } }