From af7fd628cd16d83853fa5aad4bea7e83addc6423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bordalo?= Date: Wed, 20 Dec 2023 09:32:20 +0000 Subject: [PATCH] fix playwright tests --- playwright-tests/injected-script.spec.ts | 30 +++++++++++++----------- playwright-tests/popup.spec.ts | 22 ++++++++++------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/playwright-tests/injected-script.spec.ts b/playwright-tests/injected-script.spec.ts index 316c94c3..06b9ad3a 100644 --- a/playwright-tests/injected-script.spec.ts +++ b/playwright-tests/injected-script.spec.ts @@ -11,7 +11,7 @@ import { PASSWORD, } from './utils'; import { faucet } from '../test/_regtest'; -import type { Artifact} from '@ionio-lang/ionio'; +import type { Artifact } from '@ionio-lang/ionio'; import { Contract } from '@ionio-lang/ionio'; import { AccountType } from 'marina-provider'; import captchaArtifact from '../test/fixtures/customscript/transfer_with_captcha.ionio.json'; @@ -86,7 +86,7 @@ pwTest( const zkpLib = await require('@vulpemventures/secp256k1-zkp')(); - const ecpair = ECPairFactory(ecc) + const ecpair = ECPairFactory(ecc); const keyPair = ecpair.makeRandom(); const blindingKeyPair = ecpair.makeRandom(); @@ -97,7 +97,6 @@ pwTest( zkpLib ); - const contractScript = contract.scriptPubKey.toString('hex'); await pwExpect( provider.importScript('ionio', contractScript, blindingKeyPair.privateKey!.toString('hex')) @@ -126,7 +125,7 @@ pwTest( 'marina.signTransaction popup should display the correct amount of spent asset', async ({ page, extensionId, context }) => { await makeOnboardingRestore(page, extensionId); - await switchToRegtestNetwork(page, extensionId); + await switchToRegtestNetwork(page, extensionId); await page.goto(vulpemFaucetURL); let provider = new PlaywrightMarinaProvider(page); @@ -139,7 +138,7 @@ pwTest( if (!toFaucet.confidentialAddress) throw new Error('confidentialAddress is undefined'); await faucet(toFaucet.confidentialAddress, 1); // send 1 L-BTC to the address await page.goto(marinaURL(extensionId, 'popup.html')); - await page.waitForSelector('text=1 L-BTC'); + await page.waitForSelector('text=1.00 000 000 L-BTC'); await page.goto(vulpemFaucetURL); provider = new PlaywrightMarinaProvider(page); @@ -180,7 +179,7 @@ pwTest( const handleSignTransactionPopup = async () => { const popup = await context.waitForEvent('page'); await popup.waitForSelector(`text= L-BTC`); // wait for loading to finish - const value = popup.getByTestId(networks.regtest.assetHash) + const value = popup.getByTestId(networks.regtest.assetHash); pwExpect(value).toBeTruthy(); pwExpect(await value.innerText()).toEqual('0.999985'); await popup.getByRole('button', { name: 'Reject' }).click(); @@ -199,7 +198,7 @@ pwTest( 'marina.sendTransaction popup should display the correct amount of spent asset', async ({ page, extensionId, context }) => { await makeOnboardingRestore(page, extensionId); - await switchToRegtestNetwork(page, extensionId); + await switchToRegtestNetwork(page, extensionId); await page.goto(vulpemFaucetURL); let provider = new PlaywrightMarinaProvider(page); @@ -212,33 +211,36 @@ pwTest( if (!toFaucet.confidentialAddress) throw new Error('confidentialAddress is undefined'); await faucet(toFaucet.confidentialAddress, 1); // send 1 L-BTC to the address await page.goto(marinaURL(extensionId, 'popup.html')); - await page.waitForSelector('text=1 L-BTC'); + await page.waitForSelector('text=1.00 000 000 L-BTC'); await page.goto(vulpemFaucetURL); provider = new PlaywrightMarinaProvider(page); // random regtest address - const receiver = 'el1qqdfjtdv5a7jez0qmj5g4u07pcg0qsm8jrwx0c6rza8kmquad2k62mwxw92f7vw0460wdx36m97er86rlkl3xsz774h2w3zpc9' + const receiver = + 'el1qqdfjtdv5a7jez0qmj5g4u07pcg0qsm8jrwx0c6rza8kmquad2k62mwxw92f7vw0460wdx36m97er86rlkl3xsz774h2w3zpc9'; const recipients = [ - { + { address: receiver, asset: networks.regtest.assetHash, value: 1_0000_0000 - 1500, - } + }, ]; const handleSendTransactionPopup = async () => { const popup = await context.waitForEvent('page'); await popup.waitForSelector(`text= L-BTC`); // wait for loading to finish - const value = popup.getByTestId(networks.regtest.assetHash) + const value = popup.getByTestId(networks.regtest.assetHash); pwExpect(value).toBeTruthy(); pwExpect(await value.innerText()).toEqual('0.999985'); - const btn = popup.getByRole('button', { name: 'Reject' }) + const btn = popup.getByRole('button', { name: 'Reject' }); pwExpect(btn).toBeTruthy(); await btn.click(); }; await Promise.all([ - pwExpect(provider.sendTransaction(recipients)).rejects.toThrow('user rejected the sendTransaction request'), + pwExpect(provider.sendTransaction(recipients)).rejects.toThrow( + 'user rejected the sendTransaction request' + ), handleSendTransactionPopup(), ]); } diff --git a/playwright-tests/popup.spec.ts b/playwright-tests/popup.spec.ts index 78a57b6c..6c86454e 100644 --- a/playwright-tests/popup.spec.ts +++ b/playwright-tests/popup.spec.ts @@ -29,18 +29,18 @@ pwTest( pwExpect(clipboard).toContain('el1'); pwExpect(address.isConfidential(clipboard as string)).toBe(true); - // faucet + // faucet const txid = await faucet(clipboard as string, 1); // send 1 L-BTC to the address await page.goto(marinaURL(extensionId, 'popup.html')); // wait to receive the funds - await page.waitForSelector('text=1 L-BTC'); + await page.waitForSelector('text=1.00 000 000 L-BTC'); - await page.getByRole('button', { name: 'Liquid Bitcoin'}).click(); // go to L-BTC page + await page.getByRole('button', { name: 'Liquid Bitcoin' }).click(); // go to L-BTC page // wait some time await page.getByRole('button', { name: '+1 L-BTC' }).click(); // click on tx await page.waitForSelector(`text=${txid}`); // check txid is displayed await page.waitForSelector('text=Inbound'); - await page.waitForSelector('text=1 L-BTC'); // check amount is displayed + await page.waitForSelector('text=1.00 000 000 L-BTC'); // check amount is displayed await page.waitForSelector('text=Fee'); } ); @@ -57,17 +57,21 @@ pwTest( await page.getByRole('button', { name: 'New Asset' }).click(); await page.getByRole('button', { name: 'Copy' }).click(); await page.waitForSelector('text=Copied'); - const address = await page.evaluate("navigator.clipboard.readText()"); + const address = await page.evaluate('navigator.clipboard.readText()'); pwExpect(address as string).toContain('el1'); await faucet(address as string, 1); // send 1 L-BTC to the address await page.goto(marinaURL(extensionId, 'popup.html')); - await page.waitForSelector('text=1 L-BTC'); + await page.waitForSelector('text=1.00 000 000 L-BTC'); await page.getByRole('button', { name: 'Send' }).click(); // go to send await page.getByText('Liquid Bitcoin').click(); // select L-BTC - await page.getByPlaceholder('el1...').fill('el1qq0vzd590j00zmmmnjajznkg52dw2st8drdnsxrh6gyd53g6yuf403fj26wlxtywylpxdx84vd67he6r059s0usrtlq73dyjpf'); // fill the address with a random regtest address + await page + .getByPlaceholder('el1...') + .fill( + 'el1qq0vzd590j00zmmmnjajznkg52dw2st8drdnsxrh6gyd53g6yuf403fj26wlxtywylpxdx84vd67he6r059s0usrtlq73dyjpf' + ); // fill the address with a random regtest address await page.getByPlaceholder('0').fill('0.9'); // fill the amount - await page.getByRole('button', { name: 'Verify' }).click(); - await page.getByRole('button', { name: 'L-BTC' }).click(); + await page.getByRole('button', { name: 'Verify' }).click(); + await page.getByRole('button', { name: 'L-BTC' }).click(); await page.waitForSelector('text=Fee:'); await page.getByRole('button', { name: 'Confirm' }).click(); // send await page.getByRole('button', { name: 'Send' }).click(); // confirm