Skip to content

Commit 73913ef

Browse files
committed
remove local var
Signed-off-by: yasenltd <yasenltd@gmail.com>
1 parent f1f2142 commit 73913ef

File tree

2 files changed

+51
-61
lines changed

2 files changed

+51
-61
lines changed

automation/pages/TransactionPage.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ export class TransactionPage extends BasePage {
2626
private readonly generatedPublicKeys: string[]; // Store generated public keys
2727
public generatedAccounts: string[]; // Store generated accounts from create account transaction
2828
private readonly generatedFiles: Record<string, { text: string; publicKey: string }>; // Store generated files from create file transaction with key-value pairs
29+
private hasLoggedFirstCreateTransactionPayer: boolean;
2930

3031
constructor(window: Page) {
3132
super(window);
3233
this.generatedPublicKeys = [];
3334
this.generatedAccounts = [];
3435
this.generatedFiles = {};
36+
this.hasLoggedFirstCreateTransactionPayer = false;
3537
}
3638

3739
/* Selectors */
@@ -178,7 +180,7 @@ export class TransactionPage extends BasePage {
178180
async verifyConfirmTransactionInformation(typeTransaction: string) {
179181
await this.window.waitForSelector(
180182
'[data-testid="modal-confirm-transaction"][style*="display: block"]',
181-
{ state: 'visible', timeout: 10000 },
183+
{ state: 'visible', timeout: this.LONG_TIMEOUT * 2 },
182184
);
183185
const regex = /^\d+\.\d+\.\d+@\d+\.\d+$/;
184186
const transactionId = await this.getText(this.textTransactionIdSelector);
@@ -244,7 +246,7 @@ export class TransactionPage extends BasePage {
244246
} catch (error) {
245247
if (attempt === 2) throw error;
246248
await this.window.keyboard.press('Escape');
247-
await this.window.waitForTimeout(300);
249+
await this.window.waitForTimeout(this.SHORT_TIMEOUT);
248250
}
249251
}
250252
}
@@ -263,38 +265,60 @@ export class TransactionPage extends BasePage {
263265

264266
async clickOnCreateAccountTransaction() {
265267
await this.click(this.createAccountSublinkSelector);
268+
await this.logPayerOnFirstCreateTransactionScreen();
266269
}
267270

268271
async clickOnDeleteAccountTransaction() {
269272
await this.click(this.deleteAccountSublinkSelector);
273+
await this.logPayerOnFirstCreateTransactionScreen();
270274
}
271275

272276
async clickOnUpdateAccountTransaction() {
273277
await this.click(this.updateAccountSublinkSelector);
278+
await this.logPayerOnFirstCreateTransactionScreen();
274279
}
275280

276281
async clickOnApproveAllowanceTransaction() {
277282
await this.click(this.allowanceSublinkSelector);
283+
await this.logPayerOnFirstCreateTransactionScreen();
278284
}
279285

280286
async clickOnTransferTokensTransaction() {
281287
await this.click(this.transferTokensSublinkSelector);
288+
await this.logPayerOnFirstCreateTransactionScreen();
282289
}
283290

284291
async clickOnFileCreateTransaction() {
285292
await this.click(this.createFileSublinkSelector);
293+
await this.logPayerOnFirstCreateTransactionScreen();
286294
}
287295

288296
async clickOnReadCreateTransaction() {
289297
await this.click(this.readFileSublinkSelector);
298+
await this.logPayerOnFirstCreateTransactionScreen();
290299
}
291300

292301
async clickOnUpdateFileSublink() {
293302
await this.click(this.updateFileSublinkSelector);
303+
await this.logPayerOnFirstCreateTransactionScreen();
294304
}
295305

296306
async clickOnAppendFileSublink() {
297307
await this.click(this.appendFileSublinkSelector);
308+
await this.logPayerOnFirstCreateTransactionScreen();
309+
}
310+
311+
private async logPayerOnFirstCreateTransactionScreen() {
312+
if (this.hasLoggedFirstCreateTransactionPayer) {
313+
return;
314+
}
315+
316+
await this.waitForElementToBeVisible(this.payerAccountInputSelector, this.LONG_TIMEOUT);
317+
await this.window.waitForTimeout(this.SHORT_TIMEOUT);
318+
319+
const payerValue = await this.getTextFromInputField(this.payerAccountInputSelector);
320+
console.log('[first-create-transaction-screen] payer account ID:', payerValue);
321+
this.hasLoggedFirstCreateTransactionPayer = true;
298322
}
299323

300324
async verifyTransactionExists(transactionId: string, transactionType: string) {
@@ -796,18 +820,14 @@ export class TransactionPage extends BasePage {
796820
await this.click(this.backButtonSelector, null, this.LONG_TIMEOUT * 2);
797821
}
798822

799-
async clickOnSignAndSubmitButton(forceLocalNetPayerHandling = true) {
823+
async clickOnSignAndSubmitButton(forceLocalNetPayerHandling = false) {
800824
// For LOCALNET, or when explicitly requested, use the LOCALNET payer fallback.
801825
// Mirror Node doesn't return accounts there, so Payer ID is empty.
802826
if (forceLocalNetPayerHandling || process.env.ENVIRONMENT?.toUpperCase() === 'LOCALNET') {
803827
const currentValue = await this.getTextFromInputField(this.payerAccountInputSelector);
804828
console.log('Current payer account ID:', currentValue);
805-
if (forceLocalNetPayerHandling || !currentValue || currentValue.trim() === '') {
806-
console.log(
807-
forceLocalNetPayerHandling
808-
? 'Force filling payer account ID using LOCALNET fallback'
809-
: 'Filling in payer account ID using LOCALNET fallback',
810-
);
829+
if (!currentValue || currentValue.trim() === '') {
830+
console.log('Filling in payer account ID using LOCALNET fallback');
811831
await this.fillInPayerAccountId(LOCALNET_PAYER_ACCOUNT_ID);
812832
const payerInput = this.getElement(this.payerAccountInputSelector);
813833
await payerInput.blur();

automation/utils/util.ts

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import { SettingsPage } from '../pages/SettingsPage.js';
66
import * as fsp from 'fs/promises';
77
import _ from 'lodash';
88
import Diff from 'deep-diff';
9-
import { TransactionPage } from '../pages/TransactionPage.js';
10-
import { generateEd25519KeyPair } from './keyUtil.js';
119

1210
/**
13-
* Localnet payer account ID corresponding to the PRIVATE_KEY in .env
11+
* Fixed LOCALNET payer account used by automation.
1412
* Solo account 0.0.1022 with key: 44162cd9b9a2f5582bd13b43cfd8be3bc20b8a81ee77f6bf77391598bcfbae4c
15-
* Used as fallback if Mirror Node auto-population fails
1613
*/
1714
export const LOCALNET_PAYER_ACCOUNT_ID = '0.0.1022';
1815

@@ -76,10 +73,14 @@ export async function closeApp(app: ElectronApplication) {
7673
await app.close();
7774
}
7875

76+
const LOCALNET_PK_KEY = '44162cd9b9a2f5582bd13b43cfd8be3bc20b8a81ee77f6bf77391598bcfbae4c';
7977
const LOCALNET_OPERATOR_KEY = '0x91132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137'; // genesis account key
80-
const LOCALNET_OPERATOR_ACCOUNT = '0.0.2'; // genesis account ID
8178

8279
export function getPrivateKeyEnv(): string | null {
80+
if (getNetworkEnv().toUpperCase() === 'LOCALNET') {
81+
return LOCALNET_PK_KEY;
82+
}
83+
8384
return process.env.PRIVATE_KEY && process.env.PRIVATE_KEY !== ''
8485
? process.env.PRIVATE_KEY
8586
: null;
@@ -96,7 +97,7 @@ export function getNetworkEnv(): string {
9697
export async function setupEnvironmentForTransactions(
9798
window: Page,
9899
privateKey = getPrivateKeyEnv(),
99-
isLocalNet = true,
100+
isLocalNet = false,
100101
): Promise<string | null> {
101102
const network = getNetworkEnv().toUpperCase();
102103
let resolvedPrivateKey = privateKey;
@@ -110,58 +111,27 @@ export async function setupEnvironmentForTransactions(
110111
'[setupEnvironmentForTransactions] branch: LOCALNET',
111112
isLocalNet ? '(forced)' : '(from ENVIRONMENT)',
112113
);
114+
const operatorPrivateKey = getOperatorKeyEnv();
115+
const isExplicitOperatorKey =
116+
resolvedPrivateKey !== null && resolvedPrivateKey === operatorPrivateKey;
117+
if (isExplicitOperatorKey) {
118+
console.log('[setupEnvironmentForTransactions] LOCALNET path: importing explicit operator key');
119+
} else {
120+
resolvedPrivateKey = LOCALNET_PK_KEY;
121+
console.log(
122+
'[setupEnvironmentForTransactions] LOCALNET path: importing fixed payer key for 0.0.1022',
123+
);
124+
}
125+
113126
const settingsPage = new SettingsPage(window);
114127
await settingsPage.clickOnSettingsButton();
115128
await settingsPage.clickOnLocalNodeTab();
116129
await settingsPage.clickOnKeysTab();
117130
await settingsPage.clickOnImportButton();
118131
await settingsPage.clickOnED25519DropDown();
119-
120-
if (resolvedPrivateKey === null) {
121-
console.log(
122-
'[setupEnvironmentForTransactions] LOCALNET path: no private key configured, creating payer account',
123-
);
124-
// The private key is not configured so we are going to create a payer account using the
125-
// operator key, so we need to:
126-
// - import the operator key
127-
// - generate a key pair for the payer account
128-
// - create the payer account using operator as payer, and transfer 10000 HBARs to it
129-
// - delete the operator key
130-
// - import the payer key which will further be used for all transactions
131-
await settingsPage.fillInED25519PrivateKey(getOperatorKeyEnv());
132-
await settingsPage.fillInED25519Nickname('Operator Account');
133-
await settingsPage.clickOnED25519ImportButton();
134-
135-
const { publicKey, privateKey: generatedPrivateKey } = generateEd25519KeyPair();
136-
137-
const transactionPage = new TransactionPage(window);
138-
await transactionPage.clickOnTransactionsMenuButton();
139-
await transactionPage.createNewAccount({
140-
initialFunds: '10000',
141-
publicKey: publicKey,
142-
payerAccountId: LOCALNET_OPERATOR_ACCOUNT,
143-
});
144-
145-
await settingsPage.clickOnSettingsButton();
146-
await settingsPage.clickOnKeysTab();
147-
await settingsPage.clickOnDeleteButtonAtIndex(1);
148-
await settingsPage.clickOnDeleteKeyPairButton();
149-
150-
await settingsPage.clickOnImportButton();
151-
await settingsPage.clickOnED25519DropDown();
152-
await settingsPage.fillInED25519PrivateKey(generatedPrivateKey);
153-
await settingsPage.fillInED25519Nickname('Payer Account');
154-
await settingsPage.clickOnED25519ImportButton();
155-
resolvedPrivateKey = generatedPrivateKey;
156-
} else {
157-
console.log(
158-
'[setupEnvironmentForTransactions] LOCALNET path: importing configured payer key',
159-
);
160-
// The private key is configured so this is the one which will be used as payer for all transactions
161-
await settingsPage.fillInED25519PrivateKey(resolvedPrivateKey);
162-
await settingsPage.fillInED25519Nickname('Payer Account');
163-
await settingsPage.clickOnED25519ImportButton();
164-
}
132+
await settingsPage.fillInED25519PrivateKey(resolvedPrivateKey ?? '');
133+
await settingsPage.fillInED25519Nickname('Payer Account');
134+
await settingsPage.clickOnED25519ImportButton();
165135
} else if (network === 'TESTNET') {
166136
console.log('[setupEnvironmentForTransactions] branch: TESTNET');
167137
const settingsPage = new SettingsPage(window);

0 commit comments

Comments
 (0)