Skip to content

Commit f1762b9

Browse files
Revert "feat: sync source with clear-pools-ui E2E-tested implementation"
This reverts commit 6ee9a79.
1 parent 6ee9a79 commit f1762b9

File tree

88 files changed

+3181
-2781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3181
-2781
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coinbase/onchaintestkit",
3-
"version": "1.3.0",
3+
"version": "1.2.0",
44
"description": "End-to-end testing toolkit for blockchain applications, powered by Playwright",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/cli/prepare-coinbase.mjs

Lines changed: 99 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,216 +8,226 @@
88
* is ready and to avoid race conditions during test execution.
99
*/
1010

11-
import path from 'path';
12-
import { fileURLToPath } from 'url';
13-
import extract from 'extract-zip';
14-
import fs from 'fs-extra';
15-
import fetch from 'node-fetch';
11+
import path from "path"
12+
import { fileURLToPath } from "url"
13+
import extract from "extract-zip"
14+
import fs from "fs-extra"
15+
import fetch from "node-fetch"
1616

1717
// Support for ES modules
18-
const __filename = fileURLToPath(import.meta.url);
19-
const __dirname = path.dirname(__filename);
18+
const __filename = fileURLToPath(import.meta.url)
19+
const __dirname = path.dirname(__filename)
2020

2121
// Constants for Coinbase Wallet
22-
const COINBASE_VERSION = '3.117.1';
23-
const EXTENSION_ID = 'hnfanknocfeofbddgcijnmhnfnkdnaad';
24-
const DOWNLOAD_URL = `https://update.googleapis.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=unknown&prodversion=120.0.0.0&acceptformat=crx3&x=id%3D${EXTENSION_ID}%26uc`;
25-
const EXTRACTION_COMPLETE_FLAG = '.extraction_complete';
22+
const COINBASE_VERSION = "3.117.1"
23+
const EXTENSION_ID = "hnfanknocfeofbddgcijnmhnfnkdnaad"
24+
const DOWNLOAD_URL = `https://update.googleapis.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=unknown&prodversion=120.0.0.0&acceptformat=crx3&x=id%3D${EXTENSION_ID}%26uc`
25+
const EXTRACTION_COMPLETE_FLAG = ".extraction_complete"
2626

2727
/**
2828
* Set up the cache directory structure
2929
*/
3030
async function setupCacheDir(cacheDirName) {
31-
const projectRoot = process.cwd();
32-
const cacheDirPath = path.join(projectRoot, 'e2e', '.cache', cacheDirName);
31+
const projectRoot = process.cwd()
32+
const cacheDirPath = path.join(projectRoot, "e2e", ".cache", cacheDirName)
3333

3434
// Ensure the cache directory exists
35-
await fs.ensureDir(cacheDirPath);
35+
await fs.ensureDir(cacheDirPath)
3636

37-
return cacheDirPath;
37+
return cacheDirPath
3838
}
3939

4040
/**
4141
* Download with retry logic for CI environments
4242
*/
4343
async function downloadWithRetry(url, options, maxRetries = 3) {
44-
let lastError;
44+
let lastError
4545

4646
for (let attempt = 1; attempt <= maxRetries; attempt++) {
4747
try {
48-
console.log(`Download attempt ${attempt} of ${maxRetries}...`);
49-
const response = await fetch(url, options);
48+
console.log(`Download attempt ${attempt} of ${maxRetries}...`)
49+
const response = await fetch(url, options)
5050

5151
if (!response.ok) {
52-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
52+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
5353
}
5454

55-
return response;
55+
return response
5656
} catch (error) {
57-
lastError = error;
58-
console.error(`Attempt ${attempt} failed: ${error.message}`);
57+
lastError = error
58+
console.error(`Attempt ${attempt} failed: ${error.message}`)
5959

6060
if (attempt < maxRetries) {
61-
const waitTime = Math.min(1000 * 2 ** (attempt - 1), 10000);
62-
console.log(`Waiting ${waitTime}ms before retry...`);
63-
await new Promise((resolve) => setTimeout(resolve, waitTime));
61+
const waitTime = Math.min(1000 * 2 ** (attempt - 1), 10000)
62+
console.log(`Waiting ${waitTime}ms before retry...`)
63+
await new Promise(resolve => setTimeout(resolve, waitTime))
6464
}
6565
}
6666
}
6767

68-
throw new Error(`Failed after ${maxRetries} attempts: ${lastError.message}`);
68+
throw new Error(`Failed after ${maxRetries} attempts: ${lastError.message}`)
6969
}
7070

