Skip to content

Commit

Permalink
chore: ID allocation service (#2574)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Aug 6, 2024
1 parent ccd6147 commit d4eb59e
Show file tree
Hide file tree
Showing 16 changed files with 1,205 additions and 63 deletions.
6 changes: 3 additions & 3 deletions apps/laboratory/tests/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const emailTest = test.extend<{ library: string }>({

emailTest.describe.configure({ mode: 'serial' })

emailTest.beforeAll(async ({ browser, library }, testInfo) => {
emailTest.setTimeout(120000)
emailTest.beforeAll(async ({ browser, library }) => {
emailTest.setTimeout(180000)
context = await browser.newContext()
const browserPage = await context.newPage()

Expand All @@ -32,7 +32,7 @@ emailTest.beforeAll(async ({ browser, library }, testInfo) => {
throw new Error('MAILSAC_API_KEY is not set')
}
const email = new Email(mailsacApiKey)
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)
const tempEmail = await email.getEmailAddressToUse()
await page.emailFlow(tempEmail, context, mailsacApiKey)

await validator.expectConnected()
Expand Down
4 changes: 2 additions & 2 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ export class ModalPage {
await this.page.waitForTimeout(300)
}

async updateEmail(mailsacApiKey: string, index: number) {
async updateEmail(mailsacApiKey: string) {
const email = new Email(mailsacApiKey)
const newEmailAddress = email.getEmailAddressToUse(index)
const newEmailAddress = await email.getEmailAddressToUse()

await this.page.getByTestId('account-button').click()
await this.page.getByTestId('w3m-account-email-update').click()
Expand Down
15 changes: 11 additions & 4 deletions apps/laboratory/tests/shared/utils/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Mailsac } from '@mailsac/api'
const EMAIL_CHECK_INTERVAL = 2500
const MAX_EMAIL_CHECK = 24
const MAX_EMAIL_CHECK = 48
const EMAIL_APPROVE_BUTTON_TEXT = 'Approve this login'
const APPROVE_URL_REGEX = /https:\/\/register.*/u
const OTP_CODE_REGEX = /\d{3}\s?\d{3}/u
Expand Down Expand Up @@ -77,10 +77,17 @@ export class Email {
throw new Error(`No code found in email: ${body}`)
}

getEmailAddressToUse(index: number, domain = EMAIL_DOMAIN): string {
const randIndex = Math.floor(Math.random() * 10) % 9
async getEmailAddressToUse(domain = EMAIL_DOMAIN): Promise<string> {
const response = await fetch(
'https://id-allocation-service.walletconnect-v1-bridge.workers.dev/allocate'
)
const { id } = await response.json()

return `w3m-w${index}${randIndex}@${domain}`
const email = `w3m-w${id}@${domain}`
// eslint-disable-next-line no-console
console.log(`allocating email: ${email}`)

return email
}

getSmartAccountEnabledEmail(): string {
Expand Down
6 changes: 3 additions & 3 deletions apps/laboratory/tests/siwe-email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const emailSiweTest = test.extend<{ library: string }>({

emailSiweTest.describe.configure({ mode: 'serial' })

emailSiweTest.beforeAll(async ({ browser, library }, testInfo) => {
emailSiweTest.setTimeout(120000)
emailSiweTest.beforeAll(async ({ browser, library }) => {
emailSiweTest.setTimeout(180000)
context = await browser.newContext()
const browserPage = await context.newPage()

Expand All @@ -32,7 +32,7 @@ emailSiweTest.beforeAll(async ({ browser, library }, testInfo) => {
throw new Error('MAILSAC_API_KEY is not set')
}
const email = new Email(mailsacApiKey)
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)
const tempEmail = await email.getEmailAddressToUse()
await page.emailFlow(tempEmail, context, mailsacApiKey)
await page.promptSiwe()
await page.approveSign()
Expand Down
6 changes: 3 additions & 3 deletions apps/laboratory/tests/siwe-sa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const smartAccountSiweTest = test.extend<{ library: string }>({

smartAccountSiweTest.describe.configure({ mode: 'serial' })

smartAccountSiweTest.beforeAll(async ({ browser, library }, testInfo) => {
smartAccountSiweTest.setTimeout(120000)
smartAccountSiweTest.beforeAll(async ({ browser, library }) => {
smartAccountSiweTest.setTimeout(180000)
context = await browser.newContext()
const browserPage = await context.newPage()

Expand All @@ -36,7 +36,7 @@ smartAccountSiweTest.beforeAll(async ({ browser, library }, testInfo) => {
// Switch to a SA enabled network
await page.switchNetworkWithNetworkButton('Polygon')
await page.closeModal()
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)
const tempEmail = await email.getEmailAddressToUse()
await page.emailFlow(tempEmail, context, mailsacApiKey)
await page.promptSiwe()
await page.approveSign()
Expand Down
6 changes: 3 additions & 3 deletions apps/laboratory/tests/smart-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const smartAccountTest = test.extend<{ library: string }>({

smartAccountTest.describe.configure({ mode: 'serial' })

smartAccountTest.beforeAll(async ({ browser, library }, testInfo) => {
smartAccountTest.setTimeout(120000)
smartAccountTest.beforeAll(async ({ browser, library }) => {
smartAccountTest.setTimeout(180000)
context = await browser.newContext()
const browserPage = await context.newPage()

Expand All @@ -35,7 +35,7 @@ smartAccountTest.beforeAll(async ({ browser, library }, testInfo) => {
// Switch to a SA enabled network
await page.switchNetworkWithNetworkButton('Polygon')
await page.closeModal()
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)
const tempEmail = await email.getEmailAddressToUse()
await page.emailFlow(tempEmail, context, mailsacApiKey)

await validator.expectConnected()
Expand Down
6 changes: 3 additions & 3 deletions apps/laboratory/tests/wallet-features.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const walletFeaturesTest = test.extend<{ library: string }>({

walletFeaturesTest.describe.configure({ mode: 'serial' })

walletFeaturesTest.beforeAll(async ({ browser, library }, testInfo) => {
walletFeaturesTest.setTimeout(120000)
walletFeaturesTest.beforeAll(async ({ browser, library }) => {
walletFeaturesTest.setTimeout(180000)
context = await browser.newContext()
const browserPage = await context.newPage()

Expand All @@ -31,7 +31,7 @@ walletFeaturesTest.beforeAll(async ({ browser, library }, testInfo) => {
throw new Error('MAILSAC_API_KEY is not set')
}
const email = new Email(mailsacApiKey)
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)
const tempEmail = await email.getEmailAddressToUse()
await page.emailFlow(tempEmail, context, mailsacApiKey)

await validator.expectConnected()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build:clean": "turbo run build:clean --filter={./packages/*}",
"build": "turbo run build --filter={./packages/*} --concurrency=30",
"build": "turbo run build --filter={./packages/*} --concurrency=31",
"watch": "turbo run watch --filter={./packages/*} --concurrency=50 --continue",
"gallery": "turbo run dev --filter={./apps/gallery}",
"laboratory": "pnpm --filter @apps/laboratory dev",
Expand Down
Loading

0 comments on commit d4eb59e

Please sign in to comment.