Skip to content

Commit

Permalink
Merge branch 'V4' into feat/onramp-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Feb 9, 2024
2 parents 6aa3de8 + a1ee4c6 commit 49688f6
Show file tree
Hide file tree
Showing 7 changed files with 4,832 additions and 3,444 deletions.
5 changes: 4 additions & 1 deletion apps/laboratory/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Obtain a project ID from https://cloud.walletconnect.com
NEXT_PUBLIC_PROJECT_ID=""
# See 1password for `NEXT_AUTH_SECRET`
NEXTAUTH_SECRET=""
NEXTAUTH_URL=""
# See 1password for `Mailsac Web3Modal API Key`
MAILSAC_API_KEY=""
# Only needed when overriding default next-auth URL
# NEXTAUTH_URL=""
1 change: 1 addition & 0 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"wagmi": "2.5.0"
},
"devDependencies": {
"@aws-sdk/client-cloudwatch": "3.509.0",
"@mailsac/api": "1.0.5",
"@playwright/test": "1.40.1",
"dotenv": "16.3.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ConstantsUtil = {
Metadata: {
name: 'Web3Modal',
description: 'Web3Modal Laboratory',
url: 'https://web3modal.com',
url: 'https://lab.web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886'],
verifyUrl: ''
},
Expand Down
7 changes: 6 additions & 1 deletion apps/laboratory/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ We use Playwright as our functional test runner. It's configured to try multiple
- Browsers: Chromium/Firefox
- Modal flavors: default/SIWE/email

## Setup

- Make sure your `.env` is set up (see `.env.example` for reference)
- Run `npm run playwright:install` to install the browsers required to run the tests

## Running Tests

- `npx playwright test` to run in default mode (make sure your `.env` is set up)
- `npx playwright test` to run in default mode.
- `npm run playwright:debug` to step by step see what the tests are doing

## Debugging
Expand Down
19 changes: 19 additions & 0 deletions apps/laboratory/tests/canary.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { DEFAULT_SESSION_PARAMS } from './shared/constants'
import { testMW } from './shared/fixtures/w3m-wallet-fixture'
import { uploadCanaryResultsToCloudWatch } from './shared/utils/metrics'

const ENV = process.env['ENV'] || 'dev'
const REGION = process.env['REGION'] || 'eu-central-1'

let startTime = 0

testMW.beforeEach(
async ({ modalPage, walletPage, modalValidator, walletValidator, browserName }) => {
startTime = Date.now()
// Canary doesn't need all platforms
if (browserName !== 'chromium' || modalPage.library !== 'ethers') {
return
Expand Down Expand Up @@ -38,5 +45,17 @@ testMW(
await walletValidator.expectReceivedSign({})
await walletPage.handleRequest({ accept: true })
await modalValidator.expectAcceptedSign()

if (ENV !== 'dev') {
const duration: number = Date.now() - startTime
await uploadCanaryResultsToCloudWatch(
ENV,
REGION,
'https://lab.web3modal.com/',
'HappyPath.sign',
true,
duration
)
}
}
)
87 changes: 87 additions & 0 deletions apps/laboratory/tests/shared/utils/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
CloudWatch,
type MetricDatum,
type PutMetricDataCommandInput
} from '@aws-sdk/client-cloudwatch'

// eslint-disable-next-line func-style
export const uploadCanaryResultsToCloudWatch = async (
env: string,
region: string,
target: string,
metricsPrefix: string,
isTestPassed: boolean,
testDurationMs: number
// eslint-disable-next-line max-params
) => {
const cloudwatch = new CloudWatch({ region: 'eu-central-1' })
const ts = new Date()
const metrics: MetricDatum[] = [
{
MetricName: `${metricsPrefix}.success`,
Dimensions: [
{
Name: 'Target',
Value: target
},
{
Name: 'Region',
Value: region
}
],
Unit: 'Count',
Value: isTestPassed ? 1 : 0,
Timestamp: ts
},
{
MetricName: `${metricsPrefix}.failure`,
Dimensions: [
{
Name: 'Target',
Value: target
},
{
Name: 'Region',
Value: region
}
],
Unit: 'Count',
Value: isTestPassed ? 0 : 1,
Timestamp: ts
}
]

if (isTestPassed) {
metrics.push({
MetricName: `${metricsPrefix}.latency`,
Dimensions: [
{
Name: 'Target',
Value: target
},
{
Name: 'Region',
Value: region
}
],
Unit: 'Milliseconds',
Value: testDurationMs,
Timestamp: ts
})
}

const params: PutMetricDataCommandInput = {
MetricData: metrics,
Namespace: `${env}_Canary_Web3Modal`
}

await new Promise<void>(resolve => {
cloudwatch.putMetricData(params, (err: Error) => {
if (err) {
// eslint-disable-next-line no-console
console.error('Failed to upload metrics to CloudWatch', err, err.stack)
}
resolve()
})
})
}
Loading

0 comments on commit 49688f6

Please sign in to comment.