Skip to content

Commit

Permalink
fix playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bordalix committed Dec 20, 2023
1 parent 1533f7a commit af7fd62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
30 changes: 16 additions & 14 deletions playwright-tests/injected-script.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand All @@ -97,7 +97,6 @@ pwTest(
zkpLib
);


const contractScript = contract.scriptPubKey.toString('hex');
await pwExpect(
provider.importScript('ionio', contractScript, blindingKeyPair.privateKey!.toString('hex'))
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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(),
]);
}
Expand Down
22 changes: 13 additions & 9 deletions playwright-tests/popup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
);
Expand All @@ -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
Expand Down

0 comments on commit af7fd62

Please sign in to comment.