-
Notifications
You must be signed in to change notification settings - Fork 177
test(e2e): hooks store autotests #8000
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
Open
shoom3301
wants to merge
14
commits into
e2e/market-orders
Choose a base branch
from
e2e/hooks-store
base: e2e/market-orders
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
66f68cd
Merge branch 'e2e/market-orders' of https://github.com/cowprotocol/co…
shoom3301 1e710f6
test(e2e): add [CS-129] enable Hooks via settings toggle
elena-zh 3b3d220
Merge branch 'e2e/market-orders' into e2e/hooks-store
elena-zh ebc2c4b
test(e2e): add [CS-136] Hooks: cross-chain swaps are not available
elena-zh 8495f2c
test(e2e): split [CS-136]'s known-gap check into a fixme test
elena-zh af442bd
test(e2e): remove [CS-136b], strengthen [CS-136]'s reset assertions
elena-zh 9023c8f
test(e2e): pin a sane 1:1 quote rate in [CS-136]
elena-zh 9b1bf45
test(e2e): assert [CS-136]'s reset form is actionable, not just quoted
elena-zh 2d067c7
test(e2e): use the real recorded quote rate in [CS-136], not 1:1
elena-zh 059e61c
test(e2e): add [CS-131] Add a Pre-hook to a swap order
elena-zh dd545d4
test(e2e): harden [CS-131] with real Settings flow, simulation, and l…
elena-zh 86cd3c6
fix(e2e): stop faking broken WETH/USDC/hook logos as black circles in…
elena-zh c6c0412
fix(e2e): resolve real WETH/USDC icons in [CS-131] mock, tag CS-129/1…
elena-zh f87f9f0
fix(e2e): address CodeRabbit review on [CS-129]/[CS-131]/[CS-136]
elena-zh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/cowswap-e2e-tests/src/support/mockBridgeSupportedTokens.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type { BrowserContext } from '@playwright/test' | ||
|
|
||
| export interface MockedBridgeToken { | ||
| address: string | ||
| symbol: string | ||
| name: string | ||
| decimals: number | ||
| chainId: number | ||
| } | ||
|
|
||
| /** | ||
| * Stubs the Bungee/Socket bridge provider's `/dest-tokens` endpoint (`BungeeApi.getBuyTokens` in | ||
| * `@cowprotocol/sdk-bridging`), which both `useBridgeSupportedTokens` (resolving/listing buyable | ||
| * tokens on a target chain) and `useRoutesAvailability` (is this destination chain reachable at | ||
| * all) call under the hood — mocking this one REST call satisfies both, since Bungee is the only | ||
| * enabled provider (`bridgingSdk.setAvailableProviders([bungeeBridgeProvider.info.dappId])`). | ||
| * Response shape: `{ success: true, result: TokenInfo[] }`, where the SDK maps each entry's | ||
| * `logoURI` to `logoUrl` and otherwise passes it through as-is. | ||
| */ | ||
| export async function mockBridgeSupportedTokens(context: BrowserContext, tokens: MockedBridgeToken[]): Promise<void> { | ||
| await context.route(/bungee-manual\/dest-tokens/i, async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ success: true, result: tokens }), | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import path from 'path' | ||
|
|
||
| import type { BrowserContext, Route } from '@playwright/test' | ||
|
|
||
| const BUILD_CUSTOM_HOOK_LOGO_PATH = path.resolve( | ||
| __dirname, | ||
| '../../../cowswap-frontend/src/modules/hooksStore/dapps/BuildHookApp/build.png', | ||
| ) | ||
|
|
||
| /** | ||
| * Stubs `hookDappsRegistry.ts`'s `BUILD_CUSTOM_HOOK.image` — a `raw.githubusercontent.com` URL with no | ||
| * test-side mock and no frontend-side `onError` fallback (`HookItem` just renders `<img src={...} />` | ||
| * with nothing to show if the request fails). Any hiccup reaching GitHub from the test runner renders a | ||
| * bare placeholder box instead of the hook's hard-hat icon. Fulfilling from the same `build.png` already | ||
| * checked into the frontend source removes that live network dependency entirely. | ||
| */ | ||
| export async function mockHookLogo(context: BrowserContext): Promise<void> { | ||
| await context.route( | ||
| /raw\.githubusercontent\.com\/cowprotocol\/cowswap\/.*\/BuildHookApp\/build\.png/i, | ||
| async (route: Route) => { | ||
| await route.fulfill({ status: 200, contentType: 'image/png', path: BUILD_CUSTOM_HOOK_LOGO_PATH }) | ||
| }, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { BrowserContext, Route } from '@playwright/test' | ||
|
|
||
| /** | ||
| * Stubs the Tenderly bundle-simulation endpoint (`bundleSimulation.ts`'s `simulateBundle`, hit at | ||
| * `{BFF_BASE_URL}/{chainId}/simulation/simulateBundle`) that `useTenderlyBundleSimulation` POSTs to | ||
| * once the trade-confirmation screen mounts with at least one hook attached. Real endpoint, never | ||
| * mocked before this — `HookItem` renders "Simulation successful"/"Simulation failed" straight off | ||
| * each response entry's `status` boolean, positionally matched to the posted pre/post hooks. | ||
| */ | ||
| export async function mockHooksSimulation(context: BrowserContext, opts: { status?: boolean } = {}): Promise<void> { | ||
| const status = opts.status ?? true | ||
|
|
||
| await context.route(/bff\.(?:barn\.)?cow\.fi\/\d+\/simulation\/simulateBundle/i, async (route: Route) => { | ||
| const postedHooks = JSON.parse(route.request().postData() || '[]') as unknown[] | ||
| const body = postedHooks.map((_, index) => ({ | ||
| link: `https://dashboard.tenderly.co/mock-simulation-${index}`, | ||
| status, | ||
| id: `mock-simulation-${index}`, | ||
| cumulativeBalancesDiff: {}, | ||
| stateDiff: [], | ||
| gasUsed: '21000', | ||
| })) | ||
| await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(body) }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { getAddressKey } from '@cowprotocol/cow-sdk' | ||
|
|
||
| import type { BrowserContext, Route } from '@playwright/test' | ||
|
|
||
| // This suite's Sepolia test-token deployments (`WETH`/`USDC` in `market-orders.spec.ts`) aren't on | ||
| // any token list, so every URL `useTokenLogoUrl` tries — keyed off these same addresses on every | ||
| // chain it checks — 403s against the real CDN (verified directly). Redirecting to each token's real | ||
| // mainnet counterpart resolves to the actual brand icon instead of a broken image or a letter avatar. | ||
| const REAL_MAINNET_ADDRESS: Record<string, string> = { | ||
| [getAddressKey('0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14')]: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH | ||
| [getAddressKey('0xbe72E441BF55620febc26715db68d3494213D8Cb')]: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC | ||
| } | ||
|
|
||
| const LOGO_PATH_RE = /\/token-lists\/images\/\d+\/(0x[a-fA-F0-9]{40})\/logo\.png$/i | ||
|
|
||
| /** | ||
| * Stubs `cowprotocolTokenLogoUrl`'s CDN endpoint (`files.cow.fi/token-lists/images/:chainId/:address/logo.png`) | ||
| * for this suite's test-token addresses, redirecting each to its real mainnet counterpart's logo | ||
| * (same technique as `route.fetch()`'s upstream-merge helpers elsewhere in this folder, just fetching | ||
| * a different URL instead of the same one). Anything not in `REAL_MAINNET_ADDRESS` falls back to a | ||
| * plain 404, matching the real CDN's own behavior for an unlisted token — that keeps `TokenLogo`'s | ||
| * `onError` fallback (`SingleLetterLogo`) intact rather than masking it with a fake "successful" image. | ||
| */ | ||
| export async function mockTokenLogos(context: BrowserContext): Promise<void> { | ||
| await context.route(/files\.cow\.fi\/token-lists\/images\//i, async (route: Route) => { | ||
| const match = new URL(route.request().url()).pathname.match(LOGO_PATH_RE) | ||
| const realAddress = match && REAL_MAINNET_ADDRESS[getAddressKey(match[1])] | ||
|
|
||
| if (!realAddress) { | ||
| await route.fulfill({ status: 404 }) | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| const response = await route.fetch({ url: `https://files.cow.fi/token-lists/images/1/${realAddress}/logo.png` }) | ||
| await route.fulfill({ response }) | ||
| } catch { | ||
| await route.fulfill({ status: 404 }) | ||
| } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.