Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add multiple wallet recovery from peer #3240

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions applications/daily_tests/automatic_recovery_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
10 changes: 7 additions & 3 deletions applications/daily_tests/cron_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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(
Expand All @@ -52,7 +53,9 @@ async function runWalletRecoveryTest() {
blockRate,
"blocks/min).",
recoveredAmount,
"µT recovered."
"µT recovered for ",
instances,
" instance(s)."
);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions applications/daily_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
},
"author": "",
"license": "ISC",
"devDependencies": {
}
"devDependencies": {}
}
18 changes: 18 additions & 0 deletions integration_tests/features/WalletRecovery.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NumWallets> wallets connected to all seed nodes
When I wait for <NumWallets> wallets to have at least 55000000000 uT
Then Wallet WALLET_A and <NumWallets> wallets have the same balance
@critical
Examples:
| NumWallets |
| 1 |
| 2 |
| 5 |
| 10 |

# fails often on circle CI
@critical @flaky
Scenario: Recover one-sided payments
Expand Down
72 changes: 72 additions & 0 deletions integration_tests/features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down