tests: cut over to regtest and run the marked tests in CI
What changed, and why it matters
This commit is a test-infrastructure change. It switches the project's automated tests from relying on an external Monero testnet/stagenet network to using a self-contained local 'regtest' (fakechain) network that the tests start and manage themselves. It also tags tests so they can run in CI. There is no user-facing security fix or vulnerability patch here.
No security action required. This is a testing/CI infrastructure change. Reviewers may want to verify that the regtest fixture does not leave long-lived daemon/wallet processes running in CI, but that is a test hygiene concern, not a product security issue.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a Regtest fixture (utils/Regtest.java), a StartMining helper that calls the daemon’s generateblocks RPC, and tags many JUnit tests with @Tag(‘CI’). It updates MoneroDaemonRpc to recognize the ‘fakechain’ nettype as regtest and maps it to MAINNET address semantics, and threads a regtest flag through MoneroWalletFull openWallet/openWalletData calls. CI workflows are adjusted to build monerod and wallet_rpc_server and run the tagged tests. TestUtils now defaults to a local regtest setup. No production code bug fixes or security-sensitive logic changes are present.
Changed components
src/test/java/utils/Regtest.javasrc/test/java/utils/StartMining.javasrc/test/java/utils/TestUtils.java.github/workflows/build.ymlsrc/main/java/monero/daemon/MoneroDaemonRpc.javasrc/main/java/monero/daemon/model/MoneroDaemonInfo.javasrc/main/java/monero/wallet/MoneroWalletFull.javasrc/test/java/TestMoneroDaemonRpc.javasrc/test/java/TestMoneroWalletFull.javasrc/test/java/TestMoneroWalletRpc.javasrc/test/java/TestMoneroConnectionManager.javasrc/test/java/TestSampleCode.javasrc/test/java/TestSerialization.javasrc/test/java/TestMoneroUtils.javasrc/test/java/TestNativeLibrary.javasrc/test/java/TestNetworkUtils.javaInspect captured patch +858 / −226
### .github/workflows/build.yml
@@ -2,10 +2,7 @@ name: Build
on:
push:
- branches: [ master ]
pull_request:
- branches:
- - master
workflow_dispatch:
permissions:
@@ -133,6 +130,7 @@ jobs:
cd build/release
cmake -DSTATIC=ON -DBUILD_64=ON -DARCH="${{ matrix.march }}" -DCMAKE_BUILD_TYPE=Release -DUSE_DEVICE_TREZOR=OFF ../../
make -j3 wallet cryptonote_protocol
+ if [ "${{ matrix.arch }}" = "linux-x86_64" ]; then make -j3 daemon wallet_rpc_server; fi
- name: Build monero-cpp
run: |
@@ -168,9 +166,14 @@ jobs:
if nm -D --defined-only build/libmonero-java.so | grep -E ' (SSL_|EVP_|BN_)'; then
echo "static closure symbols are exported"; exit 1
fi
- mkdir -p test_wallets
+ mkdir -p test_regtest/wallet_full
mvn -B test -Dmaven.test.skip=false -Dtest=TestMoneroUtils,TestNativeLibrary,TestSerialization,TestMoneroConnectionManager#testResponseTimesAfterSettingChange -DargLine=-Djava.library.path=build
+ - name: Test regtest suite
+ if: matrix.arch == 'linux-x86_64'
+ timeout-minutes: 90
+ run: mvn -B test -Dmaven.test.skip=false -Dgroups=CI -DfailIfNoTests=true -DargLine=-Djava.library.path=build
+
- name: Upload monero-java library
uses: actions/upload-artifact@v7
with:
@@ -288,7 +291,7 @@ jobs:
env:
MAVEN_OPTS: -Djava.library.path=build
run: |
- mkdir -p test_wallets
+ mkdir -p test_regtest/wallet_full
mvn -B test -Dmaven.test.skip=false -Dtest=TestMoneroUtils,TestNativeLibrary,TestSerialization,TestMoneroConnectionManager#testResponseTimesAfterSettingChange -DargLine=-Djava.library.path=build
- name: Upload monero-java library
@@ -413,7 +416,7 @@ jobs:
if nm -gU build/libmonero-java.dylib | awk '{print $NF}' | grep -vE '^_(Java_|JNI_OnLoad$|JNI_OnUnload$)'; then
echo "unexpected exports above"; exit 1
fi
- mkdir -p test_wallets
+ mkdir -p test_regtest/wallet_full
mvn -B test -Dmaven.test.skip=false -Dtest=TestMoneroUtils,TestNativeLibrary,TestSerialization,TestMoneroConnectionManager#testResponseTimesAfterSettingChange -DargLine=-Djava.library.path=build
- name: Upload monero-java library
@@ -474,7 +477,7 @@ jobs:
# bullseye security packages were removed from live mirrors after LTS ended
sed -i 's|^deb .* bullseye-security |deb [check-valid-until=no] http://snapshot.debian.org/archive/debian-security/20260903T220410Z/ bullseye-security |' /etc/apt/sources.list &&
apt-get update -qq && apt-get install -y -qq openjdk-11-jre-headless > /dev/null &&
- mkdir -p test_wallets &&
+ mkdir -p test_regtest/wallet_full &&
java -cp $JAR:target/test-classes:\$(cat cp.txt) TestNativeLibrary"
- name: Upload jar
### .gitignore
@@ -3,4 +3,4 @@
/lib/
**/pom.xml.versionsBackup
**/logs
-/test_wallets
+/test_regtest
### README.md
@@ -199,14 +199,17 @@ For example: `export LD_PRELOAD=/path/to/libjemalloc.a` then run your app.
## Running JUnit tests
-1. Clone the project repository: `git clone --recurse-submodules https://github.com/woodser/monero-java.git`
-2. `cd monero-java`
-3. Start RPC servers:
- 1. Download and install [Monero CLI](https://web.getmonero.org/downloads/).
- 2. Start monerod, e.g.: `./monerod --stagenet` (or use a remote daemon).
- 3. Start monero-wallet-rpc, e.g.: `./monero-wallet-rpc --daemon-address http://localhost:38081 --stagenet --rpc-bind-port 38083 --rpc-login rpc_user:abc123 --wallet-dir ./`
-4. Configure the appropriate RPC endpoints, authentication, and other settings in [TestUtils.java](src/test/java/utils/TestUtils.java).
-5. Run all *.java files in src/test/java as JUnits.
+Tests run automatically in CI. To run them locally, first [build the native libraries](#building-native-libraries-from-source). A regtest network is created and started automatically in ./test_regtest when tests run.
+
+```sh
+# run all tests
+mvn test -Dmaven.test.skip=false -DargLine=-Djava.library.path=build
+
+# run tests by class or method
+mvn test -Dmaven.test.skip=false -DargLine=-Djava.library.path=build -Dtest=TestSampleCode
+```
+
+Tests can also be run directly from an IDE like VS Code or Eclipse with `-Djava.library.path=build` as a VM option.
## Related projects
### src/main/java/monero/daemon/MoneroDaemonRpc.java
@@ -1577,7 +1577,10 @@ else if (key.equals("untrusted")) {} // handled elsewhere
else if (key.equals("was_bootstrap_ever_used")) info.setWasBootstrapEverUsed((Boolean) val);
else if (key.equals("white_peerlist_size")) info.setNumOnlinePeers(((BigInteger) val).intValue());
else if (key.equals("update_available")) info.setUpdateAvailable((Boolean) val);
- else if (key.equals("nettype")) info.setNetworkType(GenUtils.reconcile(info.getNetworkType(), MoneroDaemon.parseNetworkType((String) val)));
+ else if (key.equals("nettype")) {
+ info.setIsRegtest("fakechain".equals(val));
+ info.setNetworkType(GenUtils.reconcile(info.getNetworkType(), info.isRegtest() ? MoneroNetworkType.MAINNET : MoneroDaemon.parseNetworkType((String) val)));
+ }
else if (key.equals("mainnet")) { if ((Boolean) val) info.setNetworkType(GenUtils.reconcile(info.getNetworkType(), MoneroNetworkType.MAINNET)); }
else if (key.equals("testnet")) { if ((Boolean) val) info.setNetworkType(GenUtils.reconcile(info.getNetworkType(), MoneroNetworkType.TESTNET)); }
else if (key.equals("stagenet")) { if ((Boolean) val) info.setNetworkType(GenUtils.reconcile(info.getNetworkType(), MoneroNetworkType.STAGENET)); }
### src/main/java/monero/daemon/model/MoneroDaemonInfo.java
@@ -23,6 +23,7 @@ public class MoneroDaemonInfo {
private Long height;
private Long heightWithoutBootstrap;
private MoneroNetworkType networkType;
+ private Boolean isRegtest;
private Boolean isOffline;
private Integer numIncomingConnections;
private Integer numOutgoingConnections;
@@ -162,6 +163,15 @@ public MoneroNetworkType getNetworkType() {
public void setNetworkType(MoneroNetworkType networkType) {
this.networkType = networkType;
}
+
+ @JsonProperty("isRegtest")
+ public Boolean isRegtest() {
+ return isRegtest;
+ }
+
+ public void setIsRegtest(Boolean isRegtest) {
+ this.isRegtest = isRegtest;
+ }
@JsonProperty("isOffline")
public Boolean isOffline() {
### src/main/java/monero/wallet/MoneroWalletFull.java
@@ -218,9 +218,9 @@ public static MoneroWalletFull openWallet(MoneroWalletConfig config) {
// read wallet data from disk unless provided
MoneroWalletFull wallet;
if (config.getKeysData() == null) {
- wallet = openWallet(config.getPath(), config.getPassword(), config.getNetworkType(), (MoneroRpcConnection) null);
+ wallet = openWallet(config.getPath(), config.getPassword(), config.getNetworkType(), null, Boolean.TRUE.equals(config.getRegtest()));
} else {
- wallet = openWalletData(config.getPassword(), config.getNetworkType(), config.getKeysData(), config.getCacheData(), null);
+ wallet = openWalletData(config.getPassword(), config.getNetworkType(), config.getKeysData(), config.getCacheData(), null, Boolean.TRUE.equals(config.getRegtest()));
}
if (config.getServer() != null) wallet.setDaemonConnection(config.getServer(), config.isTrustedDaemon());
### src/test/java/TestAll.java
@@ -12,6 +12,8 @@
TestSampleCode.class,
TestSerialization.class,
TestMoneroUtils.class,
+ TestNetworkUtils.class,
+ TestNativeLibrary.class,
TestMoneroDaemonRpc.class,
TestMoneroWalletFull.class,
TestMoneroWalletRpc.class,
### src/test/java/TestMoneroConnectionManager.java
@@ -14,6 +14,7 @@
import monero.common.MoneroConnectionManager;
import monero.common.MoneroConnectionManagerListener;
import monero.wallet.MoneroWalletRpc;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import utils.TestUtils;
@@ -25,6 +26,7 @@ public class TestMoneroConnectionManager {
private static final int SYNC_PADDING = 1000;
@Test
+ @Tag("CI")
public void testResponseTimesAfterSettingChange() {
class TestConnection extends MoneroRpcConnection {
TestConnection(String uri, long responseTime) {
@@ -49,6 +51,7 @@ public boolean checkConnection(long timeoutMs) {
}
@Test
+ @Tag("CI")
public void testConnectionManager() throws InterruptedException, IOException {
List<MoneroWalletRpc> walletRpcs = new ArrayList<MoneroWalletRpc>();
MoneroConnectionManager connectionManager = null;
@@ -194,7 +197,7 @@ public void testConnectionManager() throws InterruptedException, IOException {
assertEquals(++numExpectedChanges, listener.changedConnections.size());
// connect to specific endpoint with authentication
- orderedConnections.get(1).setCredentials("rpc_user", "abc123");
+ orderedConnections.get(1).setCredentials(TestUtils.WALLET_RPC_USERNAME, TestUtils.WALLET_RPC_PASSWORD);
connectionManager.checkConnection();
assertEquals(connectionManager.getConnection().getUri(), walletRpcs.get(1).getRpcConnection().getUri());
assertTrue(connection.isOnline());
### src/test/java/TestMoneroDaemonRpc.java
@@ -56,7 +56,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
+import utils.StartMining;
import utils.TestUtils;
/**
@@ -108,15 +110,21 @@ public void beforeEach() {
// Can start and stop a daemon process
@Test
+ @Tag("CI")
public void testStartDaemon() {
// create command to start monerod process
List<String> cmd = new ArrayList<String>(Arrays.asList(
TestUtils.DAEMON_LOCAL_PATH,
- "--" + TestUtils.NETWORK_TYPE.toString().toLowerCase(),
+ "--regtest",
+ "--offline",
+ "--fixed-difficulty", "1",
+ "--keep-fakechain",
+ "--check-updates", "disabled",
+ "--disable-dns-checkpoints",
"--no-igd",
"--hide-my-port",
- "--data-dir", TestUtils.MONERO_BINS_DIR + "/node1",
+ "--data-dir", TestUtils.TEST_WALLETS_DIR + "/node1",
"--p2p-bind-port", "58080",
"--rpc-bind-port", "58081",
"--rpc-login", "superuser:abctesting123",
@@ -149,6 +157,7 @@ public void testStartDaemon() {
// Can get the daemon's version
@Test
+ @Tag("CI")
public void testGetVersion() {
assumeTrue(TEST_NON_RELAYS);
MoneroVersion version = daemon.getVersion();
@@ -159,13 +168,15 @@ public void testGetVersion() {
// Can indicate if it's trusted
@Test
+ @Tag("CI")
public void testIsTrusted() {
assumeTrue(TEST_NON_RELAYS);
daemon.isTrusted();
}
// Can get the blockchain height
@Test
+ @Tag("CI")
public void testGetHeight() {
assumeTrue(TEST_NON_RELAYS);
long height = daemon.getHeight();
@@ -174,6 +185,7 @@ public void testGetHeight() {
// Can get a block hash by height
@Test
+ @Tag("CI")
public void testGetBlockIdByHeight() {
assumeTrue(TEST_NON_RELAYS);
MoneroBlockHeader lastHeader = daemon.getLastBlockHeader();
@@ -184,6 +196,7 @@ public void testGetBlockIdByHeight() {
// Can get a block template
@Test
+ @Tag("CI")
public void testGetBlockTemplate() {
assumeTrue(TEST_NON_RELAYS);
MoneroBlockTemplate template = daemon.getBlockTemplate(TestUtils.ADDRESS, 2);
@@ -192,6 +205,7 @@ public void testGetBlockTemplate() {
// Can get the last block's header
@Test
+ @Tag("CI")
public void testGetLastBlockHeader() {
assumeTrue(TEST_NON_RELAYS);
MoneroBlockHeader lastHeader = daemon.getLastBlockHeader();
@@ -200,6 +214,7 @@ public void testGetLastBlockHeader() {
// Can get a block header by hash
@Test
+ @Tag("CI")
public void testGetBlockHeaderByHash() {
assumeTrue(TEST_NON_RELAYS);
@@ -219,6 +234,7 @@ public void testGetBlockHeaderByHash() {
// Can get a block header by height
@Test
+ @Tag("CI")
public void testGetBlockHeaderByHeight() {
assumeTrue(TEST_NON_RELAYS);
@@ -237,6 +253,7 @@ public void testGetBlockHeaderByHeight() {
// Can get block headers by range
// TODO: test start with no end, vice versa, inclusivity
@Test
+ @Tag("CI")
public void testGetBlockHeadersByRange() {
assumeTrue(TEST_NON_RELAYS);
@@ -261,6 +278,7 @@ public void testGetBlockHeadersByRange() {
// Can get a block by hash
@Test
+ @Tag("CI")
public void testGetBlockByHash() {
assumeTrue(TEST_NON_RELAYS);
@@ -295,6 +313,7 @@ public void testGetBlocksByHashBinary() {
// Can get a block by height
@Test
+ @Tag("CI")
public void testGetBlockByHeight() {
assumeTrue(TEST_NON_RELAYS);
@@ -318,6 +337,7 @@ public void testGetBlockByHeight() {
// Can get blocks by height which includes transactions (binary)
@Test
+ @Tag("CI")
public void testGetBlocksByHeightBinary() {
assumeTrue(TEST_NON_RELAYS);
@@ -349,6 +369,7 @@ public void testGetBlocksByHeightBinary() {
// Can get blocks by range in a single request
@Test
+ @Tag("CI")
public void testGetBlocksByRange() {
assumeTrue(TEST_NON_RELAYS);
@@ -374,6 +395,7 @@ public void testGetBlocksByRange() {
// Can get blocks by range using chunked requests
@Test
+ @Tag("CI")
public void testGetBlocksByRangeChunked() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
@@ -405,6 +427,7 @@ public void testGetBlockIdsBinary() {
// Can get a transaction by hash with and without pruning
@Test
+ @Tag("CI")
public void testGetTxByHash() {
assumeTrue(TEST_NON_RELAYS);
@@ -441,6 +464,7 @@ public void testGetTxByHash() {
// Can get transactions by hashes with and without pruning
@Test
+ @Tag("CI")
public void testGetTxsByHashes() {
assumeTrue(TEST_NON_RELAYS);
@@ -489,6 +513,7 @@ public void testGetTxsByHashes() {
// Can get transactions by hashes that are in the transaction pool
@Test
+ @Tag("CI")
public void testGetTxsByHashesInPool() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet); // wait for wallet's txs in the pool to clear to ensure reliable sync
@@ -527,6 +552,7 @@ public void testGetTxsByHashesInPool() {
// Can get a transaction hex by hash with and without pruning
@Test
+ @Tag("CI")
public void testGetTxHexByHash() {
assumeTrue(TEST_NON_RELAYS);
@@ -562,6 +588,7 @@ public void testGetTxHexByHash() {
// Can get transaction hexes by hashes with and without pruning
@Test
+ @Tag("CI")
public void testGetTxHexesByHashes() {
assumeTrue(TEST_NON_RELAYS);
@@ -594,6 +621,7 @@ public void testGetTxHexesByHashes() {
// Can get the miner transaction sum
@Test
+ @Tag("CI")
public void testGetMinerTxSum() {
assumeTrue(TEST_NON_RELAYS);
MoneroMinerTxSum sum = daemon.getMinerTxSum(0l, Math.min(50000l, daemon.getHeight()));
@@ -602,6 +630,7 @@ public void testGetMinerTxSum() {
// Can get a fee estimate
@Test
+ @Tag("CI")
public void testGetFeeEstimate() {
assumeTrue(TEST_NON_RELAYS);
MoneroFeeEstimate feeEstimate = daemon.getFeeEstimate();
@@ -613,6 +642,7 @@ public void testGetFeeEstimate() {
// Can get all transactions in the transaction pool
@Test
+ @Tag("CI")
public void testGetTxsInPool() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -661,6 +691,7 @@ public void testGetTxPoolBacklogBin() {
// Can get transaction pool statistics
@Test
+ @Tag("CI")
public void testGetTxPoolStatistics() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -693,6 +724,7 @@ public void testGetTxPoolStatistics() {
// Can flush all transactions from the pool
@Test
+ @Tag("CI")
public void testFlushTxsFromPool() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -727,6 +759,7 @@ public void testFlushTxsFromPool() {
// Can flush a transaction from the pool by hash
@Test
+ @Tag("CI")
public void testFlushTxFromPoolByHash() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -763,6 +796,7 @@ public void testFlushTxFromPoolByHash() {
// Can flush transactions from the pool by hashes
@Test
+ @Tag("CI")
public void testFlushTxsFromPoolByHashes() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -790,6 +824,7 @@ public void testFlushTxsFromPoolByHashes() {
// Can get the spent status of key images
@Test
+ @Tag("CI")
public void testGetSpentStatusOfKeyImages() {
assumeTrue(TEST_NON_RELAYS);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -848,6 +883,7 @@ public void testGetOutputsFromAmountsAndIndicesBinary() {
// Can get an output histogram (binary)
@Test
+ @Tag("CI")
public void testGetOutputHistogramBinary() {
assumeTrue(TEST_NON_RELAYS);
List<MoneroOutputHistogramEntry> entries = daemon.getOutputHistogram(null, null, null, null, null);
@@ -878,6 +914,7 @@ public void testGetOutputDistributionBinary() {
// Can get general information
@Test
+ @Tag("CI")
public void testGetGeneralInformation() {
assumeTrue(TEST_NON_RELAYS);
MoneroDaemonInfo info = daemon.getInfo();
@@ -886,6 +923,7 @@ public void testGetGeneralInformation() {
// Can get sync information
@Test
+ @Tag("CI")
public void testGetSyncInformation() {
assumeTrue(TEST_NON_RELAYS);
MoneroDaemonSyncInfo syncInfo = daemon.getSyncInfo();
@@ -894,6 +932,7 @@ public void testGetSyncInformation() {
// Can get hard fork information
@Test
+ @Tag("CI")
public void testGetHardForkInformation() {
assumeTrue(TEST_NON_RELAYS);
MoneroHardForkInfo hardForkInfo = daemon.getHardForkInfo();
@@ -902,6 +941,7 @@ public void testGetHardForkInformation() {
// Can get alternative chains
@Test
+ @Tag("CI")
public void testGetAlternativeChains() {
assumeTrue(TEST_NON_RELAYS);
List<MoneroAltChain> altChains = daemon.getAltChains();
@@ -912,6 +952,7 @@ public void testGetAlternativeChains() {
// Can get alternative block hashes
@Test
+ @Tag("CI")
public void testGetAlternativeBlockIds() {
assumeTrue(TEST_NON_RELAYS);
List<String> altBlockIds = daemon.getAltBlockHashes();
@@ -923,6 +964,7 @@ public void testGetAlternativeBlockIds() {
// Can get, set, and reset a download bandwidth limit
@Test
+ @Tag("CI")
public void testSetDownloadBandwidth() {
assumeTrue(TEST_NON_RELAYS);
int initVal = daemon.getDownloadLimit();
@@ -945,6 +987,7 @@ public void testSetDownloadBandwidth() {
// Can get, set, and reset an upload bandwidth limit
@Test
+ @Tag("CI")
public void testSetUploadBandwidth() {
assumeTrue(TEST_NON_RELAYS);
int initVal = daemon.getUploadLimit();
@@ -989,6 +1032,7 @@ public void testGetKnownPeers() {
// Can limit the number of outgoing peers
@Test
+ @Tag("CI")
public void testSetOutgoingPeerLimit() {
assumeTrue(TEST_NON_RELAYS);
daemon.setOutgoingPeerLimit(0);
@@ -998,6 +1042,7 @@ public void testSetOutgoingPeerLimit() {
// Can limit the number of incoming peers
@Test
+ @Tag("CI")
public void testSetIncomingPeerLimit() {
assumeTrue(TEST_NON_RELAYS);
daemon.setIncomingPeerLimit(0);
@@ -1007,6 +1052,7 @@ public void testSetIncomingPeerLimit() {
// Can ban a peer
@Test
+ @Tag("CI")
public void testBanPeer() {
assumeTrue(TEST_NON_RELAYS);
@@ -1029,6 +1075,7 @@ public void testBanPeer() {
// Can ban peers
@Test
+ @Tag("CI")
public void testBanPeers() {
assumeTrue(TEST_NON_RELAYS);
@@ -1061,6 +1108,7 @@ public void testBanPeers() {
// Can start and stop mining
@Test
+ @Tag("CI")
public void testMining() {
assumeTrue(TEST_NON_RELAYS);
@@ -1080,6 +1128,7 @@ public void testMining() {
// Can get mining status
@Test
+ @Tag("CI")
public void testGetMiningStatus() {
assumeTrue(TEST_NON_RELAYS);
@@ -1120,26 +1169,32 @@ public void testGetMiningStatus() {
// Can submit a mined block to the network
@Test
+ @Tag("CI")
public void testSubmitMinedBlock() {
assumeTrue(TEST_NON_RELAYS);
- // get template to mine on
+ // the template is mined as is at regtest's fixed difficulty of 1
MoneroBlockTemplate template = daemon.getBlockTemplate(TestUtils.ADDRESS);
+ daemon.submitBlock(template.getBlockTemplateBlob());
- // TODO monero rpc: way to get mining nonce when found in order to submit?
+ // the block extends the chain
+ MoneroBlockHeader header = daemon.getBlockHeaderByHeight(template.getHeight());
+ assertEquals(template.getPrevHash(), header.getPrevHash());
+ assertEquals(template.getHeight() + 1, daemon.getHeight());
- // try to submit block hashing blob without nonce
+ // a malformed blob is rejected
try {
- daemon.submitBlock(template.getBlockTemplateBlob());
+ daemon.submitBlock("00");
fail("Should have thrown error");
} catch (MoneroRpcError e) {
- assertEquals(-7, (int) e.getCode());
- assertEquals("Block not accepted", e.getMessage());
+ assertEquals("Wrong block blob", e.getMessage());
+ assertEquals(-6, (int) e.getCode());
}
}
// Can prune the blockchain
@Test
+ @Tag("CI")
public void testPruneBlockchain() {
assumeTrue(TEST_NON_RELAYS);
MoneroPruneResult result = daemon.pruneBlockchain(true);
@@ -1210,6 +1265,7 @@ public void testStop() throws InterruptedException {
// Can submit a tx in hex format to the pool and relay in one call
@Test
+ @Tag("CI")
public void testSubmitAndRelayTxHex() {
assumeTrue(TEST_RELAYS && !LITE_MODE);
@@ -1226,6 +1282,9 @@ public void testSubmitAndRelayTxHex() {
assertEquals(true, result.isRelayed());
testSubmitTxResultGood(result);
+ // wait for tx1 to be relayed, which monerod marks asynchronously
+ try { Thread.sleep(1000); } catch (Exception e) { throw new RuntimeException(e); }
+
// tx1 is in the pool
List<MoneroTx> txs = daemon.getTxPool();
boolean found = false;
@@ -1261,6 +1320,7 @@ public void testSubmitAndRelayTxHex() {
// Can submit a tx in hex format to the pool then relay
@Test
+ @Tag("CI")
public void testSubmitThenRelayTxHex() {
assumeTrue(TEST_RELAYS && !LITE_MODE);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -1270,6 +1330,7 @@ public void testSubmitThenRelayTxHex() {
// Can submit txs in hex format to the pool then relay
@Test
+ @Tag("CI")
public void testSubmitThenRelayTxHexes() {
assumeTrue(TEST_RELAYS && !LITE_MODE);
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
@@ -1337,15 +1398,14 @@ private static void testSubmitThenRelay(List<MoneroTx> txs) {
// Can notify listeners when a new block is added to the chain
@Test
+ @Tag("CI")
public void testBlockListener() {
assumeTrue(!LITE_MODE && TEST_NOTIFICATIONS);
try {
- // start mining if possible to help push the network along
- String address = wallet.getPrimaryAddress();
- try { daemon.startMining(address, 8l, false, true); }
- catch (MoneroError e) { }
+ // start mining to push the network along
+ StartMining.startMining();
// register a listener
MoneroDaemonListener listener = new MoneroDaemonListener();
@@ -1358,13 +1418,10 @@ public void testBlockListener() {
// test that listener was called with equivalent header
assertEquals(header, listener.getLastBlockHeader());
- } catch (MoneroError e) {
- throw e;
} finally {
// stop mining
- try { daemon.stopMining(); }
- catch (MoneroError e) { }
+ StartMining.stopMining();
}
}
@@ -1429,8 +1486,7 @@ private static void testBlockHeader(MoneroBlockHeader header, boolean isFull) {
else assertTrue(header.getTimestamp() > 0);
assertNotNull(header.getPrevHash());
assertNotNull(header.getNonce());
- if (header.getNonce() == 0) System.err.println("WARNING: header nonce is 0 at height " + header.getHeight()); // TODO (monero-project): why is header nonce 0?
- else assertTrue(header.getNonce() > 0);
+ assertTrue(header.getNonce() >= 0); // regtest blocks mine at the first nonce tried
assertNull(header.getPowHash()); // never seen defined
if (isFull) {
assertTrue(header.getSize() > 0);
@@ -1851,7 +1907,8 @@ private static void testInfo(MoneroDaemonInfo info) {
assertTrue(info.getHeight() >= 0);
assertTrue(info.getHeightWithoutBootstrap() > 0);
assertTrue(info.getNumIncomingConnections() >= 0);
- assertNotNull(info.getNetworkType());
+ assertEquals(TestUtils.NETWORK_TYPE, info.getNetworkType());
+ assertTrue(info.isRegtest());
assertNotNull(info.isOffline());
assertTrue(info.getNumOutgoingConnections() >= 0);
assertTrue(info.getNumRpcConnections() >= 0);
### src/test/java/TestMoneroUtils.java
@@ -21,12 +21,14 @@
import monero.wallet.model.MoneroIntegratedAddress;
import monero.wallet.model.MoneroTxConfig;
import monero.wallet.model.MoneroWalletConfig;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import utils.TestUtils;
/**
* Tests static Monero utilities.
*/
+@Tag("CI")
public class TestMoneroUtils {
// Can get integrated addresses
### src/test/java/TestMoneroWalletCommon.java
@@ -128,7 +128,8 @@ public void beforeEach(TestInfo testInfo) {
@AfterAll
public void afterAll() {
- // try to stop mining
+ // stop mining
+ StartMining.stopMining();
if (daemon != null) {
try { daemon.stopMining(); }
catch (MoneroError e) { }
@@ -142,9 +143,10 @@ public void afterAll() {
public void afterEach(TestInfo testInfo) {
System.out.println("After test " + testInfo.getDisplayName());
- if (daemon.getMiningStatus().isActive()) {
+ if (StartMining.isMining() || daemon.getMiningStatus().isActive()) {
System.err.println("WARNING: mining is active after test " + testInfo.getDisplayName() + ", stopping");
- daemon.stopMining();
+ StartMining.stopMining();
+ if (daemon.getMiningStatus().isActive()) daemon.stopMining();
}
}
@@ -546,8 +548,9 @@ public void testConnectionManager() {
// start polling connections
connectionManager.startPolling(TestUtils.SYNC_PERIOD_IN_MS);
- // test that wallet auto connects
- GenUtils.waitFor(TestUtils.AUTO_CONNECT_TIMEOUT_MS);
+ // test that wallet auto connects, allowing a timed out first check to retry after the polling period
+ long deadline = System.currentTimeMillis() + connectionManager.getTimeout() + TestUtils.SYNC_PERIOD_IN_MS * 2;
+ while (wallet.getDaemonConnection() == null && System.currentTimeMillis() < deadline) GenUtils.waitFor(100);
assertEquals(connection1, wallet.getDaemonConnection());
assertTrue(wallet.isConnectedToDaemon());
@@ -1300,14 +1303,15 @@ else if (tx.getIncomingTransfers() != null) {
// assertEquals(outgoingTx.getHash(), outgoingTxs.get(0).getHash());
// get txs with output query
- MoneroOutputQuery outputQuery = new MoneroOutputQuery().setIsSpent(false).setAccountIndex(1).setSubaddressIndex(2);
+ MoneroOutputWallet unspentOutput = wallet.getOutputs(new MoneroOutputQuery().setIsSpent(false).setAccountIndex(1)).get(0); // other tests spend from arbitrary subaddresses
+ MoneroOutputQuery outputQuery = new MoneroOutputQuery().setIsSpent(false).setAccountIndex(1).setSubaddressIndex(unspentOutput.getSubaddressIndex());
txs = wallet.getTxs(new MoneroTxQuery().setOutputQuery(outputQuery));
assertFalse(txs.isEmpty());
for (MoneroTxWallet tx : txs) {
assertFalse(tx.getOutputs() == null || tx.getOutputs().isEmpty());
found = false;
for (MoneroOutputWallet output : tx.getOutputsWallet()) {
- if (output.isSpent() == false && output.getAccountIndex() == 1 && output.getSubaddressIndex() == 2) {
+ if (output.isSpent() == false && output.getAccountIndex() == 1 && output.getSubaddressIndex().equals(unspentOutput.getSubaddressIndex())) {
found = true;
break;
}
@@ -2285,6 +2289,7 @@ public void testGetReserveProofWallet() {
@Test
public void testGetReserveProofAccount() {
assumeTrue(TEST_NON_RELAYS);
+ TestUtils.WALLET_TX_TRACKER.waitForTxsToClearWallets(wallet); // proof excludes unconfirmed change and incoming funds
// test proofs of accounts
int numNonZeroTests = 0;
@@ -3580,7 +3585,7 @@ private void testSendToMultiple(int numAccounts, int numSubaddressesPerAccount,
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(wallet);
// include the last mined blocks before measuring balance changes
- if (daemon.getMiningStatus().isActive()) daemon.stopMining();
+ StartMining.stopMining();
wallet.sync();
// compute the minimum account unlocked balance needed in order to fulfill the config
@@ -3830,8 +3835,7 @@ private void testMultisig(int m, int n, boolean testTx) {
} finally {
// stop mining at end of test
- try { daemon.stopMining(); }
- catch (MoneroError e) { }
+ StartMining.stopMining();
// save and close participants
for (MoneroWallet participant : participants) closeWallet(participant, true);
@@ -4082,9 +4086,8 @@ private void initMultisigWallets(List<MoneroWallet> participants, int M, int N,
System.out.println("Starting mining");
- // attempt to start mining
- try { StartMining.startMining(); }
- catch (MoneroError e) { if ("BUSY".equals(e.getMessage())) throw e; }
+ // start mining
+ StartMining.startMining();
// wait for the multisig wallet's funds to unlock // TODO: replace with MoneroWalletListener.onOutputReceived() which is called when output unlocked
Long lastNumConfirmations = null;
@@ -4114,7 +4117,7 @@ private void initMultisigWallets(List<MoneroWallet> participants, int M, int N,
}
// stop mining
- daemon.stopMining();
+ StartMining.stopMining();
// multisig wallet should have unlocked balance in subaddresses 0-3
for (int i = 0; i < numAddressesToFund; i++) {
@@ -4290,7 +4293,7 @@ public void onOutputReceived(MoneroOutputWallet received) {
GenUtils.executeTasks(tasks);
// stop mining
- wallet.stopMining();
+ StartMining.stopMining();
}
private void synchronizeMultisigParticipants(List<MoneroWallet> wallets) {
@@ -4415,17 +4418,9 @@ private void testSendAndUpdateTxs(MoneroTxConfig config) {
// track resulting outgoing and incoming txs as blocks are added to the chain
List<MoneroTxWallet> updatedTxs = null;
- // attempt to start mining to push the network along
- boolean startedMining = false;
- MoneroMiningStatus miningStatus = daemon.getMiningStatus();
- if (!miningStatus.isActive()) {
- try {
- StartMining.startMining();
- startedMining = true;
- } catch (Exception e) {
- System.err.println("Warning: could not start mining: " + e.getMessage()); // not fatal
- }
- }
+ // start mining to push the network along
+ boolean startedMining = !StartMining.isMining();
+ StartMining.startMining();
// loop to update txs through confirmations
long numConfirmations = 0;
@@ -4485,15 +4480,14 @@ private void testSendAndUpdateTxs(MoneroTxConfig config) {
}
// stop mining if it was started by this test
- if (startedMining) wallet.stopMining();
+ if (startedMining) StartMining.stopMining();
} catch (MoneroError e) {
throw e;
} finally {
// stop mining at end of test
- try { daemon.stopMining(); }
- catch (MoneroError e) { }
+ StartMining.stopMining();
}
}
@@ -4891,7 +4885,7 @@ private List<String> testWalletNotificationsAux(boolean sameWallet, boolean same
TestUtils.WALLET_TX_TRACKER.waitForUnlockedBalance(sender, 0, null, TestUtils.MAX_FEE.multiply(new BigInteger("10")));
// include the last mined blocks before measuring balance changes
- if (daemon.getMiningStatus().isActive()) daemon.stopMining();
+ StartMining.stopMining();
sender.sync();
if (receiver != sender) receiver.sync();
@@ -4988,7 +4982,7 @@ private List<String> testWalletNotificationsAux(boolean sameWallet, boolean same
}
}
- // mine until test completes
+ // mine until the funds unlock
StartMining.startMining();
// loop every sync period until unlock tested
@@ -5060,6 +5054,7 @@ private List<String> testWalletNotificationsAux(boolean sameWallet, boolean same
// otherwise test unlock notifications
else if (height >= expectedUnlockTime) {
+ StartMining.stopMining(); // freeze the chain so unrelated unlocks cannot change balances before the final checks
Thread thread = new Thread(new Runnable() {
@Override public void run() {
GenUtils.waitFor(TestUtils.SYNC_PERIOD_IN_MS * 2 + MAX_POLL_TIME); // wait 2 sync periods + poll time for notifications
@@ -5069,13 +5064,15 @@ else if (height >= expectedUnlockTime) {
if (!sameWallet && !receiver.getBalance().equals(receiver.getUnlockedBalance())) issues.add("ERROR: receiver balance != unlocked balance after funds unlocked");
if (senderNotificationCollector.getBalanceNotifications().size() == 0) issues.add("ERROR: sender did not announce any balance notifications");
else {
- if (!sender.getBalance().equals(senderNotificationCollector.getBalanceNotifications().get(senderNotificationCollector.getBalanceNotifications().size() - 1).getFirst())) issues.add("ERROR: sender balance != last notified balance after funds unlocked");
- if (!sender.getUnlockedBalance().equals(senderNotificationCollector.getBalanceNotifications().get(senderNotificationCollector.getBalanceNotifications().size() - 1).getSecond())) issues.add("ERROR: sender unlocked balance != last notified unlocked balance after funds unlocked");
+ Pair<BigInteger, BigInteger> lastNotified = senderNotificationCollector.getBalanceNotifications().get(senderNotificationCollector.getBalanceNotifications().size() - 1);
+ if (!sender.getBalance().equals(lastNotified.getFirst())) issues.add("ERROR: sender balance != last notified balance after funds unlocked (" + sender.getBalance() + " != " + lastNotified.getFirst() + ")");
+ if (!sender.getUnlockedBalance().equals(lastNotified.getSecond())) issues.add("ERROR: sender unlocked balance != last notified unlocked balance after funds unlocked (" + sender.getUnlockedBalance() + " != " + lastNotified.getSecond() + ")");
}
if (receiverNotificationCollector.getBalanceNotifications().size() == 0) issues.add("ERROR: receiver did not announce any balance notifications");
else {
- if (!receiver.getBalance().equals(receiverNotificationCollector.getBalanceNotifications().get(receiverNotificationCollector.getBalanceNotifications().size() - 1).getFirst())) issues.add("ERROR: receiver balance != last notified balance after funds unlocked");
- if (!receiver.getUnlockedBalance().equals(receiverNotificationCollector.getBalanceNotifications().get(receiverNotificationCollector.getBalanceNotifications().size() - 1).getSecond())) issues.add("ERROR: receiver unlocked balance != last notified unlocked balance after funds unlocked");
+ Pair<BigInteger, BigInteger> lastNotified = receiverNotificationCollector.getBalanceNotifications().get(receiverNotificationCollector.getBalanceNotifications().size() - 1);
+ if (!receiver.getBalance().equals(lastNotified.getFirst())) issues.add("ERROR: receiver balance != last notified balance after funds unlocked (" + receiver.getBalance() + " != " + lastNotified.getFirst() + ")");
+ if (!receiver.getUnlockedBalance().equals(lastNotified.getSecond())) issues.add("ERROR: receiver unlocked balance != last notified unlocked balance after funds unlocked (" + receiver.getUnlockedBalance() + " != " + lastNotified.getSecond() + ")");
}
}
});
@@ -5115,7 +5112,7 @@ else if (height >= expectedUnlockTime) {
throw new RuntimeException(e);
} finally {
try {
- if (daemon.getMiningStatus().isActive()) daemon.stopMining();
+ StartMining.stopMining();
} finally {
try {
if (sender.getListeners().contains(senderNotificationCollector)) sender.removeListener(senderNotificationCollector);
@@ -5228,7 +5225,7 @@ public void testCreateAndReceive() {
MoneroTxWallet sentTx = wallet.createTx(new MoneroTxConfig().setAccountIndex(0).setAddress(receiver.getPrimaryAddress()).setAmount(TestUtils.MAX_FEE).setRelay(true));
// wait for funds to confirm
- try { StartMining.startMining(); } catch (Exception e) { }
+ StartMining.startMining();
while (!(wallet.getTx(sentTx.getHash())).isConfirmed()) {
if (wallet.getTx(sentTx.getHash()).isFailed()) throw new Error("Tx failed in mempool: " + sentTx.getHash());
daemon.waitForNextBlockHeader();
@@ -5239,7 +5236,7 @@ public void testCreateAndReceive() {
assertFalse(myListener.getOutputsReceived().isEmpty());
} finally {
closeWallet(receiver);
- try { daemon.stopMining(); } catch (Exception e) { }
+ StartMining.stopMining();
}
}
@@ -5322,7 +5319,6 @@ public void testFreezeOutputs() {
@Test
public void testInputKeyImages() {
int accountIndex = 0;
- int subaddressIndex = wallet.getSubaddresses(0).size() > 1 ? 1 : 0; // TODO: avoid subaddress 0 which is more likely to fail transaction sanity check
// test unrelayed single transaction
testSpendTx(wallet.createTx(new MoneroTxConfig().addDestination(wallet.getPrimaryAddress(), TestUtils.MAX_FEE).setAccountIndex(accountIndex)));
@@ -5339,8 +5335,12 @@ public void testInputKeyImages() {
for (MoneroOutput input : tx.getInputs()) dustKeyImages.add(input.getKeyImage().getHex());
}
- // get available outputs above min amount
- List<MoneroOutputWallet> outputs = wallet.getOutputs(new MoneroOutputQuery().setAccountIndex(accountIndex).setSubaddressIndex(subaddressIndex).setIsSpent(false).setIsFrozen(false).setTxQuery(new MoneroTxQuery().setIsLocked(false)).setMinAmount(TestUtils.MAX_FEE));
+ // get available outputs above min amount from a subaddress with such outputs, preferring one other than 0 which is more likely to fail the tx sanity check
+ MoneroOutputQuery availableQuery = new MoneroOutputQuery().setAccountIndex(accountIndex).setIsSpent(false).setIsFrozen(false).setTxQuery(new MoneroTxQuery().setIsLocked(false)).setMinAmount(TestUtils.MAX_FEE);
+ int subaddressIndex = 0;
+ for (MoneroOutputWallet output : wallet.getOutputs(availableQuery)) if (output.getSubaddressIndex() > 0) { subaddressIndex = output.getSubaddressIndex(); break; }
+ List<MoneroOutputWallet> outputs = wallet.getOutputs(availableQuery.setSubaddressIndex(subaddressIndex));
+ assertFalse(outputs.isEmpty(), "Wallet does not have unlocked outputs in account " + accountIndex + "; run send tests");
// filter dust outputs
List<MoneroOutputWallet> dustOutputs = new ArrayList<MoneroOutputWallet>();
@@ -5578,7 +5578,7 @@ private static void testSubaddress(MoneroSubaddress subaddress) {
TestUtils.testUnsignedBigInteger(subaddress.getUnlockedBalance());
assertTrue(subaddress.getNumUnspentOutputs() >= 0);
assertNotNull(subaddress.isUsed());
- if (subaddress.getBalance().compareTo(BigInteger.valueOf(0)) > 0) assertTrue(subaddress.isUsed());
+ if (subaddress.getNumUnspentOutputs() > 0) assertTrue(subaddress.isUsed()); // pool funds count toward the balance before the subaddress is used
assertTrue(subaddress.getNumBlocksToUnlock() >= 0);
}
### src/test/java/TestMoneroWalletFull.java
@@ -88,6 +88,7 @@ protected MoneroWalletFull openWallet(MoneroWalletConfig config, boolean startSy
if (config == null) config = new MoneroWalletConfig();
if (config.getPassword() == null) config.setPassword(TestUtils.WALLET_PASSWORD);
if (config.getNetworkType() == null) config.setNetworkType(TestUtils.NETWORK_TYPE);
+ if (config.getRegtest() == null && config.getNetworkType() == TestUtils.NETWORK_TYPE) config.setRegtest(true);
if (config.getServer() == null && config.getConnectionManager() == null) config.setServer(daemon.getRpcConnection());
// open wallet
@@ -109,6 +110,7 @@ protected MoneroWalletFull createWallet(MoneroWalletConfig config, boolean start
if (config.getPath() == null) config.setPath(TestUtils.TEST_WALLETS_DIR + "/" + UUID.randomUUID().toString());
if (config.getPassword() == null) config.setPassword(TestUtils.WALLET_PASSWORD);
if (config.getNetworkType() == null) config.setNetworkType(TestUtils.NETWORK_TYPE);
+ if (config.getRegtest() == null && config.getNetworkType() == TestUtils.NETWORK_TYPE) config.setRegtest(true);
if (config.getServer() == null && config.getConnectionManager() == null) config.setServer(daemon.getRpcConnection());
if (config.getRestoreHeight() == null && !random) config.setRestoreHeight(0l);
@@ -137,6 +139,7 @@ protected List<String> getSeedLanguages() {
*/
//@Disabled // TODO monero-project: fix this https://github.com/monero-project/monero/issues/5812
@Test
+ @Tag("CI")
public void testImportKeyImagesAndTransfers() {
MoneroWalletFull wallet = null; // create a wallet for this test since it becomes corrupt TODO: use common wallet and move to common tests when fixed
try {
@@ -173,41 +176,45 @@ public void testImportKeyImagesAndTransfers() {
* syncing, have registered listeners, and which are not closed.
*/
@Test
+ @Tag("CI")
//@Disabled // TODO monero-project: disabled because observing memory leak behavior when all tests run together
public void testCreateWalletsWithoutClose() {
- // lets make some wallets and then go away
- for (int i = 0; i < 20; i++) {
- String path = getRandomWalletPath();
- MoneroWalletFull willLeaveYouHanging = createWallet(new MoneroWalletConfig().setPath(path));
- willLeaveYouHanging.startSyncing();
- willLeaveYouHanging.addListener(new MoneroWalletListener()); // listen for wallet events which could aggrevate hanging
+ // lets make some wallets and leave them open
+ List<MoneroWalletFull> wallets = new ArrayList<MoneroWalletFull>();
+ try {
+ for (int i = 0; i < 20; i++) {
+ String path = getRandomWalletPath();
+ MoneroWalletFull willLeaveYouHanging = createWallet(new MoneroWalletConfig().setPath(path));
+ wallets.add(willLeaveYouHanging);
+ willLeaveYouHanging.startSyncing();
+ willLeaveYouHanging.addListener(new MoneroWalletListener()); // listen for wallet events which could aggrevate hanging
+ }
+
+ // check in on the daemon
+ daemon.getHeight();
+
+ // start mining
+ StartMining.startMining();
+
+ // wait for a block
+ daemon.waitForNextBlockHeader();
+
+ // stop mining
+ StartMining.stopMining();
+
+ // check in on the daemon
+ daemon.getHeight();
+ } finally {
+ for (MoneroWalletFull wallet : wallets) wallet.close(); // release daemon connections for later tests
}
-
- // check in on the daemon
- daemon.getHeight();
-
- // start mining
- try { StartMining.startMining(); }
- catch (MoneroError e) { }
-
- // wait for a block
- daemon.waitForNextBlockHeader();
-
- // stop mining
- try { daemon.stopMining(); }
- catch (MoneroError e) { }
-
- // check in on the daemon
- daemon.getHeight();
-
- // wallet's intentionally not closed (daemon da man)
}
// ------------------------------- BEGIN TESTS ------------------------------
// Can get the daemon's height
@Test
+ @Tag("CI")
public void testDaemon() {
assumeTrue(TEST_NON_RELAYS);
assertTrue(wallet.isConnectedToDaemon());
@@ -217,6 +224,7 @@ public void testDaemon() {
// Can get the daemon's max peer height
@Test
+ @Tag("CI")
public void testGetDaemonMaxPeerHeight() {
assumeTrue(TEST_NON_RELAYS);
long height = ((MoneroWalletFull) wallet).getDaemonMaxPeerHeight();
@@ -231,6 +239,7 @@ public void testGetDaemonMaxPeerHeight() {
// Can create a random full wallet
@Test
+ @Tag("CI")
public void testCreateWalletRandomFull() {
assumeTrue(TEST_NON_RELAYS);
@@ -292,6 +301,7 @@ public void testCreateWalletRandomFull() {
// Can create a full wallet from seed
@Test
+ @Tag("CI")
public void testCreateWalletFromSeedFull() {
assumeTrue(TEST_NON_RELAYS);
@@ -369,6 +379,7 @@ public void testCreateWalletFromSeedFull() {
// Can create a full wallet from keys
@Test
+ @Tag("CI")
public void testCreateWalletFromKeysJni() {
assumeTrue(TEST_NON_RELAYS);
@@ -392,6 +403,7 @@ public void testCreateWalletFromKeysJni() {
// Is compatible with monero-wallet-rpc wallet files
@Test
+ @Tag("CI")
public void testWalletFileCompatibility() {
assumeTrue(TEST_NON_RELAYS);
@@ -405,7 +417,7 @@ public void testWalletFileCompatibility() {
walletRpc.close(true);
// open as full wallet
- MoneroWalletFull walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/" + walletName).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
+ MoneroWalletFull walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/" + walletName).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setRegtest(true).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
TestUtils.WALLET_TX_TRACKER.waitForTxsToClearPool(walletFull);
assertEquals(TestUtils.SEED, walletFull.getSeed());
assertEquals(TestUtils.ADDRESS, walletFull.getPrimaryAddress());
@@ -416,15 +428,15 @@ public void testWalletFileCompatibility() {
// create full wallet
walletName = GenUtils.getUUID();
String path = TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/" + walletName;
- walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
+ walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setRegtest(true).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
walletFull.sync();
balance = walletFull.getBalance();
outputsHex = walletFull.exportOutputs();
walletFull.close(true);
// rebuild wallet cache using full wallet
new File(path).delete();
- walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
+ walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setRegtest(true).setServerUri(TestUtils.DAEMON_RPC_URI).setServerUsername(TestUtils.DAEMON_RPC_USERNAME).setServerPassword(TestUtils.DAEMON_RPC_PASSWORD));
walletFull.close(true);
// open wallet using monero-wallet-rpc
@@ -440,6 +452,7 @@ public void testWalletFileCompatibility() {
// Is compatible with monero-wallet-rpc outputs and offline transaction signing
@SuppressWarnings("unused")
@Test
+ @Tag("CI")
public void testViewOnlyAndOfflineWalletCompatibility() throws InterruptedException, IOException {
assumeTrue(!LITE_MODE && (TEST_NON_RELAYS || TEST_RELAYS));
@@ -461,6 +474,7 @@ public void testViewOnlyAndOfflineWalletCompatibility() throws InterruptedExcept
// Is compatible with monero-wallet-rpc multisig wallets
@Test
+ @Tag("CI")
public void testMultisigCompatibility() throws InterruptedException, IOException {
assumeTrue(!LITE_MODE);
@@ -476,8 +490,7 @@ public void testMultisigCompatibility() throws InterruptedException, IOException
} finally {
// stop mining at end of test
- try { daemon.stopMining(); }
- catch (MoneroError e) { }
+ StartMining.stopMining();
// save and close participants
for (MoneroWallet participant : participants) closeWallet(participant, true);
@@ -509,6 +522,7 @@ public void testResyncExisting() {
// Can sync a wallet with a randomly generated seed
@Test
+ @Tag("CI")
public void testSyncRandom() {
assumeTrue(TEST_NON_RELAYS);
assertTrue(daemon.isConnected(), "Not connected to daemon");
@@ -567,34 +581,39 @@ public void testSyncRandom() {
// Can sync a wallet created from seed from the genesis
@Test
+ @Tag("CI")
public void testSyncSeedFromGenesis() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(null, null, true, false);
}
// Can sync a wallet created from seed from a restore height
@Test
+ @Tag("CI")
public void testSyncSeedFromRestoreHeight() {
assumeTrue(TEST_NON_RELAYS);
testSyncSeed(null, TestUtils.FIRST_RECEIVE_HEIGHT);
}
// Can sync a wallet created from seed from a start height.
@Test
+ @Tag("CI")
public void testSyncSeedFromStartHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT, null, false, true);
}
// Can sync a wallet created from seed from a start height less than the restore height
@Test
+ @Tag("CI")
public void testSyncSeedStartHeightLTRestoreHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT, TestUtils.FIRST_RECEIVE_HEIGHT + 3l);
}
// Can sync a wallet created from seed from a start height greater than the restore height
@Test
+ @Tag("CI")
public void testSyncSeedStartHeightGTRestoreHeight() {
assumeTrue(TEST_NON_RELAYS && !LITE_MODE);
testSyncSeed(TestUtils.FIRST_RECEIVE_HEIGHT + 3l, TestUtils.FIRST_RECEIVE_HEIGHT);
@@ -692,6 +711,7 @@ private void testSyncSeed(Long startHeight, Long restoreHeight, boolean skipGtCo
// Can sync a wallet created from keys
@Test
+ @Tag("CI")
public void testSyncWalletFromKeys() {
assumeTrue(TEST_NON_RELAYS);
@@ -748,6 +768,7 @@ public void testSyncWalletFromKeys() {
// TODO: test start syncing, notification of syncs happening, stop syncing, no notifications, etc
// Can start and stop syncing
@Test
+ @Tag("CI")
public void testStartStopSyncing() {
assumeTrue(TEST_NON_RELAYS);
@@ -826,6 +847,7 @@ public void testStartStopSyncing() {
// Does not interfere with other wallet notifications
@Test
+ @Tag("CI")
public void testWalletsDoNotInterfere() {
// create 2 wallets with a recent restore height
@@ -834,27 +856,34 @@ public void testWalletsDoNotInterfere() {
MoneroWalletFull wallet1 = createWallet(new MoneroWalletConfig().setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
MoneroWalletFull wallet2 = createWallet(new MoneroWalletConfig().setSeed(TestUtils.SEED).setRestoreHeight(restoreHeight), false);
- // track notifications of each wallet
- SyncProgressTester tester1 = new SyncProgressTester(wallet1, restoreHeight, height);
- SyncProgressTester tester2 = new SyncProgressTester(wallet1, restoreHeight, height);
- wallet1.addListener(tester1);
- wallet2.addListener(tester2);
-
- // sync first wallet and test that 2nd is not notified
- wallet1.sync();
- assertTrue(tester1.isNotified());
- assertFalse(tester2.isNotified());
-
- // sync 2nd wallet and test that 1st is not notified
- SyncProgressTester tester3 = new SyncProgressTester(wallet1, restoreHeight, height);
- wallet1.addListener(tester3);
- wallet2.sync();
- assertTrue(tester2.isNotified());
- assertFalse(tester3.isNotified());
+ try {
+
+ // track notifications of each wallet
+ SyncProgressTester tester1 = new SyncProgressTester(wallet1, restoreHeight, height);
+ SyncProgressTester tester2 = new SyncProgressTester(wallet2, restoreHeight, height);
+ wallet1.addListener(tester1);
+ wallet2.addListener(tester2);
+
+ // sync first wallet and test that 2nd is not notified
+ wallet1.sync();
+ assertTrue(tester1.isNotified());
+ assertFalse(tester2.isNotified());
+
+ // sync 2nd wallet and test that 1st is not notified
+ SyncProgressTester tester3 = new SyncProgressTester(wallet1, restoreHeight, height);
+ wallet1.addListener(tester3);
+ wallet2.sync();
+ assertTrue(tester2.isNotified());
+ assertFalse(tester3.isNotified());
+ } finally {
+ wallet1.close();
+ wallet2.close();
+ }
}
// Is equal to the RPC wallet.
@Test
+ @Tag("CI")
public void testWalletEqualityRpc() {
// wait for pending txs to clear from wallets before rescanning spent outputs
@@ -870,6 +899,7 @@ public void testWalletEqualityRpc() {
// Is equal to the RPC wallet with a seed offset
@Test
+ @Tag("CI")
public void testWalletEqualityRpcWithOffset() {
// use common offset to compare wallet implementations
@@ -884,6 +914,7 @@ public void testWalletEqualityRpcWithOffset() {
.setPath(getRandomWalletPath())
.setPassword(TestUtils.WALLET_PASSWORD)
.setNetworkType(TestUtils.NETWORK_TYPE)
+ .setRegtest(true)
.setSeed(TestUtils.SEED)
.setServer(TestUtils.getDaemonRpc().getRpcConnection())
.setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT)
@@ -899,6 +930,7 @@ public void testWalletEqualityRpcWithOffset() {
// Can be saved
@Test
+ @Tag("CI")
public void testSave() {
assumeTrue(TEST_NON_RELAYS);
@@ -991,6 +1023,7 @@ public void testSave() {
// Can export and import wallet files
@Test
+ @Tag("CI")
public void testGetData() {
assumeTrue(TEST_NON_RELAYS);
MoneroWalletFull wallet = null;
@@ -1029,8 +1062,39 @@ public void testGetData() {
}
}
+ // Can reopen regtest wallets from disk and keys after the chain advances
+ @Test
+ @Tag("CI")
+ public void testOpenWalletRegtest() {
+ String path = getRandomWalletPath();
+ MoneroWalletFull wallet = createWallet(new MoneroWalletConfig().setPath(path).setSeed(TestUtils.SEED).setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT), false);
+ byte[] keys;
+ try {
+ wallet.sync();
+ keys = wallet.getData()[0];
+ wallet.save();
+ } finally {
+ wallet.close();
+ }
+ StartMining.generateBlocks(1);
+ for (boolean fromKeys : new boolean[] {false, true}) {
+ MoneroWalletConfig config = new MoneroWalletConfig().setNetworkType(TestUtils.NETWORK_TYPE).setRegtest(true).setPassword(TestUtils.WALLET_PASSWORD).setServer(daemon.getRpcConnection());
+ if (fromKeys) config.setKeysData(keys);
+ else config.setPath(path);
+ wallet = MoneroWalletFull.openWallet(config);
+ try {
+ wallet.sync();
+ assertEquals(daemon.getHeight(), wallet.getHeight());
+ assertTrue(wallet.getUnlockedBalance().signum() > 0);
+ } finally {
+ wallet.close();
+ }
+ }
+ }
+
// Can be moved
@Test
+ @Tag("CI")
public void testMoveTo() {
assumeTrue(TEST_NON_RELAYS);
MoneroWalletFull wallet = null;
@@ -1122,7 +1186,7 @@ public void testMoveTo() {
// assertEquals("Must specify path to save wallet because wallet has not been previously saved", e.getMessage());
// }
//
-// // save wallet to test_wallets directory
+// // save wallet to the test wallets directory
// walletMemory.save(path, TestUtils.WALLET_FULL_PW);
//
// // read wallet saved to disk
@@ -1170,6 +1234,7 @@ public void testMoveTo() {
// Can be closed
@Test
+ @Tag("CI")
public void testClose() {
assumeTrue(TEST_NON_RELAYS);
@@ -1210,6 +1275,7 @@ public void testClose() {
// Supports multisig sample code
@Test
+ @Tag("CI")
public void testMultisigSample() {
testCreateMultisigWallet(1, 2);
testCreateMultisigWallet(1, 4);
@@ -1542,365 +1608,440 @@ private static void testWalletEqualityOnChain(MoneroWalletFull wallet1, MoneroWa
@Override
@Test
+ @Tag("CI")
public void testCreateWalletRandom() {
super.testCreateWalletRandom();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromSeed() {
super.testCreateWalletFromSeed();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromSeedWithOffset() {
super.testCreateWalletFromSeedWithOffset();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromKeys() {
super.testCreateWalletFromKeys();
}
@Override
@Test
+ @Tag("CI")
public void testSubaddressLookahead() {
super.testSubaddressLookahead();
}
@Override
@Test
+ @Tag("CI")
public void testGetVersion() {
super.testGetVersion();
}
@Override
@Test
+ @Tag("CI")
public void testGetPath() {
super.testGetPath();
}
@Override
@Test
+ @Tag("CI")
public void testSetDaemonConnection() {
super.testSetDaemonConnection();
}
@Test
+ @Tag("CI")
public void testConnectionManager() {
super.testConnectionManager();
}
@Override
@Test
+ @Tag("CI")
public void testGetHeight() {
super.testGetHeight();
}
@Override
@Test
+ @Tag("CI")
public void testGetHeightByDate() {
super.testGetHeightByDate();
}
@Override
@Test
+ @Tag("CI")
public void testGetSeed() {
super.testGetSeed();
}
@Override
@Test
+ @Tag("CI")
+ public void testGetSeedLanguage() {
+ super.testGetSeedLanguage();
+ }
+
+ @Override
+ @Test
+ @Tag("CI")
public void testGetSeedLanguages() {
super.testGetSeedLanguages();
}
@Override
@Test
+ @Tag("CI")
public void testGetPrivateViewKey() {
super.testGetPrivateViewKey();
}
@Override
@Test
+ @Tag("CI")
public void testGetPrivateSpendKey() {
super.testGetPrivateSpendKey();
}
@Override
@Test
+ @Tag("CI")
public void testGetPublicViewKey() {
super.testGetPublicViewKey();
}
@Override
@Test
+ @Tag("CI")
public void testGetPublicSpendKey() {
super.testGetPublicSpendKey();
}
@Override
@Test
+ @Tag("CI")
public void testGetPrimaryAddress() {
super.testGetPrimaryAddress();
}
@Override
@Test
+ @Tag("CI")
public void testGetIntegratedAddress() {
super.testGetIntegratedAddress();
}
@Override
@Test
+ @Tag("CI")
public void testDecodeIntegratedAddress() {
super.testDecodeIntegratedAddress();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithoutProgress() {
super.testSyncWithoutProgress();
}
@Override
@Test
+ @Tag("CI")
public void testWalletEqualityGroundTruth() {
super.testWalletEqualityGroundTruth();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccountsWithoutSubaddresses() {
super.testGetAccountsWithoutSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccountsWithSubaddresses() {
super.testGetAccountsWithSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccount() {
super.testGetAccount();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAccountWithoutLabel() {
super.testCreateAccountWithoutLabel();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAccountWithLabel() {
super.testCreateAccountWithLabel();
}
@Override
@Test
+ @Tag("CI")
public void testSetAccountLabel() {
super.testSetAccountLabel();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddresses() {
super.testGetSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressesByIndices() {
super.testGetSubaddressesByIndices();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressByIndex() {
super.testGetSubaddressByIndex();
}
@Override
@Test
+ @Tag("CI")
public void testCreateSubaddress() {
super.testCreateSubaddress();
}
@Override
@Test
+ @Tag("CI")
public void testSetSubaddressLabel() {
super.testSetSubaddressLabel();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressAddress() {
super.testGetSubaddressAddress();
}
@Override
@Test
+ @Tag("CI")
+ public void testGetSubaddressAddressOutOfRange() {
+ super.testGetSubaddressAddressOutOfRange();
+ }
+
+ @Override
+ @Test
+ @Tag("CI")
public void testGetAddressIndices() {
super.testGetAddressIndices();
}
@Override
@Test
+ @Tag("CI")
public void testGetAllBalances() {
super.testGetAllBalances();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWallet() {
super.testGetTxsWallet();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsByHash() {
super.testGetTxsByHash();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWithQuery() {
super.testGetTxsWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsByHeight() {
super.testGetTxsByHeight();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWithPaymentIds() {
super.testGetTxsWithPaymentIds();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsFieldsWithFiltering() {
super.testGetTxsFieldsWithFiltering();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetTxs() {
super.testValidateInputsGetTxs();
}
@Override
@Test
+ @Tag("CI")
public void testGetTransfers() {
super.testGetTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetTransfersWithQuery() {
super.testGetTransfersWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetTransfers() {
super.testValidateInputsGetTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetIncomingOutgoingTransfers() {
super.testGetIncomingOutgoingTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetOutputs() {
super.testGetOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testGetOutputsWithQuery() {
super.testGetOutputsWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetOutputs() {
super.testValidateInputsGetOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testAccounting() {
super.testAccounting();
}
@Override
@Test
+ @Tag("CI")
public void testCheckTxKey() {
super.testCheckTxKey();
}
@Override
@Test
+ @Tag("CI")
public void testCheckTxProof() {
super.testCheckTxProof();
}
@Override
@Test
+ @Tag("CI")
public void testCheckSpendProof() {
super.testCheckSpendProof();
}
@Override
@Test
+ @Tag("CI")
public void testGetReserveProofWallet() {
super.testGetReserveProofWallet();
}
@Override
@Test
+ @Tag("CI")
public void testGetReserveProofAccount() {
super.testGetReserveProofAccount();
}
@Override
@Test
+ @Tag("CI")
public void testSetTxNote() {
super.testSetTxNote();
}
@Override
@Test
+ @Tag("CI")
public void testSetTxNotes() {
super.testSetTxNotes();
}
@Override
@Test
+ @Tag("CI")
public void testExportOutputs() {
super.testExportOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testImportOutputs() {
super.testImportOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testExportKeyImages() {
super.testExportKeyImages();
}
@@ -1920,180 +2061,210 @@ public void testImportKeyImages() {
@Override
@Test
+ @Tag("CI")
public void testViewOnlyAndOfflineWallets() {
super.testViewOnlyAndOfflineWallets();
}
@Override
@Test
+ @Tag("CI")
public void testSignAndVerifyMessages() {
super.testSignAndVerifyMessages();
}
@Override
@Test
+ @Tag("CI")
public void testAddressBook() {
super.testAddressBook();
}
@Override
@Test
+ @Tag("CI")
public void testSetAttributes() {
super.testSetAttributes();
}
@Override
@Test
+ @Tag("CI")
public void testGetPaymentUri() {
super.testGetPaymentUri();
}
@Override
@Test
+ @Tag("CI")
public void testMining() {
super.testMining();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsSendingFunds() {
super.testValidateInputsSendingFunds();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSameAccounts() {
super.testSyncWithPoolSameAccounts();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSubmitAndFlush() {
super.testSyncWithPoolSubmitAndFlush();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSubmitAndRelay() {
super.testSyncWithPoolSubmitAndRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolRelay() {
super.testSyncWithPoolRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSendToSelf() {
super.testSendToSelf();
}
@Override
@Test
+ @Tag("CI")
public void testSendToExternal() {
super.testSendToExternal();
}
@Override
@Test
+ @Tag("CI")
public void testSendFromSubaddresses() {
super.testSendFromSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testSendFromSubaddressesSplit() {
super.testSendFromSubaddressesSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSend() {
super.testSend();
}
@Override
@Test
+ @Tag("CI")
public void testSendWithPaymentId() {
super.testSendWithPaymentId();
}
@Override
@Test
+ @Tag("CI")
public void testSendSplit() {
super.testSendSplit();
}
@Override
@Test
+ @Tag("CI")
public void testCreateThenRelay() {
super.testCreateThenRelay();
}
@Override
@Test
+ @Tag("CI")
public void testCreateThenRelaySplit() {
super.testCreateThenRelaySplit();
}
@Override
@Test
+ @Tag("CI")
public void testSendToMultiple() {
super.testSendToMultiple();
}
@Override
@Test
+ @Tag("CI")
public void testSendToMultipleSplit() {
super.testSendToMultipleSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSendDustToMultipleSplit() {
super.testSendDustToMultipleSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSubtractFeeFrom() {
super.testSubtractFeeFrom();
}
@Override
@Test
+ @Tag("CI")
public void testSubtractFeeFromSplit() {
super.testSubtractFeeFromSplit();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedSameAccount() {
super.testUpdateLockedSameAccount();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedSameAccountSplit() {
super.testUpdateLockedSameAccountSplit();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedDifferentAccounts() {
super.testUpdateLockedDifferentAccounts();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedDifferentAccountsSplit() {
super.testUpdateLockedDifferentAccountsSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSweepOutputs() {
super.testSweepOutputs();
}
@@ -2124,18 +2295,21 @@ public void testSweepWalletBySubaddresses() {
@Override
@Test
+ @Tag("CI")
public void testSweepDustNoRelay() {
super.testSweepDustNoRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSweepDust() {
super.testSweepDust();
}
@Override
@Test
+ @Tag("CI")
public void testScanTxs() {
super.testScanTxs();
}
@@ -2148,6 +2322,7 @@ public void testRescanBlockchain() {
@Override
@Test
+ @Tag("CI")
public void testMultisig() {
super.testMultisig();
}
@@ -2161,32 +2336,37 @@ public void testMultisigStress() {
@Override
@Test
+ @Tag("CI")
public void testChangePassword() {
super.testChangePassword();
}
@Override
@Test
+ @Tag("CI")
public void testSaveAndClose() {
super.testSaveAndClose();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentWallet() {
super.testNotificationsDifferentWallet();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentWalletWhenRelayed() {
super.testNotificationsDifferentWalletWhenRelayed();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentAccounts() {
super.testNotificationsDifferentAccounts();
@@ -2201,6 +2381,7 @@ public void testNotificationsSameAccount() {
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentAccountSweepOutput() {
super.testNotificationsDifferentAccountSweepOutput();
@@ -2215,36 +2396,42 @@ public void testNotificationsSameAccountSweepOutputWhenRelayed() {
@Override
@Test
+ @Tag("CI")
public void testStopListening() {
super.testStopListening();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAndReceive() {
super.testCreateAndReceive();
}
@Override
@Test
+ @Tag("CI")
public void testFreezeOutputs() {
super.testFreezeOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testInputKeyImages() {
super.testInputKeyImages();
}
@Override
@Test
+ @Tag("CI")
public void testProveUnrelayedTxs() {
super.testProveUnrelayedTxs();
}
@Override
@Test
+ @Tag("CI")
public void testGetDefaultFeePriority() {
super.testGetDefaultFeePriority();
}
### src/test/java/TestMoneroWalletRpc.java
@@ -112,6 +112,7 @@ protected List<String> getSeedLanguages() {
// Can create a wallet with a randomly generated seed
@Test
+ @Tag("CI")
public void testCreateWalletRandomRpc() {
assumeTrue(TEST_NON_RELAYS);
@@ -146,6 +147,7 @@ public void testCreateWalletRandomRpc() {
// Can create a RPC wallet from a seed
@Test
+ @Tag("CI")
public void testCreateWalletFromSeedRpc() {
assumeTrue(TEST_NON_RELAYS);
@@ -175,6 +177,7 @@ public void testCreateWalletFromSeedRpc() {
// Can open wallets
@Test
+ @Tag("CI")
public void testOpenWallet() {
assumeTrue(TEST_NON_RELAYS);
@@ -221,13 +224,15 @@ public void testOpenWallet() {
// Can indicate if multisig import is needed for correct balance information
@Test
+ @Tag("CI")
public void testIsMultisigNeeded() {
assumeTrue(TEST_NON_RELAYS);
assertEquals(false, wallet.isMultisigImportNeeded()); // TODO: test with multisig wallet
}
// Can tag accounts and query accounts by tag
@Test
+ @Tag("CI")
public void testAccountTags() {
assumeTrue(TEST_NON_RELAYS);
@@ -290,6 +295,7 @@ public void testAccountTags() {
// Can get addresses out of range of used accounts and subaddresses
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressAddressOutOfRange() {
assumeTrue(TEST_NON_RELAYS);
List<MoneroAccount> accounts = wallet.getAccounts(true);
@@ -301,13 +307,15 @@ public void testGetSubaddressAddressOutOfRange() {
// Can save the wallet
@Test
+ @Tag("CI")
public void testSave() {
assumeTrue(TEST_NON_RELAYS);
wallet.save();
}
// Can close a wallet
@Test
+ @Tag("CI")
public void testClose() {
assumeTrue(TEST_NON_RELAYS);
@@ -406,24 +414,28 @@ protected void testSignatureHeaderCheckError(MoneroError e) {
@Override
@Test
+ @Tag("CI")
public void testCreateWalletRandom() {
super.testCreateWalletRandom();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromSeed() {
super.testCreateWalletFromSeed();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromSeedWithOffset() {
super.testCreateWalletFromSeedWithOffset();
}
@Override
@Test
+ @Tag("CI")
public void testCreateWalletFromKeys() {
super.testCreateWalletFromKeys();
}
@@ -436,29 +448,34 @@ public void testSubaddressLookahead() {
@Override
@Test
+ @Tag("CI")
public void testGetVersion() {
super.testGetVersion();
}
@Override
@Test
+ @Tag("CI")
public void testGetPath() {
super.testGetPath();
}
@Override
@Test
+ @Tag("CI")
public void testSetDaemonConnection() {
super.testSetDaemonConnection();
}
@Test
+ @Tag("CI")
public void testConnectionManager() {
super.testConnectionManager();
}
@Override
@Test
+ @Tag("CI")
public void testGetHeight() {
super.testGetHeight();
}
@@ -471,24 +488,28 @@ public void testGetHeightByDate() {
@Override
@Test
+ @Tag("CI")
public void testGetSeed() {
super.testGetSeed();
}
@Override
@Test
+ @Tag("CI")
public void testGetSeedLanguages() {
super.testGetSeedLanguages();
}
@Override
@Test
+ @Tag("CI")
public void testGetPrivateViewKey() {
super.testGetPrivateViewKey();
}
@Override
@Test
+ @Tag("CI")
public void testGetPrivateSpendKey() {
super.testGetPrivateSpendKey();
}
@@ -507,270 +528,315 @@ public void testGetPublicSpendKey() {
@Override
@Test
+ @Tag("CI")
public void testGetPrimaryAddress() {
super.testGetPrimaryAddress();
}
@Override
@Test
+ @Tag("CI")
public void testGetIntegratedAddress() {
super.testGetIntegratedAddress();
}
@Override
@Test
+ @Tag("CI")
public void testDecodeIntegratedAddress() {
super.testDecodeIntegratedAddress();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithoutProgress() {
super.testSyncWithoutProgress();
}
@Override
@Test
+ @Tag("CI")
public void testWalletEqualityGroundTruth() {
super.testWalletEqualityGroundTruth();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccountsWithoutSubaddresses() {
super.testGetAccountsWithoutSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccountsWithSubaddresses() {
super.testGetAccountsWithSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetAccount() {
super.testGetAccount();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAccountWithoutLabel() {
super.testCreateAccountWithoutLabel();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAccountWithLabel() {
super.testCreateAccountWithLabel();
}
@Override
@Test
+ @Tag("CI")
public void testSetAccountLabel() {
super.testSetAccountLabel();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddresses() {
super.testGetSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressesByIndices() {
super.testGetSubaddressesByIndices();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressByIndex() {
super.testGetSubaddressByIndex();
}
@Override
@Test
+ @Tag("CI")
public void testCreateSubaddress() {
super.testCreateSubaddress();
}
@Override
@Test
+ @Tag("CI")
public void testSetSubaddressLabel() {
super.testSetSubaddressLabel();
}
@Override
@Test
+ @Tag("CI")
public void testGetSubaddressAddress() {
super.testGetSubaddressAddress();
}
@Override
@Test
+ @Tag("CI")
public void testGetAddressIndices() {
super.testGetAddressIndices();
}
@Override
@Test
+ @Tag("CI")
public void testGetAllBalances() {
super.testGetAllBalances();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWallet() {
super.testGetTxsWallet();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsByHash() {
super.testGetTxsByHash();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWithQuery() {
super.testGetTxsWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsByHeight() {
super.testGetTxsByHeight();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsWithPaymentIds() {
super.testGetTxsWithPaymentIds();
}
@Override
@Test
+ @Tag("CI")
public void testGetTxsFieldsWithFiltering() {
super.testGetTxsFieldsWithFiltering();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetTxs() {
super.testValidateInputsGetTxs();
}
@Override
@Test
+ @Tag("CI")
public void testGetTransfers() {
super.testGetTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetTransfersWithQuery() {
super.testGetTransfersWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetTransfers() {
super.testValidateInputsGetTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetIncomingOutgoingTransfers() {
super.testGetIncomingOutgoingTransfers();
}
@Override
@Test
+ @Tag("CI")
public void testGetOutputs() {
super.testGetOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testGetOutputsWithQuery() {
super.testGetOutputsWithQuery();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsGetOutputs() {
super.testValidateInputsGetOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testAccounting() {
super.testAccounting();
}
@Override
@Test
+ @Tag("CI")
public void testSetTxNote() {
super.testSetTxNote();
}
@Override
@Test
+ @Tag("CI")
public void testSetTxNotes() {
super.testSetTxNotes();
}
@Override
@Test
+ @Tag("CI")
public void testCheckTxKey() {
super.testCheckTxKey();
}
@Override
@Test
+ @Tag("CI")
public void testCheckTxProof() {
super.testCheckTxProof();
}
@Override
@Test
+ @Tag("CI")
public void testCheckSpendProof() {
super.testCheckSpendProof();
}
@Override
@Test
+ @Tag("CI")
public void testGetReserveProofWallet() {
super.testGetReserveProofWallet();
}
@Override
@Test
+ @Tag("CI")
public void testGetReserveProofAccount() {
super.testGetReserveProofAccount();
}
@Override
@Test
+ @Tag("CI")
public void testExportOutputs() {
super.testExportOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testImportOutputs() {
super.testImportOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testExportKeyImages() {
super.testExportKeyImages();
}
@Override
@Test
+ @Tag("CI")
public void testGetNewKeyImagesFromLastImport() {
super.testGetNewKeyImagesFromLastImport();
}
@@ -784,180 +850,210 @@ public void testImportKeyImages() {
@Override
@Test
+ @Tag("CI")
public void testViewOnlyAndOfflineWallets() {
super.testViewOnlyAndOfflineWallets();
}
@Override
@Test
+ @Tag("CI")
public void testSignAndVerifyMessages() {
super.testSignAndVerifyMessages();
}
@Override
@Test
+ @Tag("CI")
public void testAddressBook() {
super.testAddressBook();
}
@Override
@Test
+ @Tag("CI")
public void testSetAttributes() {
super.testSetAttributes();
}
@Override
@Test
+ @Tag("CI")
public void testGetPaymentUri() {
super.testGetPaymentUri();
}
@Override
@Test
+ @Tag("CI")
public void testMining() {
super.testMining();
}
@Override
@Test
+ @Tag("CI")
public void testValidateInputsSendingFunds() {
super.testValidateInputsSendingFunds();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSameAccounts() {
super.testSyncWithPoolSameAccounts();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSubmitAndFlush() {
super.testSyncWithPoolSubmitAndFlush();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolSubmitAndRelay() {
super.testSyncWithPoolSubmitAndRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSyncWithPoolRelay() {
super.testSyncWithPoolRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSendToSelf() {
super.testSendToSelf();
}
@Override
@Test
+ @Tag("CI")
public void testSendToExternal() {
super.testSendToExternal();
}
@Override
@Test
+ @Tag("CI")
public void testSendFromSubaddresses() {
super.testSendFromSubaddresses();
}
@Override
@Test
+ @Tag("CI")
public void testSendFromSubaddressesSplit() {
super.testSendFromSubaddressesSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSend() {
super.testSend();
}
@Override
@Test
+ @Tag("CI")
public void testSendWithPaymentId() {
super.testSendWithPaymentId();
}
@Override
@Test
+ @Tag("CI")
public void testSendSplit() {
super.testSendSplit();
}
@Override
@Test
+ @Tag("CI")
public void testCreateThenRelay() {
super.testCreateThenRelay();
}
@Override
@Test
+ @Tag("CI")
public void testCreateThenRelaySplit() {
super.testCreateThenRelaySplit();
}
@Override
@Test
+ @Tag("CI")
public void testSendToMultiple() {
super.testSendToMultiple();
}
@Override
@Test
+ @Tag("CI")
public void testSendToMultipleSplit() {
super.testSendToMultipleSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSendDustToMultipleSplit() {
super.testSendDustToMultipleSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSubtractFeeFrom() {
super.testSubtractFeeFrom();
}
@Override
@Test
+ @Tag("CI")
public void testSubtractFeeFromSplit() {
super.testSubtractFeeFromSplit();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedSameAccount() {
super.testUpdateLockedSameAccount();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedSameAccountSplit() {
super.testUpdateLockedSameAccountSplit();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedDifferentAccounts() {
super.testUpdateLockedDifferentAccounts();
}
@Override
@Test
+ @Tag("CI")
public void testUpdateLockedDifferentAccountsSplit() {
super.testUpdateLockedDifferentAccountsSplit();
}
@Override
@Test
+ @Tag("CI")
public void testSweepOutputs() {
super.testSweepOutputs();
}
@@ -988,24 +1084,28 @@ public void testSweepWalletBySubaddresses() {
@Override
@Test
+ @Tag("CI")
public void testSweepDustNoRelay() {
super.testSweepDustNoRelay();
}
@Override
@Test
+ @Tag("CI")
public void testSweepDust() {
super.testSweepDust();
}
@Override
@Test
+ @Tag("CI")
public void testScanTxs() {
super.testScanTxs();
}
// Can rescan spent // TODO: run this in full wallet too
@Test
+ @Tag("CI")
public void testRescanSpent() {
assumeTrue(TEST_NON_RELAYS);
wallet.rescanSpent();
@@ -1019,6 +1119,7 @@ public void testRescanBlockchain() {
@Override
@Test
+ @Tag("CI")
public void testMultisig() {
super.testMultisig();
}
@@ -1032,32 +1133,37 @@ public void testMultisigStress() {
@Override
@Test
+ @Tag("CI")
public void testChangePassword() {
super.testChangePassword();
}
@Override
@Test
+ @Tag("CI")
public void testSaveAndClose() {
super.testSaveAndClose();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentWallet() {
super.testNotificationsDifferentWallet();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentWalletWhenRelayed() {
super.testNotificationsDifferentWalletWhenRelayed();
}
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentAccounts() {
super.testNotificationsDifferentAccounts();
@@ -1072,6 +1178,7 @@ public void testNotificationsSameAccount() {
@Override
@Test
+ @Tag("CI")
@Tag("NotificationTest")
public void testNotificationsDifferentAccountSweepOutput() {
super.testNotificationsDifferentAccountSweepOutput();
@@ -1086,36 +1193,42 @@ public void testNotificationsSameAccountSweepOutputWhenRelayed() {
@Override
@Test
+ @Tag("CI")
public void testStopListening() {
super.testStopListening();
}
@Override
@Test
+ @Tag("CI")
public void testCreateAndReceive() {
super.testCreateAndReceive();
}
@Override
@Test
+ @Tag("CI")
public void testFreezeOutputs() {
super.testFreezeOutputs();
}
@Override
@Test
+ @Tag("CI")
public void testInputKeyImages() {
super.testInputKeyImages();
}
@Override
@Test
+ @Tag("CI")
public void testProveUnrelayedTxs() {
super.testProveUnrelayedTxs();
}
@Override
@Test
+ @Tag("CI")
public void testGetDefaultFeePriority() {
super.testGetDefaultFeePriority();
}
### src/test/java/TestNativeLibrary.java
@@ -15,6 +15,7 @@
import monero.wallet.MoneroWallet;
import monero.wallet.MoneroWalletFull;
import monero.wallet.model.MoneroWalletConfig;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import utils.TestUtils;
@@ -23,6 +24,7 @@
*
* Has a main() so it can also run on a bare jvm, without maven: java -cp <classpath> TestNativeLibrary
*/
+@Tag("CI")
public class TestNativeLibrary {
/**
### src/test/java/TestNetworkUtils.java
@@ -4,11 +4,13 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import monero.common.NetworkUtils;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
/**
* Tests generic network/transport addressing utilities.
*/
+@Tag("CI")
public class TestNetworkUtils {
@Test
### src/test/java/TestSampleCode.java
@@ -23,6 +23,7 @@
import monero.wallet.model.MoneroWalletConfig;
import monero.wallet.model.MoneroWalletListener;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import utils.TestUtils;
@@ -48,21 +49,23 @@ public static void setUpBeforeClass() throws Exception {
// Sample code demonstration
@SuppressWarnings("unused")
@Test
+ @Tag("CI")
public void testSampleCode() throws InterruptedException {
// connect to daemon
- MoneroDaemon daemon = new MoneroDaemonRpc("http://localhost:28081", "", "");
+ MoneroDaemon daemon = new MoneroDaemonRpc(TestUtils.DAEMON_RPC_URI, TestUtils.DAEMON_RPC_USERNAME, TestUtils.DAEMON_RPC_PASSWORD);
long height = daemon.getHeight(); // 1523651
List<MoneroTx> txsInPool = daemon.getTxPool(); // get transactions in the pool
// create wallet from seed using JNI bindings to monero-project
MoneroWalletFull walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig()
- .setPath("./test_wallets/" + UUID.randomUUID().toString()) // *** CHANGE README TO "sample_wallet_full" ***
+ .setPath(TestUtils.TEST_WALLETS_DIR + "/" + UUID.randomUUID().toString()) // *** CHANGE README TO "sample_wallet_full" ***
.setPassword("supersecretpassword123")
- .setNetworkType(MoneroNetworkType.TESTNET)
- .setServerUri("http://localhost:28081")
- .setServerUsername("superuser")
- .setServerPassword("abctesting123")
+ .setNetworkType(TestUtils.NETWORK_TYPE)
+ .setRegtest(true)
+ .setServerUri(TestUtils.DAEMON_RPC_URI)
+ .setServerUsername(TestUtils.DAEMON_RPC_USERNAME)
+ .setServerPassword(TestUtils.DAEMON_RPC_PASSWORD)
.setSeed(TestUtils.SEED) // *** REPLACE WITH SEED IN README ***
.setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT)); // *** REPLACE WITH FIRST RECEIVE HEIGHT IN README ***
@@ -118,23 +121,25 @@ public void onOutputReceived(MoneroOutputWallet output) {
// Connection manager demonstration
@SuppressWarnings("unused")
@Test
+ @Tag("CI")
public void testConnectionManagerDemo() {
// create connection manager
MoneroConnectionManager connectionManager = new MoneroConnectionManager();
// add managed connections with priorities
- connectionManager.addConnection(new MoneroRpcConnection("http://localhost:28081").setPriority(1)); // use localhost as first priority
+ connectionManager.addConnection(new MoneroRpcConnection(TestUtils.DAEMON_RPC_URI, TestUtils.DAEMON_RPC_USERNAME, TestUtils.DAEMON_RPC_PASSWORD).setPriority(1)); // use localhost as first priority
connectionManager.addConnection(new MoneroRpcConnection("http://example.com")); // default priority is prioritized last
// set current connection
connectionManager.setConnection(new MoneroRpcConnection("http://foo.bar", "admin", "password")); // connection is added if new
// create or open wallet governed by connection manager
MoneroWalletFull walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig()
- .setPath("./test_wallets/" + UUID.randomUUID().toString()) // *** CHANGE README TO "sample_wallet_full" ***
+ .setPath(TestUtils.TEST_WALLETS_DIR + "/" + UUID.randomUUID().toString()) // *** CHANGE README TO "sample_wallet_full" ***
.setPassword("supersecretpassword123")
- .setNetworkType(MoneroNetworkType.TESTNET)
+ .setNetworkType(TestUtils.NETWORK_TYPE)
+ .setRegtest(true)
.setConnectionManager(connectionManager)
.setSeed(TestUtils.SEED) // *** REPLACE WITH SEED IN README ***
.setRestoreHeight(TestUtils.FIRST_RECEIVE_HEIGHT)); // *** REPLACE WITH FIRST RECEIVE HEIGHT IN README ***
### src/test/java/TestSerialization.java
@@ -18,14 +18,43 @@
import java.util.Map;
import monero.common.MoneroRpcConnection;
import monero.common.SslOptions;
+import monero.daemon.MoneroDaemonRpc;
+import monero.daemon.model.MoneroDaemonInfo;
+import monero.daemon.model.MoneroNetworkType;
import monero.wallet.MoneroWalletRpc;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
/**
* Tests serialization and deserialization.
*/
+@Tag("CI")
public class TestSerialization {
+ @Test
+ public void testDaemonNetworkType() {
+ Map<String, Object> info = new HashMap<String, Object>();
+ info.put("status", "OK");
+ MoneroDaemonRpc daemon = new MoneroDaemonRpc(new MoneroRpcConnection("http://localhost:18081") {
+ @Override
+ public Map<String, Object> sendJsonRequest(String method, Object params) {
+ assertEquals("get_info", method);
+ return Collections.singletonMap("result", info);
+ }
+ });
+ for (String network : Arrays.asList("mainnet", "testnet", "stagenet", "fakechain")) {
+ info.put("nettype", network);
+ MoneroDaemonInfo result = daemon.getInfo();
+ assertEquals("fakechain".equals(network), result.isRegtest());
+ assertEquals("fakechain".equals(network) ? MoneroNetworkType.MAINNET : MoneroNetworkType.parse(network), result.getNetworkType());
+ assertEquals(result.isRegtest(), JsonUtils.toMap(result).get("isRegtest"));
+ }
+ info.remove("nettype");
+ info.put("mainnet", true);
+ assertNull(daemon.getInfo().isRegtest());
+ assertEquals(MoneroNetworkType.MAINNET, daemon.getInfo().getNetworkType());
+ }
+
@Test
public void testSimpleSerialization() {
### src/test/java/utils/FundWallets.java
@@ -7,7 +7,6 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
-import monero.daemon.model.MoneroNetworkType;
import monero.wallet.MoneroWallet;
import monero.wallet.MoneroWalletFull;
import monero.wallet.model.MoneroDestination;
@@ -43,7 +42,7 @@ public static void fundWallets(MoneroWallet srcWallet, int numWallets, int numAc
// create wallet and create and collect subaddresses
List<String> subaddresses = new ArrayList<String>();
String path = TestUtils.TEST_WALLETS_DIR + "/funded_" + UUID.randomUUID().toString();
- MoneroWalletFull fundedWallet = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(MoneroNetworkType.STAGENET));
+ MoneroWalletFull fundedWallet = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(TestUtils.NETWORK_TYPE).setRegtest(true));
for (int accountIdx = 0; accountIdx < NUM_ACCOUNTS; accountIdx++) {
fundedWallet.createAccount();
for (int subaddressIdx = 0; subaddressIdx < NUM_SUBADDRESSES_PER_ACCOUNT; subaddressIdx++) {
### src/test/java/utils/Regtest.java
@@ -0,0 +1,192 @@
+package utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+import monero.common.MoneroError;
+import monero.common.MoneroRpcConnection;
+import monero.daemon.MoneroDaemonRpc;
+import monero.daemon.model.MoneroDaemonInfo;
+import monero.wallet.MoneroWalletRpc;
+import monero.wallet.model.MoneroTxConfig;
+import monero.wallet.model.MoneroWalletConfig;
+
+/**
+ * Starts and funds the regtest servers used by the tests unless they are already running.
+ */
+public class Regtest {
+
+ public static final String DAEMON_DIR = TestUtils.REGTEST_DIR + "/monerod";
+ public static final int COINBASE_BLOCKS = 100; // blocks mined to the test wallet from its first receive height
+ public static final long FUNDING_HEIGHT = TestUtils.FIRST_RECEIVE_HEIGHT + COINBASE_BLOCKS + 60; // the test wallet's coinbase outputs are unlocked
+ public static final int COVERAGE_BLOCKS = 15; // one block funding accounts 1 to 3, 10 to unlock, one spend per account, one block funding every subaddress
+ public static final int HISTORY_ROUNDS = 20; // random transfers confirmed one per block after coverage
+ public static final long FIXTURE_HEIGHT = FUNDING_HEIGHT + COVERAGE_BLOCKS + HISTORY_ROUNDS + 10; // history outputs are unlocked
+
+ private static MoneroDaemonRpc daemon;
+ private static MoneroWalletRpc walletRpc;
+ private static boolean started;
+ private static RuntimeException startError;
+
+ /**
+ * Start the servers unless they answer on the configured ports, then fund the test wallet on a fresh chain.
+ */
+ public static synchronized void start() {
+ if (startError != null) throw startError;
+ if (started) return;
+ try {
+ daemon = startDaemon();
+ walletRpc = startWalletRpc();
+ started = true; // calls while funding use the running servers
+ mineTo(TestUtils.MINING_ADDRESS, TestUtils.FIRST_RECEIVE_HEIGHT);
+ mineTo(TestUtils.ADDRESS, TestUtils.FIRST_RECEIVE_HEIGHT + COINBASE_BLOCKS);
+ mineTo(TestUtils.MINING_ADDRESS, FUNDING_HEIGHT);
+ if (daemon.getHeight() < FIXTURE_HEIGHT) buildHistory();
+ if (!daemon.getTxPool().isEmpty()) StartMining.generateBlocks(10); // confirm and unlock txs left by a previous run
+ initMiningDataset();
+ } catch (IOException e) {
+ startError = new MoneroError(e);
+ throw startError;
+ } catch (RuntimeException e) {
+ startError = e;
+ throw e;
+ } catch (Error e) {
+ startError = new MoneroError(e);
+ throw e;
+ }
+ }
+
+ /**
+ * Stop the servers started by this process and any wallet servers left running by tests.
+ */
+ public static synchronized void stop() {
+ for (MoneroWalletRpc wallet : new ArrayList<MoneroWalletRpc>(TestUtils.WALLET_PORT_OFFSETS.keySet())) TestUtils.stopWalletRpcProcess(wallet);
+ if (walletRpc != null && walletRpc.getProcess() != null) walletRpc.stopProcess();
+ if (daemon != null && daemon.getProcess() != null) daemon.stopProcess();
+ }
+
+ // connect to the daemon on the configured port, starting one if nothing answers
+ private static MoneroDaemonRpc startDaemon() throws IOException {
+ MoneroDaemonRpc daemon = new MoneroDaemonRpc(new MoneroRpcConnection(TestUtils.DAEMON_RPC_URI, TestUtils.DAEMON_RPC_USERNAME, TestUtils.DAEMON_RPC_PASSWORD));
+ MoneroDaemonInfo info;
+ try {
+ info = daemon.getInfo();
+ } catch (MoneroError e) {
+ new File(DAEMON_DIR).mkdirs();
+ daemon = new MoneroDaemonRpc(Arrays.asList(TestUtils.DAEMON_LOCAL_PATH,
+ "--regtest", "--keep-fakechain", "--offline", "--fixed-difficulty", "1", "--non-interactive", "--no-zmq",
+ "--p2p-bind-ip", "127.0.0.1", "--p2p-bind-port", "" + (TestUtils.DAEMON_RPC_PORT - 1),
+ "--rpc-bind-ip", "127.0.0.1", "--rpc-bind-port", "" + TestUtils.DAEMON_RPC_PORT,
+ "--rpc-ssl", "disabled", "--rpc-access-control-origins", TestUtils.WALLET_RPC_ACCESS_CONTROL_ORIGINS,
+ "--data-dir", DAEMON_DIR, "--check-updates", "disabled", "--disable-dns-checkpoints"));
+ info = daemon.getInfo();
+ }
+ if (!Boolean.TRUE.equals(info.isRegtest())) throw new MoneroError("Daemon at " + TestUtils.DAEMON_RPC_URI + " is not regtest");
+ return daemon;
+ }
+
+ // connect to the wallet server on the configured port, starting one if nothing answers
+ private static MoneroWalletRpc startWalletRpc() throws IOException {
+ MoneroWalletRpc walletRpc = new MoneroWalletRpc(new MoneroRpcConnection(TestUtils.WALLET_RPC_URI, TestUtils.WALLET_RPC_USERNAME, TestUtils.WALLET_RPC_PASSWORD));
+ try {
+ walletRpc.getVersion();
+ return walletRpc;
+ } catch (MoneroError e) {
+ new File(TestUtils.WALLET_RPC_LOCAL_WALLET_DIR).mkdirs();
+ List<String> cmd = new ArrayList<String>(Arrays.asList(TestUtils.WALLET_RPC_LOCAL_PATH,
+ "--rpc-bind-ip", "127.0.0.1", "--rpc-bind-port", "" + TestUtils.WALLET_RPC_PORT_START,
+ "--rpc-login", TestUtils.WALLET_RPC_USERNAME + ":" + TestUtils.WALLET_RPC_PASSWORD,
+ "--rpc-ssl", "disabled", "--daemon-ssl", "disabled",
+ "--rpc-access-control-origins", TestUtils.WALLET_RPC_ACCESS_CONTROL_ORIGINS,
+ "--daemon-address", TestUtils.DAEMON_RPC_URI,
+ "--wallet-dir", TestUtils.WALLET_RPC_LOCAL_WALLET_DIR,
+ "--log-file", TestUtils.WALLET_RPC_LOCAL_WALLET_DIR + "/monero-wallet-rpc.log",
+ "--allow-mismatched-daemon-version", "--trusted-daemon", "--non-interactive"));
+ if (!TestUtils.DAEMON_RPC_USERNAME.isEmpty()) cmd.addAll(Arrays.asList("--daemon-login", TestUtils.DAEMON_RPC_USERNAME + ":" + TestUtils.DAEMON_RPC_PASSWORD));
+ return new MoneroWalletRpc(cmd);
+ }
+ }
+
+ // mine a block with the daemon so its randomx dataset is initialized before tests stop mining through
+ // the wallet servers, whose daemon requests time out after 15 seconds
+ private static void initMiningDataset() {
+ long height = daemon.getHeight();
+ boolean miningStarted = !daemon.getMiningStatus().isActive();
+ if (miningStarted) daemon.startMining(TestUtils.MINING_ADDRESS, 1l, false, true);
+ while (daemon.getHeight() == height) {
+ try { TimeUnit.MILLISECONDS.sleep(100); }
+ catch (InterruptedException e) { throw new RuntimeException(e); }
+ }
+ if (miningStarted) daemon.stopMining();
+ }
+
+ private static void mineTo(String address, long height) {
+ StartMining.generateBlocks(address, height - daemon.getHeight());
+ }
+
+ // confirm a seeded random sequence of transfers so the test wallet has history beyond coinbase
+ private static void buildHistory() {
+ String seedEnv = System.getenv("MONERO_HISTORY_SEED");
+ long seed = seedEnv == null ? new Random().nextLong() : Long.parseLong(seedEnv);
+ System.out.println("Building regtest history with seed " + seed);
+ Random random = new Random(seed);
+ TestUtils.openTestWallet(walletRpc);
+ MoneroWalletRpc funder = TestUtils.createWalletRpc(new MoneroWalletConfig().setSeed(TestUtils.MINING_SEED).setServer(daemon.getRpcConnection()));
+ try {
+ funder.sync();
+ if (funder.getUnlockedBalance().signum() == 0) throw new MoneroError("Mining wallet is unfunded on this chain, delete " + TestUtils.REGTEST_DIR + " to start over");
+ while (walletRpc.getAccounts().size() < 4) walletRpc.createAccount();
+ for (int accountIdx = 0; accountIdx < 4; accountIdx++) while (walletRpc.getSubaddresses(accountIdx).size() < 3) walletRpc.createSubaddress(accountIdx);
+
+ // fund accounts 1 to 3, spend from each so each has spent outputs, then fund every subaddress from account 0
+ MoneroTxConfig funding = new MoneroTxConfig().setAccountIndex(0).setRelay(true);
+ for (int accountIdx = 1; accountIdx < 4; accountIdx++) funding.addDestination(walletRpc.getAddress(accountIdx, 0), TestUtils.MAX_FEE.multiply(BigInteger.valueOf(2)));
+ walletRpc.sync();
+ walletRpc.createTx(funding);
+ StartMining.generateBlocks(10);
+ for (int accountIdx = 1; accountIdx < 4; accountIdx++) {
+ walletRpc.sync();
+ walletRpc.createTx(new MoneroTxConfig().setAccountIndex(accountIdx).setAddress(funder.getPrimaryAddress()).setAmount(TestUtils.MAX_FEE).setRelay(true));
+ StartMining.generateBlocks(1);
+ }
+ funding = new MoneroTxConfig().setAccountIndex(0).setRelay(true);
+ for (int accountIdx = 0; accountIdx < 4; accountIdx++) for (int subaddressIdx = 0; subaddressIdx < 3; subaddressIdx++) funding.addDestination(walletRpc.getAddress(accountIdx, subaddressIdx), randomAmount(random));
+ walletRpc.sync();
+ walletRpc.createTx(funding);
+ StartMining.generateBlocks(1);
+
+ // random transfers one per block
+ while (daemon.getHeight() < FUNDING_HEIGHT + COVERAGE_BLOCKS + HISTORY_ROUNDS) {
+ walletRpc.sync();
+ funder.sync();
+ MoneroTxConfig config = new MoneroTxConfig().setAccountIndex(0).setRelay(true);
+ int shape = random.nextInt(4);
+ if (shape == 0) funder.createTx(config.addDestination(randomAddress(random), randomAmount(random)));
+ else if (shape == 1) walletRpc.createTx(config.addDestination(funder.getPrimaryAddress(), randomAmount(random)));
+ else {
+ for (int i = random.nextInt(3); i >= 0; i--) config.addDestination(randomAddress(random), randomAmount(random));
+ walletRpc.createTx(config);
+ }
+ StartMining.generateBlocks(1);
+ }
+ mineTo(TestUtils.MINING_ADDRESS, FIXTURE_HEIGHT);
+ } finally {
+ funder.close(true);
+ TestUtils.stopWalletRpcProcess(funder);
+ }
+ }
+
+ private static String randomAddress(Random random) {
+ return walletRpc.getAddress(random.nextInt(4), random.nextInt(3));
+ }
+
+ private static BigInteger randomAmount(Random random) {
+ return TestUtils.MAX_FEE.multiply(BigInteger.valueOf(random.nextInt(20) + 1));
+ }
+}
### src/test/java/utils/Scratchpad.java
@@ -27,7 +27,7 @@ public static void main(String[] args) {
// create wallet from seed on mainnet
MoneroDaemon daemon = new MoneroDaemonRpc("http://xmr-node.cakewallet.com:18081");
MoneroWallet walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig()
- .setPath("./test_wallets/" + UUID.randomUUID().toString()) // leave blank for in-memory wallet
+ .setPath(TestUtils.TEST_WALLETS_DIR + "/" + UUID.randomUUID().toString()) // leave blank for in-memory wallet
.setPassword("abctesting123")
.setNetworkType(MoneroNetworkType.MAINNET)
.setServerUri("http://xmr-node.cakewallet.com:18081")
### src/test/java/utils/StartMining.java
@@ -1,41 +1,61 @@
package utils;
-import common.utils.GenUtils;
-import monero.daemon.MoneroDaemon;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
/**
- * Utility class to start mining.
+ * Mines regtest blocks on demand or one per block period in the background.
*/
public class StartMining {
- public static void main(String[] args) {
+ private static ScheduledExecutorService miner;
+
+ public static void main(String[] args) throws InterruptedException {
startMining();
+ Thread.currentThread().join();
+ }
+
+ public static void generateBlocks(long numBlocks) {
+ generateBlocks(TestUtils.MINING_ADDRESS, numBlocks);
+ }
+
+ public static void generateBlocks(String address, long numBlocks) {
+ if (numBlocks <= 0) return;
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("wallet_address", address);
+ params.put("amount_of_blocks", numBlocks);
+ TestUtils.getDaemonRpc().getRpcConnection().sendJsonRequest("generateblocks", params);
}
public static void mineToHeight(long height) {
- MoneroDaemon daemon = TestUtils.getDaemonRpc();
- if (daemon.getHeight() >= height) return;
- boolean startedMining = false;
- if (!daemon.getMiningStatus().isActive()) {
- try {
- startMining();
- startedMining = true;
- } catch (Exception e) { }
- }
- try {
- while (daemon.getHeight() < height) GenUtils.waitFor(TestUtils.SYNC_PERIOD_IN_MS);
- } finally {
- if (startedMining) daemon.stopMining();
- }
+ generateBlocks(height - TestUtils.getDaemonRpc().getHeight());
}
-
- public static void startMining() {
- startMining(1);
+
+ public static synchronized void startMining() {
+ if (miner != null) return;
+ miner = Executors.newSingleThreadScheduledExecutor(runnable -> {
+ Thread thread = new Thread(runnable);
+ thread.setDaemon(true);
+ return thread;
+ });
+ miner.scheduleWithFixedDelay(() -> {
+ try { generateBlocks(1); }
+ catch (Exception e) { System.err.println("Failed to mine block: " + e.getMessage()); }
+ }, 0, TestUtils.BLOCK_PERIOD_IN_MS, TimeUnit.MILLISECONDS);
+ }
+
+ public static synchronized void stopMining() {
+ if (miner == null) return;
+ miner.shutdown(); // a block being mined completes first
+ try { miner.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); }
+ catch (InterruptedException e) { throw new RuntimeException(e); }
+ miner = null;
}
-
- public static void startMining(long numThreads) {
- //TestUtils.getWalletRpc().startMining(numThreads, false, true);
- //TestUtils.getDaemonRpc().startMining("59dF9pSotECe1Fn4dBGZXWHYyNdo53rbZ7YYseu9jBKCf4c2cUzhuFVRH8HuD4wyaKTqtD3VF3F4eQe3Kzq342F5U8R4jeq", numThreads, false, false); // stagenet
- TestUtils.getDaemonRpc().startMining("9tsUiG9bwcU7oTbAdBwBk2PzxFtysge5qcEsHEpetmEKgerHQa1fDqH7a4FiquZmms7yM22jdifVAD7jAb2e63GSJMuhY75", numThreads, false, false); // testnet
+
+ public static synchronized boolean isMining() {
+ return miner != null;
}
}
### src/test/java/utils/StopMining.java
@@ -1,8 +0,0 @@
-package utils;
-
-public class StopMining {
-
- public static void main(String[] args) {
- TestUtils.getDaemonRpc().stopMining();
- }
-}
### src/test/java/utils/TestUtils.java
@@ -47,45 +47,52 @@ public class TestUtils {
}
// directory with monero binaries to test (monerod and monero-wallet-rpc)
- public static final String MONERO_BINS_DIR = "";
+ public static final String MONERO_BINS_DIR = System.getenv().getOrDefault("MONERO_BINS_DIR", "external/monero-cpp/external/monero-project/build/release/bin");
+
+ // directory with the chain and wallets of the regtest servers started by the tests
+ public static final String REGTEST_DIR = "./test_regtest";
// monero daemon rpc endpoint configuration (change per your configuration)
- public static final String DAEMON_RPC_URI = "localhost:28081";
- public static final String DAEMON_RPC_USERNAME = "";
- public static final String DAEMON_RPC_PASSWORD = "";
+ public static final int DAEMON_RPC_PORT = Integer.parseInt(System.getenv().getOrDefault("MONERO_DAEMON_RPC_PORT", "28881"));
+ public static final String DAEMON_RPC_URI = "http://127.0.0.1:" + DAEMON_RPC_PORT;
+ public static final String DAEMON_RPC_USERNAME = System.getenv().getOrDefault("MONERO_DAEMON_RPC_USERNAME", "");
+ public static final String DAEMON_RPC_PASSWORD = System.getenv().getOrDefault("MONERO_DAEMON_RPC_PASSWORD", "");
public static final String DAEMON_LOCAL_PATH = MONERO_BINS_DIR + "/monerod";
// monero wallet rpc configuration (change per your configuration)
- public static final int WALLET_RPC_PORT_START = 28084; // test wallet executables will bind to consecutive ports after these
+ public static final int WALLET_RPC_PORT_START = Integer.parseInt(System.getenv().getOrDefault("MONERO_WALLET_RPC_PORT", "28884")); // test wallet executables will bind to consecutive ports after these
public static final boolean WALLET_RPC_ZMQ_ENABLED = false;
public static final int WALLET_RPC_ZMQ_PORT_START = 58083;
public static final int WALLET_RPC_ZMQ_BIND_PORT_START = 48083; // TODO: zmq bind port necessary?
public static final boolean WALLET_RPC_PROXY_ENABLED = false;
public static final String WALLET_RPC_PROXY_URI = null;
- public static final String WALLET_RPC_USERNAME = "rpc_user";
- public static final String WALLET_RPC_PASSWORD = "abc123";
+ public static final String WALLET_RPC_USERNAME = System.getenv().getOrDefault("MONERO_WALLET_RPC_USERNAME", "rpc_user");
+ public static final String WALLET_RPC_PASSWORD = System.getenv().getOrDefault("MONERO_WALLET_RPC_PASSWORD", "abc123");
public static final String WALLET_RPC_ZMQ_DOMAIN = "127.0.0.1";
public static final String WALLET_RPC_DOMAIN = "localhost";
public static final String WALLET_RPC_URI = WALLET_RPC_DOMAIN + ":" + WALLET_RPC_PORT_START;
public static final String WALLET_RPC_ZMQ_URI = "tcp://" + WALLET_RPC_ZMQ_DOMAIN + ":" + WALLET_RPC_ZMQ_PORT_START;
public static final String WALLET_RPC_LOCAL_PATH = MONERO_BINS_DIR + "/monero-wallet-rpc";
- public static final String WALLET_RPC_LOCAL_WALLET_DIR = MONERO_BINS_DIR;
+ public static final String WALLET_RPC_LOCAL_WALLET_DIR = System.getenv().getOrDefault("MONERO_WALLET_RPC_DIR", REGTEST_DIR + "/wallet_rpc");
public static final String WALLET_RPC_ACCESS_CONTROL_ORIGINS = "http://localhost:8080"; // cors access from web browser
// test wallet config
public static final String WALLET_NAME = "test_wallet_1";
public static final String WALLET_PASSWORD = "supersecretpassword123";
- public static final String TEST_WALLETS_DIR = "./test_wallets";
+ public static final String TEST_WALLETS_DIR = System.getenv().getOrDefault("MONERO_TEST_WALLETS_DIR", REGTEST_DIR + "/wallet_full");
public static final String WALLET_FULL_PATH = TEST_WALLETS_DIR + "/" + WALLET_NAME;
// test wallet constants
public static final BigInteger MAX_FEE = BigInteger.valueOf(7500000).multiply(BigInteger.valueOf(10000));
- public static final MoneroNetworkType NETWORK_TYPE = MoneroNetworkType.TESTNET;
+ public static final MoneroNetworkType NETWORK_TYPE = MoneroNetworkType.MAINNET; // regtest uses mainnet addresses
public static final String LANGUAGE = "English";
public static final String SEED = "silk mocked cucumber lettuce hope adrenalin aching lush roles fuel revamp baptism wrist long tender teardrop midst pastry pigment equip frying inbound pinched ravine frying";
- public static final String ADDRESS = "A1y9sbVt8nqhZAVm3me1U18rUVXcjeNKuBd1oE2cTs8biA9cozPMeyYLhe77nPv12JA3ejJN3qprmREriit2fi6tJDi99RR";
- public static final long FIRST_RECEIVE_HEIGHT = 171; // NOTE: this value must be the height of the wallet's first tx for tests
+ public static final String ADDRESS = "4ARcPLqcrRjhZAVm3me1U18rUVXcjeNKuBd1oE2cTs8biA9cozPMeyYLhe77nPv12JA3ejJN3qprmREriit2fi6tJAPbWJu";
+ public static final String MINING_SEED = "wield dinner tipsy pepper laboratory zigzags evicted fowls entrance cigar ourselves onboard inkling cousin losing whole smog mops viewpoint highway skater hashing kept lawsuit highway"; // wallet mined to, which funds the test wallet's history
+ public static final String MINING_ADDRESS = "45L2BnYnjPe4K74PfyNLCg37UPr7GTeVcRaSQYVTNFw9XebBpTexBTFNzCMhHWM5ftFBFiQMbAAd5ZR5fRdjx67R3h5mhTY";
+ public static final long FIRST_RECEIVE_HEIGHT = 101; // NOTE: this value must be the height of the wallet's first tx for tests
public static final long SYNC_PERIOD_IN_MS = 5000; // period between wallet syncs in milliseconds
+ public static final long BLOCK_PERIOD_IN_MS = 2000; // period between blocks mined in the background
public static final String OFFLINE_SERVER_URI = "offline_server_uri"; // dummy server uri to remain offline because wallet2 connects to default if not given
public static final long AUTO_CONNECT_TIMEOUT_MS = 3000;
@@ -103,11 +110,17 @@ public class TestUtils {
// used to track wallet txs for tests
public static WalletTxTracker WALLET_TX_TRACKER = new WalletTxTracker();
+ // stop servers started by the tests when the JVM exits
+ static {
+ Runtime.getRuntime().addShutdownHook(new Thread(Regtest::stop));
+ }
+
/**
* Get a singleton instance of a monerod client.
*/
private static MoneroDaemonRpc daemonRpc;
public static MoneroDaemonRpc getDaemonRpc() {
+ Regtest.start();
if (daemonRpc == null) {
MoneroRpcConnection rpc = new MoneroRpcConnection(DAEMON_RPC_URI, DAEMON_RPC_USERNAME, DAEMON_RPC_PASSWORD);
daemonRpc = new MoneroDaemonRpc(rpc);
@@ -121,38 +134,39 @@ public static MoneroDaemonRpc getDaemonRpc() {
private static MoneroWalletRpc walletRpc;
public static MoneroWalletRpc getWalletRpc() {
if (walletRpc == null) {
+ Regtest.start();
// construct wallet rpc instance with daemon connection
MoneroRpcConnection rpc = new MoneroRpcConnection(WALLET_RPC_URI, WALLET_RPC_USERNAME, WALLET_RPC_PASSWORD, WALLET_RPC_ZMQ_ENABLED ? WALLET_RPC_ZMQ_URI : null, WALLET_RPC_PROXY_ENABLED ? WALLET_RPC_PROXY_URI : null);
walletRpc = new MoneroWalletRpc(rpc);
}
+ openTestWallet(walletRpc);
- // attempt to open test wallet
+ // sync and save wallet
+ walletRpc.sync();
+ walletRpc.save();
+ walletRpc.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
+
+ // return cached wallet rpc
+ return walletRpc;
+ }
+
+ /**
+ * Open the test wallet on a wallet server, creating it from the seed if it does not exist.
+ */
+ public static void openTestWallet(MoneroWalletRpc walletRpc) {
try {
walletRpc.openWallet(WALLET_NAME, WALLET_PASSWORD);
} catch (MoneroRpcError e) {
// -1 returned when wallet does not exist or fails to open e.g. it's already open by another application
- if (e.getCode() == -1) {
-
- // create wallet
- walletRpc.createWallet(new MoneroWalletConfig().setPath(WALLET_NAME).setPassword(WALLET_PASSWORD).setSeed(SEED).setRestoreHeight(FIRST_RECEIVE_HEIGHT));
- } else {
- throw e;
- }
+ if (e.getCode() != -1) throw e;
+ walletRpc.createWallet(new MoneroWalletConfig().setPath(WALLET_NAME).setPassword(WALLET_PASSWORD).setSeed(SEED).setRestoreHeight(FIRST_RECEIVE_HEIGHT));
}
// ensure we're testing the right wallet
assertEquals(TestUtils.SEED, walletRpc.getSeed());
assertEquals(TestUtils.ADDRESS, walletRpc.getPrimaryAddress());
-
- // sync and save wallet
- walletRpc.sync();
- walletRpc.save();
- walletRpc.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
-
- // return cached wallet rpc
- return walletRpc;
}
public static MoneroWalletRpc openWalletRpc(MoneroWalletConfig config) {
@@ -208,17 +222,21 @@ public static MoneroWalletRpc createWalletRpc(MoneroWalletConfig config) {
* Start a monero-wallet-rpc process bound to the next available port.
*/
public static Map<MoneroWalletRpc, Integer> WALLET_PORT_OFFSETS = new HashMap<MoneroWalletRpc, Integer>();
- public static MoneroWalletRpc startWalletRpcProcess() { return TestUtils.startWalletRpcProcess(null, null, null); }
+ public static MoneroWalletRpc startWalletRpcProcess() { return TestUtils.startWalletRpcProcess(DAEMON_RPC_URI, DAEMON_RPC_USERNAME, DAEMON_RPC_PASSWORD); }
public static MoneroWalletRpc startWalletRpcProcess(String daemonUri, String daemonUsername, String daemonPassword) {
// get next available offset of ports to bind to
int portOffset = 1;
while (WALLET_PORT_OFFSETS.values().contains(portOffset)) portOffset++;
+ new File(WALLET_RPC_LOCAL_WALLET_DIR).mkdirs();
+
// create command to start client with internal monero-wallet-rpc process
List<String> cmd = new ArrayList<String>(Arrays.asList(
TestUtils.WALLET_RPC_LOCAL_PATH,
- "--" + TestUtils.NETWORK_TYPE.toString().toLowerCase(),
+ "--allow-mismatched-daemon-version",
+ "--daemon-ssl", "disabled",
+ "--rpc-ssl", "disabled",
"--rpc-bind-port", "" + (TestUtils.WALLET_RPC_PORT_START + portOffset),
"--rpc-login", TestUtils.WALLET_RPC_USERNAME + ":" + TestUtils.WALLET_RPC_PASSWORD,
"--wallet-dir", TestUtils.WALLET_RPC_LOCAL_WALLET_DIR,
@@ -264,6 +282,7 @@ public static void stopWalletRpcProcess(MoneroWalletRpc walletRpc) {
private static MoneroWalletFull walletFull;
public static MoneroWalletFull getWalletFull() {
if (walletFull == null || walletFull.isClosed()) {
+ Regtest.start();
// create wallet from seed if it doesn't exist
if (!MoneroWalletFull.walletExists(WALLET_FULL_PATH)) {
@@ -274,14 +293,14 @@ public static MoneroWalletFull getWalletFull() {
// create wallet with connection
MoneroRpcConnection daemonConnection = new MoneroRpcConnection(DAEMON_RPC_URI, DAEMON_RPC_USERNAME, DAEMON_RPC_PASSWORD);
- walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_FULL_PATH).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(NETWORK_TYPE).setSeed(TestUtils.SEED).setServer(daemonConnection).setRestoreHeight(FIRST_RECEIVE_HEIGHT));
+ walletFull = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(TestUtils.WALLET_FULL_PATH).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(NETWORK_TYPE).setRegtest(true).setSeed(TestUtils.SEED).setServer(daemonConnection).setRestoreHeight(FIRST_RECEIVE_HEIGHT));
assertEquals(TestUtils.FIRST_RECEIVE_HEIGHT, walletFull.getRestoreHeight());
assertEquals(daemonConnection, walletFull.getDaemonConnection());
}
// otherwise open existing wallet and update daemon connection
else {
- walletFull = MoneroWalletFull.openWallet(WALLET_FULL_PATH, WALLET_PASSWORD, TestUtils.NETWORK_TYPE);
+ walletFull = MoneroWalletFull.openWallet(new MoneroWalletConfig().setPath(WALLET_FULL_PATH).setPassword(WALLET_PASSWORD).setNetworkType(NETWORK_TYPE).setRegtest(true));
walletFull.setDaemonConnection(TestUtils.getDaemonRpc().getRpcConnection());
}
@@ -307,6 +326,7 @@ public static MoneroWalletFull getWalletFull() {
* @return the created wallet
*/
public static MoneroWalletFull createWalletGroundTruth(MoneroNetworkType networkType, String seed, Long startHeight, Long restoreHeight) {
+ Regtest.start();
// create directory for test wallets if it doesn't exist
File testWalletsDir = new File(TestUtils.TEST_WALLETS_DIR);
@@ -315,7 +335,7 @@ public static MoneroWalletFull createWalletGroundTruth(MoneroNetworkType network
// create ground truth wallet
MoneroRpcConnection daemonConnection = new MoneroRpcConnection(DAEMON_RPC_URI, DAEMON_RPC_USERNAME, DAEMON_RPC_PASSWORD);
String path = TestUtils.TEST_WALLETS_DIR + "/gt_wallet_" + System.currentTimeMillis();
- MoneroWalletFull gtWallet = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(networkType).setSeed(seed).setServer(daemonConnection).setRestoreHeight(restoreHeight));
+ MoneroWalletFull gtWallet = MoneroWalletFull.createWallet(new MoneroWalletConfig().setPath(path).setPassword(TestUtils.WALLET_PASSWORD).setNetworkType(networkType).setRegtest(true).setSeed(seed).setServer(daemonConnection).setRestoreHeight(restoreHeight));
assertEquals(restoreHeight == null ? 0 : (long) restoreHeight, gtWallet.getRestoreHeight());
gtWallet.sync(startHeight, new WalletSyncPrinter());
gtWallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
### src/test/java/utils/WalletTxTracker.java
@@ -5,7 +5,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import monero.daemon.MoneroDaemon;
-import monero.daemon.model.MoneroMiningStatus;
import monero.daemon.model.MoneroTx;
import monero.wallet.MoneroWallet;
import monero.wallet.model.MoneroTxQuery;
@@ -73,21 +72,16 @@ private void waitForTxsToClear(boolean clearFromWallet, MoneroWallet... wallets)
// break if no txs to wait for
if (txHashesPool.isEmpty()) {
- if (miningStarted) daemon.stopMining(); // stop mining if started mining
+ if (miningStarted) StartMining.stopMining(); // stop mining if started mining
break;
}
// log message and start mining if first iteration
if (isFirst) {
isFirst = false;
System.out.println("Waiting for wallet txs to clear from the pool in order to fully sync and avoid double spend attempts: " + txHashesPool);
- MoneroMiningStatus miningStatus = daemon.getMiningStatus();
- if (!miningStatus.isActive()) {
- try {
- StartMining.startMining();
- miningStarted = true;
- } catch (Exception e) { } // no problem
- }
+ miningStarted = !StartMining.isMining();
+ StartMining.startMining();
}
// sleep for sync period
@@ -107,14 +101,8 @@ public BigInteger waitForUnlockedBalance(MoneroWallet wallet, Integer accountInd
if (unlockedBalance.compareTo(minAmount) > 0) return unlockedBalance;
// start mining
- MoneroDaemon daemon = TestUtils.getDaemonRpc();
- boolean miningStarted = false;
- if (!daemon.getMiningStatus().isActive()) {
- try {
- StartMining.startMining();
- miningStarted = true;
- } catch (Exception err) { }
- }
+ boolean miningStarted = !StartMining.isMining();
+ StartMining.startMining();
// wait for unlocked balance // TODO: promote to MoneroWallet interface?
System.out.println("Waiting for unlocked balance");
@@ -125,7 +113,7 @@ public BigInteger waitForUnlockedBalance(MoneroWallet wallet, Integer accountInd
}
// stop mining if started
- if (miningStarted) daemon.stopMining();
+ if (miningStarted) StartMining.stopMining();
return unlockedBalance;
}
}
\ No newline at end of fileWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.