1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import { expect, test } from "@playwright/test";
import {
aliceUsername,
alicePassword,
login,
getBitcoinAddress,
pasteAndSend,
fillNumpadAmount,
waitForSentRedirect,
setActiveAccount,
} from "./helpers";
test("bitcoin vault sends to external bitcoin address with PSBT signing", async ({ page }) => {
test.setTimeout(120_000);
// Capture console errors for debugging
const consoleErrors: string[] = [];
page.on("console", (msg) => {
if (msg.type() === "error") {
consoleErrors.push(msg.text());
}
});
page.on("pageerror", (err) => {
consoleErrors.push(`PAGE ERROR: ${err.message}`);
});
// --- Alice: log in ---
await login(page, aliceUsername, alicePassword);
// --- Find the bitcoin vault account and switch to it ---
const vaultCard = page.locator('[data-testid="account-card"][data-account-type="bitcoin"]');
const vaultCount = await vaultCard.count();
if (vaultCount === 0) {
test.skip(true, "No bitcoin vault account found");
return;
}
const accountHref = await vaultCard
.first()
.locator('a[href^="/account/"]')
.first()
.getAttribute("href");
const vaultAid = accountHref?.split("/account/")[1];
expect(vaultAid).toBeTruthy();
await setActiveAccount(page, vaultAid!);
console.log(`[e2e] Switched to vault account: ${vaultAid}`);
// --- Get external bitcoin address (from 'external' wallet, not 'coinos') ---
const externalAddress = getBitcoinAddress();
console.log(`[e2e] External bitcoin address: ${externalAddress}`);
// --- Paste address and send ---
await pasteAndSend(page, externalAddress);
const pageUrl = page.url();
console.log(`[e2e] Navigated to: ${pageUrl}`);
expect(pageUrl).toContain("/send/bitcoin/");
// Enter amount on numpad
await fillNumpadAmount(page, 1000);
// Now on the fee/send page
await page.waitForURL(/\/send\/bitcoin\/[^/]+\/\d+/, { timeout: 10_000 });
console.log(`[e2e] On fee page: ${page.url()}`);
// Check for error message on the fee page (load error)
const loadError = await page
.locator(".text-red-600")
.first()
.innerText({ timeout: 1000 })
.catch(() => "");
if (loadError) {
console.log(`[e2e] Fee page error: ${loadError}`);
test.skip(true, `Fee page error: ${loadError}`);
return;
}
// Click Send — this triggers the WalletPass dialog for vault accounts
const sendButton = page.locator('button[type="submit"]:not([data-testid="walletpass-submit"])');
await expect(sendButton).toBeVisible({ timeout: 5_000 });
await sendButton.click();
// Wait for WalletPass dialog
const walletPassInput = page.getByTestId("walletpass-input");
const walletPassVisible = await walletPassInput
.first()
.isVisible({ timeout: 5000 })
.catch(() => false);
if (walletPassVisible) {
console.log("[e2e] WalletPass dialog appeared, entering password...");
await walletPassInput.fill(alicePassword);
// Click the WalletPass Submit button specifically
const walletPassSubmit = page.getByTestId("walletpass-submit");
await expect(walletPassSubmit).toBeVisible({ timeout: 3_000 });
await walletPassSubmit.click();
console.log("[e2e] WalletPass submitted, waiting for PSBT signing...");
// Wait for either /sent/ redirect or the dialog to close (signing done)
const sent = await page
.waitForURL(/\/sent\//, { timeout: 60_000 })
.then(() => true)
.catch(() => false);
if (!sent) {
// Check if dialog closed and we need to click Send again
const dialogStillOpen = await walletPassInput
.first()
.isVisible({ timeout: 1000 })
.catch(() => false);
if (!dialogStillOpen) {
console.log("[e2e] Dialog closed, clicking Send again...");
const sendAgain = page.locator('button[type="submit"]:visible');
if (await sendAgain.isVisible().catch(() => false)) {
await sendAgain.click();
await waitForSentRedirect(page, 30_000);
}
} else {
console.log("[e2e] Dialog still open after 60s");
if (consoleErrors.length > 0) {
console.log(`[e2e] Console errors: ${consoleErrors.join("; ")}`);
// Client-side PSBT signing may fail if esplora/PSBT format is not
// properly configured in the test environment
const signingError = consoleErrors.some(
(e) => e.includes("invalid tag") || e.includes("decrypt") || e.includes("PSBT"),
);
if (signingError) {
test.skip(
true,
"PSBT signing failed (likely test env issue): " + consoleErrors.join("; "),
);
return;
}
}
expect(false, "WalletPass signing timed out").toBeTruthy();
}
}
} else {
console.log("[e2e] No WalletPass (cached password), waiting for redirect...");
await waitForSentRedirect(page, 30_000);
}
if (consoleErrors.length > 0) {
console.log(`[e2e] Console errors during test: ${consoleErrors.join("; ")}`);
}
console.log(`[e2e] Vault BTC payment sent: ${page.url()}`);
});
|