Skip to content

Commit

Permalink
fix: prevent initial run of wallet recovery
Browse files Browse the repository at this point in the history
When running cron, the two walet receovery tests would run immediately
and not be awaited (Promises are eager in js)
- Fix " ReferenceError: Cannot access recoveredAmount before
  initialization"
  • Loading branch information
sdbondi committed Sep 2, 2021
1 parent cedb1d4 commit e0b2001
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions applications/daily_tests/automatic_recovery_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ async function run(options = {}) {
process: wallet.ps,
outputStream: logfile,
onData: (data) => {
let successLog = data.match(RECOVERY_COMPLETE_REGEXP);
let recoveredAmount = data.match(RECOVERY_WORTH_REGEXP);
if (successLog && recoveredAmount) {
let recoveredAmount = parseInt(recoveredAmount[1]);
if (recoveredAmount[2] === "T") {
let scannedMatch = data.match(RECOVERY_COMPLETE_REGEXP);
let recoveredAmountMatch = data.match(RECOVERY_WORTH_REGEXP);
if (scannedMatch && recoveredAmountMatch) {
let recoveredAmount = parseInt(recoveredAmountMatch[1]);
if (recoveredAmountMatch[2] === "T") {
// convert to micro tari
recoveredAmount *= 1000000;
}
return {
height: parseInt(height[1]),
recoveredAmount: parseInt(recoveredAmount[1]),
numScanned: parseInt(scannedMatch[1]),
recoveredAmount,
};
}

Expand All @@ -114,13 +114,13 @@ async function run(options = {}) {

await wallet.stop();

const block_rate = recoveryResult.height / timeDiffMinutes;
const scannedRate = recoveryResult.numScanned / timeDiffMinutes;

return {
identity: id,
height: recoveryResult.height,
numScanned: recoveryResult.numScanned,
timeDiffMinutes,
blockRate: block_rate.toFixed(2),
scannedRate: scannedRate.toFixed(2),
recoveredAmount: recoveryResult.recoveredAmount,
};
} catch (err) {
Expand Down
27 changes: 16 additions & 11 deletions applications/daily_tests/cron_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,28 @@ async function runWalletRecoveryTest(instances) {
await emptyFile(LOG_FILE);

try {
const { identity, timeDiffMinutes, height, blockRate, recoveredAmount } =
await walletRecoveryTest({
seedWords:
"spare man patrol essay divide hollow trip visual actress sadness country hungry toy blouse body club depend capital sleep aim high recycle crystal abandon",
log: LOG_FILE,
numWallets: instances,
});
const {
identity,
timeDiffMinutes,
numScanned,
scannedRate,
recoveredAmount,
} = await walletRecoveryTest({
seedWords:
"spare man patrol essay divide hollow trip visual actress sadness country hungry toy blouse body club depend capital sleep aim high recycle crystal abandon",
log: LOG_FILE,
numWallets: instances,
});

notify(
"🙌 Wallet (Pubkey:",
identity.public_key,
") recovered to a block height of",
height,
numScanned,
"completed in",
timeDiffMinutes,
"minutes (",
blockRate,
scannedRate,
"blocks/min).",
recoveredAmount,
"µT recovered for ",
Expand Down Expand Up @@ -121,8 +126,8 @@ ${logLines.join("\n")}
}

// ------------------------- CRON ------------------------- //
new CronJob("0 7 * * *", runWalletRecoveryTest(1)).start();
new CronJob("0 7 * * *", runWalletRecoveryTest(5)).start();
new CronJob("0 7 * * *", () => runWalletRecoveryTest(1)).start();
new CronJob("30 7 * * *", () => runWalletRecoveryTest(5)).start();
new CronJob("0 6 * * *", () => runBaseNodeSyncTest(SyncType.Archival)).start();
new CronJob("30 6 * * *", () => runBaseNodeSyncTest(SyncType.Pruned)).start();

Expand Down

0 comments on commit e0b2001

Please sign in to comment.