-
Notifications
You must be signed in to change notification settings - Fork 176
/
index.js
113 lines (99 loc) · 4.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const assert = require('assert');
const {
connect,
keyStores: { InMemoryKeyStore },
utils: {
KeyPair,
format: { parseNearAmount }
}
} = require('near-api-js');
const { parseSeedPhrase } = require('near-seed-phrase');
const { webkit } = require('playwright');
const NETWORK_ID = 'default';
const BANK_SEED_PHRASE = process.env.BANK_SEED_PHRASE;
const BANK_ACCOUNT = process.env.BANK_ACCOUNT;
const TEST_ACCOUNT_SEED_PHRASE = process.env.TEST_ACCOUNT_SEED_PHRASE;
const HEADLESS = !['no', 'false'].includes(process.env.HEADLESS);
const ENABLE_ALERT = ['yes', 'true'].includes(process.env.ENABLE_ALERT);
const config = {
networkId: NETWORK_ID,
nodeUrl: process.env.NODE_URL || 'https://rpc.testnet.near.org',
walletUrl: process.env.WALLET_URL || 'https://wallet.testnet.near.org',
keyStore: new InMemoryKeyStore()
};
async function createIncident(accountId, error) {
const { api } = require('@pagerduty/pdjs');
const pd = api({ token: process.env.PAGERDUTY_API_KEY });
console.log('Creating incident on PagerDuty');
await pd.post('/incidents', {
data: {
incident: {
type: "incident",
title: "wallet e2e-tests failure",
service: {
id: "PJ9TV6C", // wallet
type: "service_reference"
},
assignments: [
{
assignee: {
id: "PM9MK7I", // [email protected]
type: "user_reference"
}
}
],
body: {
type: "incident_body",
details: `
Wallet e2e-tests suite has failed. See https://dashboard.render.com/cron/crn-bvrt6tblc6ct62bdjmig/logs for details.
Make sure that account recovery works well on https://wallet.near.org.
${accountId ? `Test account to check https://explorer.near.org/accounts/${accountId}` : ''}
${error.stack}
`
}
},
}
});
}
let lastTestAccountId;
(async () => {
const near = await connect(config);
const { keyStore } = config;
const bankKeyPair = KeyPair.fromString((await parseSeedPhrase(BANK_SEED_PHRASE)).secretKey);
await keyStore.setKey(NETWORK_ID, BANK_ACCOUNT, bankKeyPair);
const bankAccount = await near.account(BANK_ACCOUNT);
async function createTestAccount() {
const accountId = `test-account-${Date.now()}-${Math.floor(Math.random() * 1000) % 1000}.${bankAccount.accountId}`;
console.log('createTestAccount', accountId);
const seedPhrase = `${accountId} ${TEST_ACCOUNT_SEED_PHRASE}`;
const { secretKey } = await parseSeedPhrase(seedPhrase);
// TODO: Use the same seed phrase for all accounts to test recovery not picking up deleted accounts
const keyPair = KeyPair.fromString(secretKey);
await keyStore.setKey(NETWORK_ID, accountId, keyPair);
await bankAccount.createAccount(accountId, keyPair.publicKey, parseNearAmount('1.0'));
lastTestAccountId = accountId;
return near.account(accountId);
}
const testAccount1 = await createTestAccount();
try {
const browser = await webkit.launch({ headless: HEADLESS });
const page = await browser.newPage();
await page.goto(config.walletUrl + '/recover-seed-phrase');
const seedPhrase = `${testAccount1.accountId} ${TEST_ACCOUNT_SEED_PHRASE}`;
await page.fill('[name=seedPhrase]', seedPhrase);
await page.click('[type=submit]');
await page.waitForNavigation();
assert(page.url() === config.walletUrl + '/');
assert.strictEqual(await page.textContent('.user-name'), testAccount1.accountId);
await browser.close();
} finally {
console.log('Removing', testAccount1.accountId);
await testAccount1.deleteAccount(bankAccount.accountId);
}
})().catch(async e => {
console.error(e);
if (ENABLE_ALERT) {
await createIncident(lastTestAccountId, e);
}
process.exit(1);
});