From 33a968a6d5883b7167c842148083089d0ac35419 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 10 Nov 2024 22:17:59 +0000 Subject: [PATCH] core: Implement RegtestWalletAppKit The RegtestWalletAppKit sets up BitcoinJ and loads the given wallets. --- core/build.gradle | 5 +++ .../java/bisq/core/RegtestWalletAppKit.java | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java diff --git a/core/build.gradle b/core/build.gradle index 9ff3b9a414..6e0f86bab9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,6 +1,7 @@ plugins { id 'bisq.java-conventions' id 'bisq.javafx' + id 'bisq.java-integration-tests' } javafx { @@ -61,6 +62,10 @@ dependencies { testAnnotationProcessor libs.lombok testCompileOnly libs.lombok testImplementation libs.natpryce.make.it.easy + + integrationTestImplementation libs.junit.jupiter + integrationTestAnnotationProcessor libs.lombok + integrationTestCompileOnly libs.lombok } test { diff --git a/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java b/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java new file mode 100644 index 0000000000..2e0b8f618e --- /dev/null +++ b/core/src/integrationTest/java/bisq/core/RegtestWalletAppKit.java @@ -0,0 +1,41 @@ +package bisq.core; + +import bisq.core.btc.wallet.WalletFactory; + +import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.kits.WalletAppKit; +import org.bitcoinj.wallet.Wallet; + +import java.nio.file.Path; + +import java.util.List; + +import lombok.Getter; + +@Getter +public class RegtestWalletAppKit { + private final WalletAppKit walletAppKit; + + public RegtestWalletAppKit(NetworkParameters networkParams, Path dataDirPath, List wallets) { + walletAppKit = new WalletAppKit(networkParams, dataDirPath.toFile(), "dataDirFilePrefix") { + @Override + protected void onSetupCompleted() { + super.onSetupCompleted(); + wallets.forEach(wallet -> { + vChain.addWallet(wallet); + vPeerGroup.addWallet(wallet); + }); + } + }; + } + + public void initialize() { + walletAppKit.connectToLocalHost(); + + var walletFactory = new WalletFactory(walletAppKit.params()); + walletAppKit.setWalletFactory((params, keyChainGroup) -> walletFactory.createBsqWallet()); + + walletAppKit.startAsync(); + walletAppKit.awaitRunning(); + } +}