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

fix: switch network test flakyness #2175

Merged
merged 4 commits into from
Apr 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ export function SolanaWriteContractTest() {
}

return (
<Button isDisabled={loading} data-testid="sign-message-button" onClick={onIncrementCounter}>
<Button
isDisabled={loading}
data-testid="increment-counter-with-sign-button"
onClick={onIncrementCounter}
>
Increment Counter With Sign
</Button>
)
Expand Down
6 changes: 4 additions & 2 deletions apps/laboratory/tests/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ testMEmail('it should switch network and sign', async ({ modalPage, modalValidat
let targetChain = 'Polygon'
await modalPage.switchNetwork(targetChain)
await modalValidator.expectNetwork(targetChain)
await modalPage.page.waitForTimeout(3500)
await modalPage.closeModal()
await modalPage.page.waitForTimeout(1500)
await modalPage.sign()
await modalPage.approveSign()
await modalValidator.expectAcceptedSign()
Expand All @@ -38,7 +39,8 @@ testMEmail('it should switch network and sign', async ({ modalPage, modalValidat
targetChain = 'Ethereum'
await modalPage.switchNetwork(targetChain)
await modalValidator.expectNetwork(targetChain)
await modalPage.page.waitForTimeout(3500)
await modalPage.closeModal()
await modalPage.page.waitForTimeout(1500)
await modalPage.sign()
await modalPage.approveSign()
await modalValidator.expectAcceptedSign()
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export class ModalPage {
await this.page.getByTestId('account-button').click()
await this.page.getByTestId('w3m-account-select-network').click()
await this.page.getByTestId(`w3m-network-switch-${network}`).click()
await this.page.getByTestId('w3m-header-close').click()
// Network switch might take a second or two
await this.page.waitForTimeout(2000)
}

async clickWalletDeeplink() {
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/tests/shared/validators/ModalValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ModalValidator {
}

async expectNetwork(network: string) {
const networkButton = this.page.locator('wui-network-button')
const networkButton = this.page.getByTestId('w3m-account-select-network')
await expect(networkButton, `Network button should contain text ${network}`).toHaveText(
network,
{
Expand Down
8 changes: 6 additions & 2 deletions apps/laboratory/tests/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ testConnectedMW(
testConnectedMW(
'it should switch networks and sign',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
const chains = modalPage.library === 'solana' ? ['Solana'] : ['Polygon', 'Ethereum']
const chains = modalPage.library === 'solana' ? ['Solana Devnet'] : ['Polygon', 'Ethereum']

// Run them one after another
async function processChain(index: number) {
Expand All @@ -50,9 +50,13 @@ testConnectedMW(
}

const chainName = chains[index] ?? DEFAULT_CHAIN_NAME
// For Solana, even though we switch to Solana Devnet, the chain name on the wallet page is still Solana
const chainNameOnWalletPage = modalPage.library === 'solana' ? 'Solana' : chainName
await modalPage.switchNetwork(chainName)
await modalValidator.expectNetwork(chainName)
await modalPage.closeModal()
await modalPage.sign()
await walletValidator.expectReceivedSign({ chainName })
await walletValidator.expectReceivedSign({ chainName: chainNameOnWalletPage })
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()

Expand Down
Loading