From 999b9167fce5eabb3e44efe5ae4e0da415c1ddda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stankiewicz?= Date: Tue, 14 May 2024 13:48:51 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=AA=BF=20Update=20add=20new=20network?= =?UTF-8?q?=20test=20(#1162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/docs/playwright/with-metamask.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/docs/playwright/with-metamask.test.ts b/packages/docs/playwright/with-metamask.test.ts index e4c189966..3dcb5e657 100644 --- a/packages/docs/playwright/with-metamask.test.ts +++ b/packages/docs/playwright/with-metamask.test.ts @@ -101,12 +101,8 @@ describe(`Browser: ${browserType.name()} with Metamask`, () => { const popupPage = await popupPromise await sleep(2000) // Wait for the popup to be fully loaded. - expect( - // if this link is visible, then the network does not match metamask records - await popupPage.isVisible(`//a[@href='https://metamask.zendesk.com/hc/en-us/articles/360057142392']`) - ).to.be.false - await popupPage.click(XPath.text('a', 'View all')) + await popupPage.click(XPath.text('a', 'View all details')) await waitForExpect(async () => { expect(await popupPage.isVisible(`//*[text()='${Optimism.chainName}']`)).to.be.true expect(await popupPage.isVisible(`//*[text()='${Optimism.rpcUrl}']`)).to.be.true From b9113edc80b5e65e9ecc272d05e9bacf92e88133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stankiewicz?= Date: Tue, 14 May 2024 15:43:16 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=9A=F0=9F=8F=BB=20Remove=20goerli?= =?UTF-8?q?=20from=20example=20app=20=20multichain=20section=20(#1157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🧚🏻 Remove goerli from example app multichain section * Add sepolia to test * Update readonly urls * Remove sepolia * Remove from non metamask test --- packages/example/playwright/with-metamask.ts | 12 +++++------- packages/example/playwright/without-metamask.ts | 2 -- packages/example/src/entrypoint.tsx | 9 +-------- packages/example/src/pages/Multichain.tsx | 4 ++-- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/packages/example/playwright/with-metamask.ts b/packages/example/playwright/with-metamask.ts index 2db1a2019..0bd914148 100644 --- a/packages/example/playwright/with-metamask.ts +++ b/packages/example/playwright/with-metamask.ts @@ -276,9 +276,7 @@ export const withMetamaskTest = (baseUrl: string) => { await waitForExpect(async () => { expect(await page.isVisible(XPath.text('span', 'Mainnet'))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Goerli'))).to.be.true expect(await page.isVisible(XPath.text('span', 'Optimism'))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Optimism Goerli'))).to.be.true }) }) @@ -286,11 +284,11 @@ export const withMetamaskTest = (baseUrl: string) => { await page.goto(`${baseUrl}multichain`) await waitForExpect(async () => { - expect(await page.isVisible(XPath.text('span', 'Chain id:', 4))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Current block timestamp:', 4))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Current difficulty:', 4))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Current block:', 4))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Ether balance:', 4))).to.be.true + expect(await page.isVisible(XPath.text('span', 'Chain id:', 2))).to.be.true + expect(await page.isVisible(XPath.text('span', 'Current block timestamp:', 2))).to.be.true + expect(await page.isVisible(XPath.text('span', 'Current difficulty:', 2))).to.be.true + expect(await page.isVisible(XPath.text('span', 'Current block:', 2))).to.be.true + expect(await page.isVisible(XPath.text('span', 'Ether balance:', 2))).to.be.true }) }) }) diff --git a/packages/example/playwright/without-metamask.ts b/packages/example/playwright/without-metamask.ts index d811e053d..04c136a06 100644 --- a/packages/example/playwright/without-metamask.ts +++ b/packages/example/playwright/without-metamask.ts @@ -90,9 +90,7 @@ export const withoutMetamaskTest = (baseUrl: string) => { await waitForExpect(async () => { expect(await page.isVisible(XPath.text('span', 'Mainnet'))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Goerli'))).to.be.true expect(await page.isVisible(XPath.text('span', 'Optimism'))).to.be.true - expect(await page.isVisible(XPath.text('span', 'Optimism Goerli'))).to.be.true }) }) diff --git a/packages/example/src/entrypoint.tsx b/packages/example/src/entrypoint.tsx index 0e55206a2..3c70f7d24 100644 --- a/packages/example/src/entrypoint.tsx +++ b/packages/example/src/entrypoint.tsx @@ -7,8 +7,6 @@ import { Localhost, MetamaskConnector, CoinbaseWalletConnector, - Goerli, - OptimismGoerli, Optimism, } from '@usedapp/core' import { App } from './App' @@ -18,11 +16,7 @@ import { getDefaultProvider } from '@ethersproject/providers' const readOnlyUrls: Config['readOnlyUrls'] = { [Mainnet.chainId]: process.env.MAINNET_URL || getDefaultProvider('mainnet'), - [Goerli.chainId]: process.env.MAINNET_URL - ? process.env.MAINNET_URL.replace('mainnet', 'goerli') - : getDefaultProvider('goerli'), [Optimism.chainId]: 'https://mainnet.optimism.io', - [OptimismGoerli.chainId]: 'https://goerli.optimism.io', } if (process.env.LOCALHOST_URL) { @@ -45,8 +39,7 @@ const config: Config = { projectId: 'bffbe493c0928ee125dc8f23e20167b7', chains: [Mainnet], rpcMap: { - 1: 'https://mainnet.infura.io/v3/d8df2cb7844e4a54ab0a782f608749dd', - 5: 'https://goerli.infura.io/v3/d8df2cb7844e4a54ab0a782f608749dd', + [Mainnet.chainId]: 'https://mainnet.infura.io/v3/d8df2cb7844e4a54ab0a782f608749dd', }, }), }, diff --git a/packages/example/src/pages/Multichain.tsx b/packages/example/src/pages/Multichain.tsx index 59cd2f958..454140016 100644 --- a/packages/example/src/pages/Multichain.tsx +++ b/packages/example/src/pages/Multichain.tsx @@ -1,11 +1,11 @@ import React from 'react' import { Container, MainContent, Section, SectionRow } from '../components/base/base' -import { Goerli, Mainnet, Optimism, OptimismGoerli } from '@usedapp/core' +import { Mainnet, Optimism } from '@usedapp/core' import { ChainState } from '../components/ChainState' import { Title } from '../typography/Title' import styled from 'styled-components' -const chains = [Mainnet.chainId, Goerli.chainId, Optimism.chainId, OptimismGoerli.chainId] +const chains = [Mainnet.chainId, Optimism.chainId] export const Multichain = () => { return ( From bce5650ae8e63cd6ba3baaa88c2fb4601af35c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stankiewicz?= Date: Fri, 17 May 2024 13:14:25 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A7=20Use=20sepolia=20in=20e2e=20t?= =?UTF-8?q?ests=20(#1166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎧 Use sepolia in e2e tests * Add another sleep --- .../docs/playwright/with-metamask.test.ts | 22 ++++++++++++++----- packages/docs/src/examples/Siwe.tsx | 4 ++-- .../docs/src/examples/SwitchingNetworks.tsx | 8 +++---- packages/example/src/entrypoint.tsx | 1 + packages/playwright/src/metamask/MetaMask.ts | 21 +++++++++++++++++- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/packages/docs/playwright/with-metamask.test.ts b/packages/docs/playwright/with-metamask.test.ts index 3dcb5e657..e01bc0d1f 100644 --- a/packages/docs/playwright/with-metamask.test.ts +++ b/packages/docs/playwright/with-metamask.test.ts @@ -80,12 +80,17 @@ describe(`Browser: ${browserType.name()} with Metamask`, () => { }) const popupPromise = waitForPopup(context) - await page.click(XPath.text('button', 'Switch to Goerli')) + await page.click(XPath.text('button', 'Switch to Sepolia')) const popupPage = await popupPromise await popupPage.click(XPath.text('button', 'Switch network')) + await sleep(1000) + if (await page.isVisible(XPath.text('button', 'Connect with Metamask'))) { + await page.click(XPath.text('button', 'Connect with Metamask')) + } + await waitForExpect(async () => { - expect(await page.isVisible(`//*[text()='Current chain: ' and text()='5']`)).to.be.true + expect(await page.isVisible(`//*[text()='Current chain: ' and text()='11155111']`)).to.be.true }) }) @@ -93,7 +98,7 @@ describe(`Browser: ${browserType.name()} with Metamask`, () => { await page.goto(`${baseUrl}Guides/Transactions/Switching%20Networks`) await waitForExpect(async () => { - expect(await page.isVisible(`//*[text()='Current chain: ' and text()='5']`)).to.be.true + expect(await page.isVisible(`//*[text()='Current chain: ' and text()='11155111']`)).to.be.true }) const popupPromise = waitForPopup(context) @@ -145,7 +150,7 @@ describe(`Browser: ${browserType.name()} with Metamask`, () => { let popupPage = await popupPromise await popupPage.click(XPath.text('button', 'Sign')) await waitForExpect(async () => { - expect(await page.isVisible(`//*[text()='ChainId: ' and text()='5']`)).to.be.true + expect(await page.isVisible(`//*[text()='ChainId: ' and text()='11155111']`)).to.be.true }) await metamask.switchToNetwork('Ethereum Mainnet') @@ -163,10 +168,15 @@ describe(`Browser: ${browserType.name()} with Metamask`, () => { expect(await page.isVisible(`//*[text()='Not logged in']`)).to.be.true }) - await metamask.switchToNetwork('Goerli Test Network') + await metamask.switchToNetwork('Sepolia Test Network') + + await sleep(1000) + if (await page.isVisible(XPath.text('button', 'Connect with Metamask'))) { + await page.click(XPath.text('button', 'Connect with Metamask')) + } await waitForExpect(async () => { - expect(await page.isVisible(`//*[text()='ChainId: ' and text()='5']`)).to.be.true + expect(await page.isVisible(`//*[text()='ChainId: ' and text()='11155111']`)).to.be.true }) }) }) diff --git a/packages/docs/src/examples/Siwe.tsx b/packages/docs/src/examples/Siwe.tsx index 8479594a3..18381b68e 100644 --- a/packages/docs/src/examples/Siwe.tsx +++ b/packages/docs/src/examples/Siwe.tsx @@ -1,6 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom' -import { Mainnet, DAppProvider, useEthers, Config, Goerli } from '@usedapp/core' +import { Mainnet, DAppProvider, useEthers, Config, Sepolia } from '@usedapp/core' import { getDefaultProvider } from 'ethers' import { SiweProvider, useSiwe } from '@usedapp/siwe' @@ -12,7 +12,7 @@ const config: Config = { readOnlyChainId: Mainnet.chainId, readOnlyUrls: { [Mainnet.chainId]: getDefaultProvider('mainnet'), - [Goerli.chainId]: getDefaultProvider('goerli'), + [Sepolia.chainId]: 'https://rpc2.sepolia.org', }, } diff --git a/packages/docs/src/examples/SwitchingNetworks.tsx b/packages/docs/src/examples/SwitchingNetworks.tsx index 5562404a4..34c5caa65 100644 --- a/packages/docs/src/examples/SwitchingNetworks.tsx +++ b/packages/docs/src/examples/SwitchingNetworks.tsx @@ -1,6 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom' -import { DAppProvider, useSendTransaction, useEthers, Config, Goerli, Mainnet, Optimism } from '@usedapp/core' +import { DAppProvider, useSendTransaction, useEthers, Config, Mainnet, Optimism, Sepolia } from '@usedapp/core' import { getDefaultProvider } from 'ethers' const config: Config = { @@ -8,7 +8,7 @@ const config: Config = { readOnlyUrls: { [Mainnet.chainId]: getDefaultProvider('mainnet'), [Optimism.chainId]: getDefaultProvider('optimism'), - [Goerli.chainId]: getDefaultProvider('goerli'), + [Sepolia.chainId]: 'https://rpc2.sepolia.org', }, } @@ -45,8 +45,8 @@ export function App() { }{' '} { - } diff --git a/packages/example/src/entrypoint.tsx b/packages/example/src/entrypoint.tsx index 3c70f7d24..0ed0caeec 100644 --- a/packages/example/src/entrypoint.tsx +++ b/packages/example/src/entrypoint.tsx @@ -17,6 +17,7 @@ import { getDefaultProvider } from '@ethersproject/providers' const readOnlyUrls: Config['readOnlyUrls'] = { [Mainnet.chainId]: process.env.MAINNET_URL || getDefaultProvider('mainnet'), [Optimism.chainId]: 'https://mainnet.optimism.io', + [Localhost.chainId]: 'http://localhost:8545', } if (process.env.LOCALHOST_URL) { diff --git a/packages/playwright/src/metamask/MetaMask.ts b/packages/playwright/src/metamask/MetaMask.ts index e228dc0e8..2fbc3f9e4 100644 --- a/packages/playwright/src/metamask/MetaMask.ts +++ b/packages/playwright/src/metamask/MetaMask.ts @@ -65,7 +65,9 @@ export class MetaMask { log('Metamask account connected to pages.') } - async switchToNetwork(network: 'Ethereum Mainnet' | 'Localhost 8545' | 'Goerli Test Network') { + async switchToNetwork( + network: 'Ethereum Mainnet' | 'Localhost 8545' | 'Goerli Test Network' | 'Sepolia Test Network' + ) { log('Switching network...') await this.gotoMetamask() await this.page.click('.network-display--clickable') // Network popup menu on the top right. @@ -104,6 +106,23 @@ export class MetaMask { await this.page.click('//button[@title="Close"]') // Close "What's new" section. log('Metamask activated.') + + log('Add Sepolia') + await this.page.goto( + 'chrome-extension://' + (await this.getExtensionId()) + '//home.html#settings/networks/add-network' + ) + + await this.page.locator('input').locator('nth=1').fill('Sepolia Test Network') + await this.page.locator('input').locator('nth=2').fill('https://rpc2.sepolia.org') + await this.page.locator('input').locator('nth=3').fill('11155111') + await this.page.locator('input').locator('nth=4').fill('ETH') + await this.page.click(XPath.text('button', 'Save')) + + log('Sepolia added') + + log('Switch back to mainnet') + await this.switchToNetwork('Ethereum Mainnet') + log('Switched back to mainnet') } async switchWallet(index: number) {