Skip to content

Commit

Permalink
fix: corrected workflow build, improved test flow by serializing to s…
Browse files Browse the repository at this point in the history
…imulate a real user
  • Loading branch information
JonathanConn committed Aug 3, 2023
1 parent 0ae3421 commit bc718b2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 131 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/playwright_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ jobs:

- name: Install deps
run: npm ci


- name: build
run: npm run build

- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium firefox

Expand Down
4 changes: 4 additions & 0 deletions laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ export class ModalPage {
async closeModal() {
await this.page.getByTestId('backcard-close').click()
}

async closePopup() {
await this.page.locator('.nextui-modal-close-icon-svg').click()
}
}
6 changes: 0 additions & 6 deletions laboratory/tests/shared/validators/ModalValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ export class ModalValidator {
constructor(public readonly page: Page) {}

async expectConnected() {
if (this.page.url() !== this.baseURL) {
await this.page.goto(this.baseURL)
}
await expect(this.page.getByTestId('partial-account-address')).toBeVisible()
}

async expectDisconnected() {
if (this.page.url() !== this.baseURL) {
await this.page.goto(this.baseURL)
}
await expect(this.page.getByTestId('partial-account-address')).not.toBeVisible()
}

Expand Down
206 changes: 82 additions & 124 deletions laboratory/tests/w3m-wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,126 +1,84 @@
import { DEFAULT_SESSION_PARAMS } from './shared/constants'
import { testMW, expect } from './shared/fixtures/w3m-wallet-fixture'

testMW.describe('W3M using wallet web-example', () => {
testMW.beforeEach(
async ({ modalPage, walletPage, modalValidator, walletValidator, browserName }) => {
testMW.skip(
browserName === 'webkit' && process.platform === 'linux',
'Webkit on Linux does not support clipboard'
)

await modalPage.getUri()
await walletPage.connect()

await walletPage.handleSessionProposal(DEFAULT_SESSION_PARAMS)
await modalValidator.expectConnected()
await walletValidator.expectConnected()
}
)

testMW(
'Should be able to connect, then disconnect',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
expect(modalPage).toBeDefined()
expect(walletPage).toBeDefined()
await modalPage.disconnect()
await modalValidator.expectDisconnected()
await walletValidator.expectDisconnected()
}
)

testMW(
'Should send disconnect to wallet',
async ({ modalPage, modalValidator, walletValidator }) => {
await modalPage.disconnect()
await modalValidator.expectDisconnected()
await walletValidator.expectDisconnected()
}
)
testMW(
'Should recieve disconnect from a wallet',
async ({ walletPage, modalValidator, walletValidator }) => {
await walletPage.disconnect()
await walletValidator.expectDisconnected()
await modalValidator.expectDisconnected()
}
)

testMW(
'Should sign a message',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.sign()

await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: true })

await modalValidator.expectAcceptedSign()
}
)

testMW(
'Should handle rejected sign',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.sign()

await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: false })

await modalValidator.expectRejectedSign()
}
)

testMW(
'should sign typed data',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.signTyped()

await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: true })

await modalValidator.expectAcceptedSignTyped()
}
)

testMW(
'should handle rejected sign typed data',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.signTyped()

await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: false })

await modalValidator.expectRejectedSignTyped()
}
)

testMW(
'should handle chain switch using sign',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.switchChain({ chainName: 'Polygon' })
await modalPage.closeModal()

await modalPage.sign()

await walletValidator.expectRecievedSign({ chainName: 'Polygon' })
await walletPage.handleRequest({ accept: true })

await modalValidator.expectAcceptedSign()
}
)

testMW(
'should handle chain switch using sign typed',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.switchChain({ chainName: 'Polygon' })
await modalPage.closeModal()

await modalPage.signTyped()

await walletValidator.expectRecievedSignTyped({ chainName: 'Polygon' })
await walletPage.handleRequest({ accept: true })

await modalValidator.expectAcceptedSignTyped()
}
)
import { testMW } from './shared/fixtures/w3m-wallet-fixture'

// Initialize the connection
testMW.beforeEach(async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
await modalPage.getUri()
await walletPage.connect()
await walletPage.handleSessionProposal(DEFAULT_SESSION_PARAMS)
await modalValidator.expectConnected()
await walletValidator.expectConnected()
})

testMW(
'Should handle all sign requests',
async ({ modalPage, walletPage, modalValidator, walletValidator }) => {
// Should accept sign
await modalPage.sign()
await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()
await modalPage.closePopup()

// Should reject sign
await modalPage.sign()
await walletValidator.expectRecievedSign({})
await walletPage.handleRequest({ accept: false })
await modalValidator.expectRejectedSign()
await modalPage.closePopup()

// Should accept sign typed
await modalPage.signTyped()
await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSignTyped()
await modalPage.closePopup()

// Should reject sign typed
await modalPage.signTyped()
await walletValidator.expectRecievedSignTyped({})
await walletPage.handleRequest({ accept: false })
await modalValidator.expectRejectedSignTyped()
await modalPage.closePopup()

// Should accept sign with chain switch
await modalPage.switchChain({ chainName: 'Polygon' })
await modalPage.closeModal()
await modalPage.sign()
await walletValidator.expectRecievedSign({ chainName: 'Polygon' })
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()
await modalPage.closePopup()

// Should reject sign with chain switch
await modalPage.switchChain({ chainName: 'Ethereum' })
await modalPage.closeModal()
await modalPage.signTyped()
await walletValidator.expectRecievedSignTyped({ chainName: 'Ethereum' })
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSignTyped()
await modalPage.closePopup()
}
)

testMW(
'Should connect, send disconnect event to wallet, recieve disconnect event',
async ({ modalPage, modalValidator, walletValidator }) => {
await modalValidator.expectConnected()
await walletValidator.expectConnected()
await modalPage.disconnect()
await modalValidator.expectDisconnected()
await walletValidator.expectDisconnected()
}
)

testMW(
'Should connect, recieve disconnect event from wallet',
async ({ walletPage, modalValidator, walletValidator }) => {
await modalValidator.expectConnected()
await walletValidator.expectConnected()
await walletPage.disconnect()
await walletValidator.expectDisconnected()
await modalValidator.expectDisconnected()
}
)

0 comments on commit bc718b2

Please sign in to comment.