Skip to content

Commit 80f5c73

Browse files
committed
test(predict): align e2e mocks/fixtures with pUSD + CLOB v2 migration
After removing CLOB v1 and migrating Predict deposit/withdraw to pUSD, several smoke tests broke because the e2e mocks/fixtures still assumed the old USDC.e + CLOB v1 world. - POLYMARKET_USDC_BALANCE_MOCKS: route balanceOf for the pUSD address to the global mock balance, and zero out legacy USDC.e so deposit/ withdraw/claim/trade flows skip the new legacy-sweep maintenance path. - POLYMARKET_UPDATE_USDC_BALANCE_MOCKS / POLYMARKET_WITHDRAW_BALANCE_LOAD_MOCKS: match pUSD balanceOf instead of USDC.e, since the app now reads the Predict balance from pUSD. - POLYMARKET_POST_CASH_OUT_MOCKS: update SELL order matcher to the v2 shape (timestamp/metadata/builder; no taker/nonce/feeRateBps). Without this, the cash-out sheet never dismissed and the predict market details Back button wasn't reachable. - RELAY_QUOTE_MOCK currencyOut: switch from USDC.e to pUSD so the transaction-pay quote target matches the Predict deposit transaction target token (otherwise the pay-with row never resolves). - transaction-pay.spec.ts / predict-withdraw.spec.ts fixtures: seed pUSD instead of USDC.e in TokensController so confirmation amount encoding picks up decimals=6 immediately.
1 parent d9f1abb commit 80f5c73

4 files changed

Lines changed: 68 additions & 30 deletions

File tree