7171
/**
7272
* Prepares the Coinbase Wallet extension by downloading and extracting it
7373
*/
7474
async function setupCoinbaseExtraction() {
75-
console.log(`Preparing Coinbase Wallet extension v${COINBASE_VERSION}...`);
75+
console.log(`Preparing Coinbase Wallet extension v${COINBASE_VERSION}...`)
7676

7777
// Set up the cache directory
78-
const cacheDir = await setupCacheDir('coinbase-extension');
79-
const extractionPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}`);
80-
const flagPath = path.join(extractionPath, EXTRACTION_COMPLETE_FLAG);
78+
const cacheDir = await setupCacheDir("coinbase-extension")
79+
const extractionPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}`)
80+
const flagPath = path.join(extractionPath, EXTRACTION_COMPLETE_FLAG)
8181

8282
// Download the CRX file
83-
const crxPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}.crx`);
84-
console.log(`Downloading Coinbase Wallet extension to: ${crxPath}`);
83+
const crxPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}.crx`)
84+
console.log(`Downloading Coinbase Wallet extension to: ${crxPath}`)
8585

8686
// Check if file already exists
87-
let cached = false;
87+
let cached = false
8888
if (await fs.pathExists(crxPath)) {
89-
const stats = await fs.stat(crxPath);
89+
const stats = await fs.stat(crxPath)
9090
if (stats.size > 0) {
91-
console.log(`Using cached download at ${crxPath}`);
92-
cached = true;
91+
console.log(`Using cached download at ${crxPath}`)
92+
cached = true
9393
}
9494
}
9595

9696
// Download if not cached
9797
if (!cached) {
98-
console.log('Downloading from Chrome Web Store...');
98+
console.log("Downloading from Chrome Web Store...")
9999
try {
100100
// Attempt download with retry logic
101101
const response = await downloadWithRetry(
102102
DOWNLOAD_URL,
103103
{
104-
redirect: 'follow',
104+
redirect: "follow",
105105
follow: 20,
106106
},
107107
3,
108-
);
108+
)
109109

110-
const contentType = response.headers.get('content-type');
111-
console.log(`Response content-type: ${contentType}`);
110+
const contentType = response.headers.get("content-type")
111+
console.log(`Response content-type: ${contentType}`)
112112

113-
const buffer = await response.arrayBuffer();
113+
const buffer = await response.arrayBuffer()
114114

115-
await fs.writeFile(crxPath, Buffer.from(buffer));
116-
console.log('Download complete');
115+
await fs.writeFile(crxPath, Buffer.from(buffer))
116+
console.log("Download complete")
117117

118118
// Verify the download
119-
const downloadedStats = await fs.stat(crxPath);
119+
const downloadedStats = await fs.stat(crxPath)
120120
if (downloadedStats.size === 0) {
121-
await fs.remove(crxPath);
121+
await fs.remove(crxPath)
122122
throw new Error(
123-
'Downloaded file is empty. The Chrome Web Store might be blocking automated downloads.',
124-
);
123+
"Downloaded file is empty. The Chrome Web Store might be blocking automated downloads.",
124+
)
125125
}
126126
} catch (error) {
127-
throw new Error(`Extension download failed: ${error.message}`);
127+
throw new Error(`Extension download failed: ${error.message}`)
128128
}
129129
}
130130

131131
// Clean any existing extraction directory
132132
if (await fs.pathExists(extractionPath)) {
133-
console.log(`Cleaning existing directory: ${extractionPath}`);
134-
await fs.emptyDir(extractionPath);
133+
console.log(`Cleaning existing directory: ${extractionPath}`)
134+
await fs.emptyDir(extractionPath)
135135
}
136136

