From 2d732484f00c878c949c0e6edf77799030c8515d Mon Sep 17 00:00:00 2001 From: striderDM <51991544+StriderDM@users.noreply.github.com> Date: Tue, 24 Aug 2021 14:38:39 +0200 Subject: [PATCH] tests: Added multiple wallet recovery from peer --- Cargo.lock | 2 +- .../daily_tests/automatic_recovery_test.js | 42 ++++++----- applications/daily_tests/cron_jobs.js | 10 ++- applications/daily_tests/package.json | 3 +- .../features/WalletRecovery.feature | 18 +++++ integration_tests/features/support/steps.js | 72 +++++++++++++++++++ 6 files changed, 125 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9dfd279170..188850e8e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5060,7 +5060,7 @@ dependencies = [ [[package]] name = "tari_wallet_ffi" -version = "0.17.3" +version = "0.17.4" dependencies = [ "chrono", "env_logger 0.7.1", diff --git a/applications/daily_tests/automatic_recovery_test.js b/applications/daily_tests/automatic_recovery_test.js index 66c0a72289..538827f226 100644 --- a/applications/daily_tests/automatic_recovery_test.js +++ b/applications/daily_tests/automatic_recovery_test.js @@ -20,25 +20,35 @@ async function main() { type: "string", default: "logs/wallet.log", }) + .option("num-wallets", { + alias: "n", + description: "The number of times a wallet instance is recovered", + type: "integer", + default: 1, + }) .help() .alias("help", "h").argv; - const { identity, timeDiffMinutes, height, blockRate, recoveredAmount } = - await run(argv); - - console.log( - "Wallet (Pubkey:", - identity.public_key, - ") recovered to a block height of", - height, - "completed in", - timeDiffMinutes, - "minutes (", - blockRate, - "blocks/min).", - recoveredAmount, - "µT recovered." - ); + for (let i = 0; i < argv.numWallets; i++) { + let { identity, timeDiffMinutes, height, blockRate, recoveredAmount } = + await run(argv); + + console.log( + "Wallet (Pubkey:", + identity.public_key, + ") recovered to a block height of", + height, + "completed in", + timeDiffMinutes, + "minutes (", + blockRate, + "blocks/min).", + recoveredAmount, + "µT recovered for instance ", + i, + "." + ); + } } async function run(options = {}) { diff --git a/applications/daily_tests/cron_jobs.js b/applications/daily_tests/cron_jobs.js index c822e36eac..f723545659 100644 --- a/applications/daily_tests/cron_jobs.js +++ b/applications/daily_tests/cron_jobs.js @@ -27,7 +27,7 @@ function notify(message) { } } -async function runWalletRecoveryTest() { +async function runWalletRecoveryTest(instances) { notify("🚀 Wallet recovery check has begun 🚀"); const LOG_FILE = "./logs/wallet-recovery-test.log"; @@ -39,6 +39,7 @@ async function runWalletRecoveryTest() { 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( @@ -52,7 +53,9 @@ async function runWalletRecoveryTest() { blockRate, "blocks/min).", recoveredAmount, - "µT recovered." + "µT recovered for ", + instances, + " instance(s)." ); } catch (err) { console.error(err); @@ -95,7 +98,8 @@ ${logLines.join("\n")} } // ------------------------- CRON ------------------------- // -new CronJob("0 7 * * *", runWalletRecoveryTest).start(); +new CronJob("0 7 * * *", runWalletRecoveryTest(1)).start(); +new CronJob("0 7 * * *", runWalletRecoveryTest(5)).start(); new CronJob("0 6 * * *", () => runBaseNodeSyncTest(SyncType.Archival)).start(); new CronJob("30 6 * * *", () => runBaseNodeSyncTest(SyncType.Pruned)).start(); diff --git a/applications/daily_tests/package.json b/applications/daily_tests/package.json index 2d1642fc3a..160275830d 100644 --- a/applications/daily_tests/package.json +++ b/applications/daily_tests/package.json @@ -15,6 +15,5 @@ }, "author": "", "license": "ISC", - "devDependencies": { - } + "devDependencies": {} } diff --git a/integration_tests/features/WalletRecovery.feature b/integration_tests/features/WalletRecovery.feature index f52be08cce..bf6147472d 100644 --- a/integration_tests/features/WalletRecovery.feature +++ b/integration_tests/features/WalletRecovery.feature @@ -20,6 +20,24 @@ Feature: Wallet Recovery Then all nodes are at height 20 Then I wait for wallet WALLET_C to have at least 100000 uT + Scenario Outline: Multiple Wallet recovery from seed node + Given I have a seed node NODE + And I have wallet WALLET_A connected to all seed nodes + And I have a merge mining proxy PROXY connected to NODE and WALLET_A with default config + When I merge mine 15 blocks via PROXY + When I wait for wallet WALLET_A to have at least 55000000000 uT + Then all nodes are at height 15 + When I recover wallet WALLET_A into wallets connected to all seed nodes + When I wait for wallets to have at least 55000000000 uT + Then Wallet WALLET_A and wallets have the same balance + @critical + Examples: + | NumWallets | + | 1 | + | 2 | + | 5 | + | 10 | + # fails often on circle CI @critical @flaky Scenario: Recover one-sided payments diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index d89f25fd82..16fe92acd4 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -403,6 +403,78 @@ Given( } ); +Given( + /I recover wallet (.*) into (\d+) wallets connected to all seed nodes/, + { timeout: 120 * 1000 }, + async function (walletNameA, numwallets) { + const seedWords = this.getWallet(walletNameA).getSeedWords(); + for (let i = 1; i <= numwallets; i++) { + console.log( + "Recover " + + walletNameA + + " into wallet " + + i + + ", seed words:\n " + + seedWords + ); + const wallet = new WalletProcess( + i, + false, + {}, + this.logFilePathWallet, + seedWords + ); + wallet.setPeerSeeds([this.seedAddresses()]); + await wallet.startNew(); + this.addWallet(i, wallet); + let walletClient = await this.getWallet(i.toString()).connectClient(); + let walletInfo = await walletClient.identify(); + this.addWalletPubkey(wallet, walletInfo.public_key); + } + } +); + +Then( + /I wait for (\d+) wallets to have at least (\d+) uT/, + { timeout: 710 * 1000 }, + async function (numwallets, amount) { + for (let i = 1; i <= numwallets; i++) { + const walletClient = await this.getWallet(i.toString()).connectClient(); + console.log("\n"); + console.log( + "Waiting for wallet " + i + " balance to be at least " + amount + " uT" + ); + + await waitFor( + async () => walletClient.isBalanceAtLeast(amount), + true, + 700 * 1000, + 5 * 1000, + 5 + ); + consoleLogBalance(await walletClient.getBalance()); + if (!(await walletClient.isBalanceAtLeast(amount))) { + console.log("Balance not adequate!"); + } + expect(await walletClient.isBalanceAtLeast(amount)).to.equal(true); + } + } +); + +Then( + /Wallet (.*) and (\d+) wallets have the same balance/, + { timeout: 120 * 1000 }, + async function (wallet, numwallets) { + const walletClient = await this.getWallet(wallet).connectClient(); + let balance = await walletClient.getBalance(); + for (let i = 1; i <= numwallets; i++) { + const walletClient2 = await this.getWallet(i.toString()).connectClient(); + let balance2 = await walletClient2.getBalance(); + expect(balance === balance2); + } + } +); + When(/I stop wallet (.*)/, async function (walletName) { let wallet = this.getWallet(walletName); await wallet.stop();