tests/api-mocking/mock-responses/polymarket/polymarket-mocks.ts

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -966,23 +966,41 @@ export const POLYMARKET_USDC_BALANCE_MOCKS = async (
966966
// Safe Factory call - return proxy wallet address
967967
result = MOCK_RPC_RESPONSES.SAFE_FACTORY_RESULT;
968968
} else if (
969-
toAddress?.toLowerCase() === USDC_CONTRACT_ADDRESS.toLowerCase()
969+
toAddress?.toLowerCase() === POLYGON_PUSD_TOKEN_ADDRESS.toLowerCase()
970970
) {
971-
// USDC contract call - check function selector
971+
// pUSD contract call (post-CLOB-v1 migration: Predict balance lives in pUSD).
972+
// Return the current global balance for balanceOf so the displayed Predict
973+
// balance comes from pUSD, matching production state for v2 users.
972974
if (callData?.toLowerCase()?.startsWith('0x70a08231')) {
973975
// balanceOf(address) selector - return current global balance
974976
result = currentUSDCBalance;
975977
} else if (callData?.toLowerCase()?.startsWith('0xdd62ed3e')) {
976-
// allowance(address,address) selector - return max allowance (uint256 max)
977-
// This indicates full allowance is granted
978+
// allowance(address,address) selector - max allowance
979+
result =
980+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
981+
} else {
982+
result = currentUSDCBalance;
983+
}
984+
} else if (
985+
toAddress?.toLowerCase() === USDC_CONTRACT_ADDRESS.toLowerCase()
986+
) {
987+
// Legacy Safe USDC.e contract call. Post-migration this balance is 0
988+
// so deposit/withdraw/claim/trade flows do not append the legacy sweep
989+
// maintenance transactions during E2E. Allowances stay maxed so any
990+
// unrelated reads still see the wallet as fully approved.
991+
if (callData?.toLowerCase()?.startsWith('0x70a08231')) {
992+
// balanceOf(address) selector - 0 (no legacy balance to sweep)
993+
result = MOCK_RPC_RESPONSES.EMPTY_RESULT;
994+
} else if (callData?.toLowerCase()?.startsWith('0xdd62ed3e')) {
995+
// allowance(address,address) selector - max allowance
978996
result =
979997
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
980998
} else if (callData?.toLowerCase()?.startsWith('0x6352211e')) {
981-
// ownerOf(uint256) selector - return owner of the token
999+
// ownerOf(uint256) selector
9821000
result = '0x';
9831001
} else {
984-
// Other USDC contract calls - return current global balance as fallback
985-
result = currentUSDCBalance;
1002+
// Other legacy USDC.e contract calls
1003+
result = MOCK_RPC_RESPONSES.EMPTY_RESULT;
9861004
}
9871005
} else if (
9881006
toAddress?.toLowerCase() === MULTICALL_CONTRACT_ADDRESS.toLowerCase()
@@ -1475,7 +1493,7 @@ export const POLYMARKET_UPDATE_USDC_BALANCE_MOCKS = async (
14751493
return false;
14761494
}
14771495

1478-
// Parse body to ensure this is a USDC balance call
1496+
// Parse body to ensure this is a pUSD balance call
14791497
try {
14801498
const bodyText = await request.body.getText();
14811499
const body = bodyText ? JSON.parse(bodyText) : undefined;
@@ -1485,9 +1503,9 @@ export const POLYMARKET_UPDATE_USDC_BALANCE_MOCKS = async (
14851503
const toAddress = body?.params?.[0]?.to?.toLowerCase();
14861504
const callData = body?.params?.[0]?.data;
14871505
const isMatch =
1488-
toAddress === USDC_CONTRACT_ADDRESS.toLowerCase() &&
1506+
toAddress === POLYGON_PUSD_TOKEN_ADDRESS.toLowerCase() &&
14891507
callData?.toLowerCase()?.startsWith('0x70a08231');
1490-
// Only match USDC balanceOf calls
1508+
// Only match pUSD balanceOf calls (post-CLOB-v1 Predict balance source)
14911509
return isMatch;
14921510
} catch (error) {
14931511
return false;
@@ -1546,15 +1564,23 @@ export const POLYMARKET_POST_CASH_OUT_MOCKS = async (mockServer: Mockttp) => {
15461564

15471565
// Verify the request matches cash-out order structure
15481566
// Only check consistent fields - allow variable values for dynamic fields (salt, tokenId, amounts, signature, owner)
1567+
// CLOB v2 SELL order shape — see
1568+
// app/components/UI/Predict/providers/polymarket/protocol/orderCodec.ts
1569+
// (`buildProtocolUnsignedOrder`/`serializeProtocolRelayerOrder`).
1570+
// v2 orders have `timestamp`, `metadata`, `builder`; v1-only fields
1571+
// (`taker`, `nonce`, `feeRateBps`) were removed when CLOB v1 support
1572+
// was dropped, so this matcher must not check them.
15491573
return (
15501574
order &&
15511575
(body.orderType === 'FOK' || body.orderType === 'FAK') &&
15521576
order.maker?.toLowerCase() === PROXY_WALLET_ADDRESS.toLowerCase() &&
15531577
order.signer?.toLowerCase() === USER_WALLET_ADDRESS.toLowerCase() &&
1554-
order.taker === '0x0000000000000000000000000000000000000000' &&
15551578
order.expiration === '0' &&
1556-
order.nonce === '0' &&
1557-
typeof order.feeRateBps === 'string' &&
1579+
typeof order.timestamp === 'string' &&
1580+
typeof order.metadata === 'string' &&
1581+
order.metadata.startsWith('0x') &&
1582+
typeof order.builder === 'string' &&
1583+
order.builder.startsWith('0x') &&
15581584
order.side === 'SELL' &&
15591585
order.signatureType === 2 &&
15601586
typeof order.salt === 'number' &&
@@ -1878,12 +1904,14 @@ export const POLYMARKET_WITHDRAW_BALANCE_LOAD_MOCKS = async (
18781904
try {
18791905
const bodyText = await request.body.getText();
18801906
const body = bodyText ? JSON.parse(bodyText) : undefined;
1881-
const isUSDCBalanceCall =
1907+
// Match pUSD balanceOf calls — post-CLOB-v1 migration the Predict
1908+
// balance lives in pUSD, so withdraw flow refreshes target pUSD.
1909+
const isPusdBalanceCall =
18821910
body?.method === 'eth_call' &&
18831911
body?.params?.[0]?.to?.toLowerCase() ===
1884-
USDC_CONTRACT_ADDRESS.toLowerCase();
1912+
POLYGON_PUSD_TOKEN_ADDRESS.toLowerCase();
18851913

1886-
return isUSDCBalanceCall;
1914+
return isPusdBalanceCall;
18871915
} catch (error) {
18881916
return false;
18891917
}

tests/api-mocking/mock-responses/transaction-pay.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const RELAY_QUOTE_MOCK = {
88
id: 'deposit',
99
action: 'Confirm transaction in your wallet',
1010
description:
11-
'Depositing funds to the relayer to execute the swap for USDC.e',
11+
'Depositing funds to the relayer to execute the swap for pUSD',
1212
kind: 'transaction',
1313
items: [
1414
{
@@ -162,10 +162,15 @@ export const RELAY_QUOTE_MOCK = {
162162
},
163163
currencyOut: {
164164
currency: {
165+
// Polymarket USD (pUSD) — the new Predict deposit/withdraw collateral
166+
// after CLOB v1 was removed. Must match POLYGON_PUSD in
167+
// app/components/Views/confirmations/constants/predict.ts so the
168+
// transaction-pay quote target matches the Predict deposit transaction
169+
// target token (otherwise the pay-with row never resolves).
165170
chainId: 137,
166-
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
167-
symbol: 'USDC.e',
168-
name: 'USDCoin (bridged)',
171+
address: '0xc011a7e12a19f7b1f670d46f03b03f3342e82dfb',
172+
symbol: 'pUSD',
173+
name: 'Polymarket USD',
169174
decimals: 6,
170175
metadata: {
171176
logoURI: 'https://ethereum-optimism.github.io/data/USDC/logo.png',

tests/smoke/confirmations/transactions/transaction-pay.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ describe(SmokeConfirmations('Transaction Pay'), () => {
3030
{
3131
fixture: new FixtureBuilder()
3232
.withPolygon()
33+
// Polymarket USD (pUSD) is the Predict deposit collateral after CLOB v1
34+
// was removed. Seed it in TokensController so the deposit confirmation's
35+
// useUpdateTokenAmount picks up decimals=6 immediately, instead of
36+
// racing with PredictDepositInfo's async useAddToken call.
3337
.withTokens(
3438
[
3539
{
36-
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
40+
address: '0xc011a7e12a19f7b1f670d46f03b03f3342e82dfb',
3741
decimals: 6,
38-
name: 'USD Coin (PoS)',
39-
symbol: 'USDC.e',
42+
name: 'Polymarket USD',
43+
symbol: 'pUSD',
4044
},
4145
],
4246
CHAIN_IDS.POLYGON,

tests/smoke/predict/predict-withdraw.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ describe(SmokePredictions('Predictions Withdraw'), () => {
4848
{
4949
fixture: new FixtureBuilder()
5050
.withPolygon()
51-
// Polygon bridged USDC must be in TokenController so confirmation's
52-
// useUpdateTokenAmount gets decimals=6. Otherwise decimals fall back to 18 and
53-
// "5" USDC is encoded as 5e18 raw — Predict signWithdraw then throws
54-
// "Decoded USDC amount is invalid or too large".
51+
// Polymarket USD (pUSD) is the Predict withdraw token after CLOB v1
52+
// was removed. It must be in TokenController so the confirmation's
53+
// useUpdateTokenAmount gets decimals=6. Otherwise decimals fall back
54+
// to 18 and "5" pUSD is encoded as 5e18 raw — Predict signWithdraw
55+
// then throws "Decoded USDC amount is invalid or too large".
5556
.withTokens(
5657
[
5758
{
58-
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
59+
address: '0xc011a7e12a19f7b1f670d46f03b03f3342e82dfb',
5960
decimals: 6,
60-
name: 'USD Coin (PoS)',
61-
symbol: 'USDC.e',
61+
name: 'Polymarket USD',
62+
symbol: 'pUSD',
6263
},
6364
],
6465
CHAIN_IDS.POLYGON,

0 commit comments

Comments
 (0)