137137
// Extract the CRX file
138-
console.log(`Extracting to: ${extractionPath}`);
138+
console.log(`Extracting to: ${extractionPath}`)
139139
try {
140140
// Read the CRX file
141-
const crxBuffer = await fs.readFile(crxPath);
142-
console.log(`CRX file size: ${crxBuffer.length} bytes`);
141+
const crxBuffer = await fs.readFile(crxPath)
142+
console.log(`CRX file size: ${crxBuffer.length} bytes`)
143143

144144
// CRX3 files start with "Cr24" magic number
145-
const crx3Magic = Buffer.from('Cr24');
145+
const crx3Magic = Buffer.from("Cr24")
146146

147-
let zipStart = -1;
147+
let zipStart = -1
148148

149149
if (crxBuffer.subarray(0, 4).equals(crx3Magic)) {
150-
console.log('Detected CRX3 format');
150+
console.log("Detected CRX3 format")
151151
// CRX3 format:
152152
// 4 bytes: "Cr24" magic
153153
// 4 bytes: version (3)
154154
// 4 bytes: header length
155-
const version = crxBuffer.readUInt32LE(4);
156-
const headerLength = crxBuffer.readUInt32LE(8);
157-
console.log(`CRX version: ${version}, header length: ${headerLength}`);
155+
const version = crxBuffer.readUInt32LE(4)
156+
const headerLength = crxBuffer.readUInt32LE(8)
157+
console.log(`CRX version: ${version}, header length: ${headerLength}`)
158158

159159
// ZIP content starts after the header
160-
zipStart = 12 + headerLength;
160+
zipStart = 12 + headerLength
161161
} else {
162-
throw new Error("Invalid CRX file format - expected CRX3 with 'Cr24' header");
162+
throw new Error(
163+
"Invalid CRX file format - expected CRX3 with 'Cr24' header",
164+
)
163165
}
164166

165167
// Extract the ZIP portion
166-
const zipBuffer = crxBuffer.subarray(zipStart);
167-
console.log(`Extracting ZIP content from offset ${zipStart}, size: ${zipBuffer.length} bytes`);
168+
const zipBuffer = crxBuffer.subarray(zipStart)
169+
console.log(
170+
`Extracting ZIP content from offset ${zipStart}, size: ${zipBuffer.length} bytes`,
171+
)
168172

169-
const zipPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}.zip`);
170-
await fs.writeFile(zipPath, zipBuffer);
173+
const zipPath = path.join(cacheDir, `coinbase-${COINBASE_VERSION}.zip`)
174+
await fs.writeFile(zipPath, zipBuffer)
171175

172176
// Now extract the ZIP file
173-
await extract(zipPath, { dir: extractionPath });
177+
await extract(zipPath, { dir: extractionPath })
174178

175179
// Clean up the temporary ZIP file
176-
await fs.remove(zipPath);
180+
await fs.remove(zipPath)
177181

178182
// Verify extraction succeeded
179-
const manifestPath = path.join(extractionPath, 'manifest.json');
183+
const manifestPath = path.join(extractionPath, "manifest.json")
180184
if (!(await fs.pathExists(manifestPath))) {
181-
throw new Error(`Extraction failed: manifest.json not found at ${manifestPath}`);
185+
throw new Error(
186+
`Extraction failed: manifest.json not found at ${manifestPath}`,
187+
)
182188
}
183189

184190
// Create flag file to indicate successful extraction
185-
await fs.writeFile(flagPath, new Date().toISOString());
191+
await fs.writeFile(flagPath, new Date().toISOString())
186192

187-
console.log(`Coinbase Wallet extension successfully prepared at: ${extractionPath}`);
188-
return extractionPath;
193+
console.log(
194+
`Coinbase Wallet extension successfully prepared at: ${extractionPath}`,
195+
)
196+
return extractionPath
189197
} catch (error) {
190-
console.error(`Error extracting CRX: ${error.message}`);
198+
console.error(`Error extracting CRX: ${error.message}`)
191199
// Clean up on failure
192200
try {
193-
await fs.emptyDir(extractionPath);
201+
await fs.emptyDir(extractionPath)
194202
} catch (cleanupError) {
195-
console.error(`Failed to clean up: ${cleanupError.message}`);
203+
console.error(`Failed to clean up: ${cleanupError.message}`)
196204
}
197205

198-
throw new Error(`Extraction failed: ${error.message}`);
206+
throw new Error(`Extraction failed: ${error.message}`)
199207
}
200208
}
201209

202210
async function main() {
203211
try {
204-
console.log('Preparing Coinbase Wallet extension for tests...');
212+
console.log("Preparing Coinbase Wallet extension for tests...")
205213

206214
// Run the setup function
207-
const extensionPath = await setupCoinbaseExtraction();
208-
console.log(`Coinbase Wallet extension prepared successfully at: ${extensionPath}`);
209-
console.log('You can now run the tests!');
215+
const extensionPath = await setupCoinbaseExtraction()
216+
console.log(
217+
`Coinbase Wallet extension prepared successfully at: ${extensionPath}`,
218+
)
219+
console.log("You can now run the tests!")
210220

211-
process.exit(0);
221+
process.exit(0)
212222
} catch (error) {
213-
console.error('Failed to prepare Coinbase Wallet extension:');
214-
console.error(error);
215-
process.exit(1);
223+
console.error("Failed to prepare Coinbase Wallet extension:")
224+
console.error(error)
225+
process.exit(1)
216226
}
217227
}
218228

219229
// Run the main function with proper promise handling
220-
main().catch((error) => {
221-
console.error('Unhandled error in main function:', error);
222-
process.exit(1);
223-
});
230+
main().catch(error => {
231+
console.error("Unhandled error in main function:", error)
232+
process.exit(1)
233+
})

0 commit comments

Comments
 (0)