-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_utils.js
More file actions
133 lines (111 loc) · 3.4 KB
/
test_utils.js
File metadata and controls
133 lines (111 loc) · 3.4 KB
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
// Test utilities for Arbitrum Pulse Orbit Chain demos
const { ethers } = require('ethers');
// Mock implementation of createRollupChain for testing
const mockCreateRollupChain = async (wallet, config) => {
console.log(`[MOCK] Creating Orbit Chain: ${config.chainName}`);
// Return mock deployment data
return {
chainId: config.chainId,
rpcUrl: `https://mock-rpc-${config.chainId}.arbitrum.io/rpc`,
explorerUrl: `https://mock-explorer-${config.chainId}.arbitrum.io`,
};
};
// Mock provider for testing
class MockProvider {
constructor(url) {
this.url = url;
console.log(`[MOCK] Connected to: ${url}`);
}
// Add minimal required functionality
getSigner() {
return { address: '0xMockAddress' };
}
}
// Check all JavaScript files for common issues
const validateOrbitFiles = () => {
const fs = require('fs');
const path = require('path');
const orbitDir = path.join(__dirname);
const jsFiles = fs.readdirSync(orbitDir).filter(file =>
file.endsWith('.js') && file !== 'test_utils.js'
);
console.log(`Found ${jsFiles.length} Orbit Chain demo files to validate`);
const results = {
valid: [],
issues: []
};
for (const file of jsFiles) {
try {
// Simple validation - just check that the file can be required
const fullPath = path.join(orbitDir, file);
console.log(`Validating: ${file}`);
// Basic syntax check
const content = fs.readFileSync(fullPath, 'utf8');
new Function(content);
// Check for required imports
if (!content.includes('createRollupChain')) {
results.issues.push({
file,
issue: 'Missing createRollupChain import'
});
continue;
}
if (!content.includes('ethers')) {
results.issues.push({
file,
issue: 'Missing ethers import'
});
continue;
}
results.valid.push(file);
} catch (error) {
results.issues.push({
file,
issue: `Syntax error: ${error.message}`
});
}
}
return results;
};
// Run a quick check on a specific file
const quickCheck = (filename) => {
const fs = require('fs');
const path = require('path');
try {
const fullPath = path.join(__dirname, filename);
console.log(`Quick checking: ${filename}`);
const content = fs.readFileSync(fullPath, 'utf8');
// Extract and validate Chain ID
const chainIdMatch = content.match(/chainId:\s*(\d+)/);
if (chainIdMatch) {
console.log(`[OK] Chain ID found: ${chainIdMatch[1]}`);
} else {
console.log(`[WARNING] Chain ID not found or in unexpected format`);
}
// Check for contract deployment
if (content.includes('deploy()')) {
console.log(`[OK] Contract deployment found`);
} else {
console.log(`[WARNING] Contract deployment might be missing or in unexpected format`);
}
// Check for dotenv configuration
if (content.includes('dotenv.config()')) {
console.log(`[OK] Environment loading found`);
} else {
console.log(`[WARNING] dotenv configuration might be missing`);
}
return { success: true };
} catch (error) {
console.error(`Error checking ${filename}:`, error.message);
return {
success: false,
error: error.message
};
}
};
module.exports = {
mockCreateRollupChain,
MockProvider,
validateOrbitFiles,
quickCheck
};