Skip to content

Commit

Permalink
feat(e2e): enhance WalletConnectConnector tests FE-911 (#431)
Browse files Browse the repository at this point in the history
Co-authored-by: Luiz Gomes <[email protected]>
  • Loading branch information
nelitow and LuizAsFight authored Dec 4, 2024
1 parent 1e05e03 commit fb025f8
Showing 1 changed file with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { getButtonByText, getByAriaLabel } from '@fuels/playwright-utils';
import {
getButtonByText,
getByAriaLabel,
seedWallet,
} from '@fuels/playwright-utils';
import { testWithSynpress } from '@synthetixio/synpress';
import { MetaMask, metaMaskFixtures } from '@synthetixio/synpress/playwright';
import { sessionTests, transferTests } from '../../../common/common';
import { type BN, bn } from 'fuels';
import {
incrementTests,
sessionTests,
transferTests,
} from '../../../common/common';
import type { ConnectorFunctions } from '../../../common/types';
import basicSetup from '../../../wallet-setup/basic.setup';
import { fundWallet } from '../setup';

const test = testWithSynpress(metaMaskFixtures(basicSetup));

const { VITE_FUEL_PROVIDER_URL, VITE_WALLET_SECRET } = process.env as Record<
string,
string
>;

test.describe('WalletConnectConnector', () => {
let metamask: MetaMask;

test.slow();
test.beforeEach(async ({ context, extensionId, metamaskPage, page }) => {
metamask = new MetaMask(
context,
Expand All @@ -22,47 +35,45 @@ test.describe('WalletConnectConnector', () => {
});

const connect: ConnectorFunctions['connect'] = async (page) => {
await page.goto('/');
const connectButton = getButtonByText(page, 'Connect Wallet', true);
await connectButton.click();
await getByAriaLabel(page, 'Connect to Ethereum Wallets', true).click();

await page.getByText('Proceed anyway').click();
await getButtonByText(page, 'MetaMask', true).click();

await metamask.connectToDapp();
// wait 3 seconds for the connection to be established
await page.waitForTimeout(3000);

await page.waitForTimeout(4000);
await metamask.confirmSignature();
};

const approveTransfer: ConnectorFunctions['approveTransfer'] = async () => {
await metamask.confirmTransaction();
};

test('Fuel tests', async ({ page }) => {
test('Ethereum session tests', async ({ page }) => {
await sessionTests(page, { connect, approveTransfer });
});

test('Ethereum transfer tests', async ({ page }) => {
await connect(page);

const addressElement = await page.locator('#address');
let address: string | null = null;
if (addressElement) {
address = await addressElement.getAttribute('data-address');
}
const addressElement = await page.locator('css=#address');

const address = await addressElement.getAttribute('data-address');
const amount: BN = bn(100_000_000);

if (address) {
await fundWallet({ publicKey: address });
await seedWallet(
address,
amount,
VITE_FUEL_PROVIDER_URL || '',
VITE_WALLET_SECRET || '',
);
} else {
throw new Error('Address is null');
}

await page.click('text=Disconnect');
await page.waitForSelector('text=/Connect Wallet/');

await transferTests(page, { connect, approveTransfer });
await transferTests(page, { connect, approveTransfer, keepSession: true });

// await incrementTests(page, { connect, approveTransfer });
await incrementTests(page, { connect, approveTransfer, keepSession: true });
});
});

0 comments on commit fb025f8

Please sign in to comment.