tests: mine to height before checking sync notifications
What changed, and why it matters
This commit only changes test code. It refactors how a Monero wallet test waits for a new block by introducing a helper that mines until a specific blockchain height is reached, instead of starting mining and waiting for the next block in the test itself. There is no change to production wallet or daemon code, and no security fix or vulnerability is visible in the diff.
No security action needed. Treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies TestMoneroWalletFull.java and StartMining.java. It replaces inline mining start/stop logic in a sync-notification test with a new StartMining.mineToHeight(long) utility. The helper starts mining if not already active, polls daemon.getHeight() until the target height is reached, then stops mining only if it started it. This is a test reliability/robustness improvement; no cryptographic, RPC, or wallet logic is altered.
Changed components
src/test/java/TestMoneroWalletFull.javasrc/test/java/utils/StartMining.javaInspect captured patch +33 / −27
### src/test/java/TestMoneroWalletFull.java
@@ -666,37 +666,23 @@ private void testSyncSeed(Long startHeight, Long restoreHeight, boolean skipGtCo
if (testPostSyncNotifications) {
// start automatic syncing
+ long walletHeight = wallet.getHeight();
wallet.startSyncing(TestUtils.SYNC_PERIOD_IN_MS);
- // attempt to start mining to push the network along // TODO: TestUtils.tryStartMining() : reqId, TestUtils.tryStopMining(reqId)
- boolean startedMining = false;
- try {
- StartMining.startMining();
- startedMining = true;
- } catch (Exception e) {
- // no problem
- }
-
+ System.out.println("Waiting for next block to test post sync notifications");
+ StartMining.mineToHeight(walletHeight + 1);
+
+ // ensure wallet has time to detect new block
try {
-
- // wait for block
- System.out.println("Waiting for next block to test post sync notifications");
- daemon.waitForNextBlockHeader();
-
- // ensure wallet has time to detect new block
- try {
- TimeUnit.MILLISECONDS.sleep(TestUtils.SYNC_PERIOD_IN_MS + 3000); // sleep for wallet interval + time to sync
- } catch (InterruptedException e) {
- e.printStackTrace();
- throw new RuntimeException(e.getMessage());
- }
-
- // test that wallet listener's onSyncProgress() and onNewBlock() were invoked after previous completion
- assertTrue(walletSyncTester.getOnSyncProgressAfterDone());
- assertTrue(walletSyncTester.getOnNewBlockAfterDone());
- } finally {
- if (startedMining) wallet.stopMining();
+ TimeUnit.MILLISECONDS.sleep(TestUtils.SYNC_PERIOD_IN_MS + 3000); // sleep for wallet interval + time to sync
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
}
+
+ // test that wallet listener's onSyncProgress() and onNewBlock() were invoked after previous completion
+ assertTrue(walletSyncTester.getOnSyncProgressAfterDone());
+ assertTrue(walletSyncTester.getOnNewBlockAfterDone());
}
} finally {
if (walletGt != null) walletGt.close(true);
### src/test/java/utils/StartMining.java
@@ -1,5 +1,8 @@
package utils;
+import common.utils.GenUtils;
+import monero.daemon.MoneroDaemon;
+
/**
* Utility class to start mining.
*/
@@ -8,6 +11,23 @@ public class StartMining {
public static void main(String[] args) {
startMining();
}
+
+ 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();
+ }
+ }
public static void startMining() {
startMining(1);Why this scored 14/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.