Merge pull request 'fix: Swap completion detection relies on a fragile timing assumption (#415)' (#499) from fix/issue-415 into master

This commit is contained in:
johba 2026-03-06 10:55:54 +01:00
commit a6c238570f
2 changed files with 23 additions and 13 deletions

View file

@ -184,16 +184,21 @@ test.describe('Acquire & Stake', () => {
console.log('[TEST] Clicking Buy KRK button...');
await buyButton.click();
// Wait for button to show "Submitting..." then return to "Buy KRK"
// Wait for swap to complete. The button becomes disabled (swapping=true) while the
// transaction is in flight and re-enables (swapping=false) when it finishes.
// Try to observe the disabled state first; if the RPC responds so fast that the
// disabled state cycles before we can observe it, the try throws and we fall through.
// Either way, the unconditional toBeEnabled() call below waits for the final ready
// state, covering both fast-RPC (already enabled) and slow-RPC (waiting to enable) paths.
console.log('[TEST] Waiting for swap to process...');
try {
await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 });
console.log('[TEST] Swap initiated, waiting for completion...');
await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 });
console.log('[TEST] Swap completed!');
} catch (e) {
console.log('[TEST] No "Submitting" state detected, swap may have completed instantly');
await expect(buyButton).toBeDisabled({ timeout: 5_000 });
console.log('[TEST] Swap initiated...');
} catch {
console.log('[TEST] Swap completed before disabled state was observable (fast RPC).');
}
await expect(buyButton).toBeEnabled({ timeout: 60_000 });
console.log('[TEST] Swap completed!');
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: no event source exists for Ponder indexing lag and UI re-renders after on-chain transactions in E2E tests. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(2_000);

View file

@ -194,15 +194,20 @@ test.describe('Max Stake All Tax Rates', () => {
await expect(buyButton).toBeVisible();
await buyButton.click();
// Wait for swap to complete
// Wait for swap to complete. The button becomes disabled (swapping=true) while the
// transaction is in flight and re-enables (swapping=false) when it finishes.
// Try to observe the disabled state first; if the RPC responds so fast that the
// disabled state cycles before we can observe it, the try throws and we fall through.
// Either way, the unconditional toBeEnabled() call below waits for the final ready
// state, covering both fast-RPC (already enabled) and slow-RPC (waiting to enable) paths.
console.log('[TEST] Waiting for swap to process...');
try {
await page.getByRole('button', { name: /Submitting/i }).waitFor({ state: 'visible', timeout: 5_000 });
await expect(page.getByTestId('swap-buy-button')).toHaveText('Buy KRK', { timeout: 60_000 });
console.log('[TEST] Swap completed!');
} catch (e) {
console.log('[TEST] Swap may have completed instantly');
await expect(buyButton).toBeDisabled({ timeout: 5_000 });
} catch {
console.log('[TEST] Swap completed before disabled state was observable (fast RPC).');
}
await expect(buyButton).toBeEnabled({ timeout: 60_000 });
console.log('[TEST] Swap completed!');
// eslint-disable-next-line no-restricted-syntax -- waitForTimeout: no event source exists for Ponder indexing lag and UI re-renders after on-chain transactions in E2E tests. See AGENTS.md #Engineering Principles.
await page.waitForTimeout(2_000);