Skip to content

Commit

Permalink
fix: switch network test flakyness (#2175)
Browse files Browse the repository at this point in the history
Co-authored-by: enesozturk <[email protected]>
  • Loading branch information
tomiir and enesozturk authored Apr 22, 2024
1 parent 433bc8e commit 90fe952
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
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

0 comments on commit 90fe952

Please sign in to comment.