-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_utils.js
More file actions
80 lines (66 loc) · 2.41 KB
/
test_utils.js
File metadata and controls
80 lines (66 loc) · 2.41 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
// Test utilities for Arbitrum Pulse Stylus demo contracts
const fs = require('fs');
const path = require('path');
// Simple syntax validation of Rust Stylus contracts
const validateStylusFiles = () => {
const stylusDir = path.join(__dirname);
const rustFiles = fs.readdirSync(stylusDir).filter(file =>
file.endsWith('.rs') && !file.startsWith('test_')
);
console.log(`Found ${rustFiles.length} Stylus demo contracts to validate`);
const results = {
valid: [],
issues: []
};
for (const file of rustFiles) {
try {
const fullPath = path.join(stylusDir, file);
// Read file content
const content = fs.readFileSync(fullPath, 'utf8');
console.log(`Validating: ${file}`);
results.valid.push(file);
} catch (error) {
results.issues.push({
file,
issue: `Error reading file: ${error.message}`
});
}
}
return results;
};
// Check a specific Rust file in more detail
const checkRustContract = (filename) => {
try {
const fullPath = path.join(__dirname, filename);
console.log(`Checking Rust contract: ${filename}`);
const content = fs.readFileSync(fullPath, 'utf8');
// Basic Rust syntax checks
const checks = [
{ name: "Public functions", regex: /pub\s+fn/, severity: "OK" },
{ name: "Struct definitions", regex: /struct\s+\w+/, severity: "OK" },
{ name: "Stylus imports", regex: /use\s+stylus_sdk/, severity: "OK" },
{ name: "External implementation", regex: /#\[external\]/, severity: "INFO" },
{ name: "Payable functions", regex: /#\[payable/, severity: "INFO" },
{ name: "No std attribute", regex: /#!\[no_std\]/, severity: "INFO" },
{ name: "Implementation blocks", regex: /impl\s+\w+/, severity: "OK" }
];
for (const check of checks) {
const found = check.regex.test(content);
console.log(`[${found ? check.severity : 'WARNING'}] ${check.name}: ${found ? 'Found' : 'Not found'}`);
}
// Check file size (large files may indicate comprehensive implementations)
const sizeInKB = content.length / 1024;
console.log(`[INFO] File size: ${sizeInKB.toFixed(2)} KB`);
return { success: true };
} catch (error) {
console.error(`Error checking ${filename}:`, error.message);
return {
success: false,
error: error.message
};
}
};
module.exports = {
validateStylusFiles,
checkRustContract
};