Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎧 Use sepolia in e2e tests #1166

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/docs/playwright/with-metamask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,25 @@ 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
})
})

it('Add new network to Metamask', async () => {
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)
Expand Down Expand Up @@ -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')
Expand All @@ -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
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/examples/Siwe.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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',
},
}

Expand Down
8 changes: 4 additions & 4 deletions packages/docs/src/examples/SwitchingNetworks.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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 = {
readOnlyChainId: Mainnet.chainId,
readOnlyUrls: {
[Mainnet.chainId]: getDefaultProvider('mainnet'),
[Optimism.chainId]: getDefaultProvider('optimism'),
[Goerli.chainId]: getDefaultProvider('goerli'),
[Sepolia.chainId]: 'https://rpc2.sepolia.org',
},
}

Expand Down Expand Up @@ -45,8 +45,8 @@ export function App() {
</button>
}{' '}
{
<button onClick={() => switchNetwork(Goerli.chainId)} disabled={chainId === Goerli.chainId}>
Switch to Goerli
<button onClick={() => switchNetwork(Sepolia.chainId)} disabled={chainId === Sepolia.chainId}>
Switch to Sepolia
</button>
}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/example/src/entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion packages/playwright/src/metamask/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Loading