-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_contract.js
More file actions
55 lines (46 loc) · 1.84 KB
/
check_contract.js
File metadata and controls
55 lines (46 loc) · 1.84 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
// Simple script to check a single Rust contract
const fs = require('fs');
const path = require('path');
// Get the contract name from command line
const contractName = process.argv[2];
if (!contractName) {
console.error('Please provide a contract name, e.g.: node check_contract.js microfinance_dao.rs');
process.exit(1);
}
// Full path to the contract
const contractPath = path.join(__dirname, contractName);
// Read the contract
try {
const content = fs.readFileSync(contractPath, 'utf8');
console.log(`Successfully read contract: ${contractName}`);
console.log(`File size: ${(content.length / 1024).toFixed(2)} KB`);
// Basic Rust checks
console.log('\nBasic contract checks:');
const checks = [
{ name: "Public functions", regex: /pub\s+fn/, severity: "Critical" },
{ name: "Struct definitions", regex: /struct\s+\w+/, severity: "Critical" },
{ name: "Stylus imports", regex: /use\s+stylus_sdk/, severity: "Critical" },
{ name: "External attribute", regex: /#\[external\]/, severity: "Important" },
{ name: "Payable attribute", regex: /#\[payable/, severity: "Optional" },
{ name: "No std attribute", regex: /#!\[no_std\]/, severity: "Important" },
{ name: "Implementation blocks", regex: /impl\s+\w+/, severity: "Critical" }
];
let passedCritical = true;
for (const check of checks) {
const found = check.regex.test(content);
console.log(`[${found ? 'PASS' : 'FAIL'}] ${check.name} (${check.severity})`);
if (!found && check.severity === 'Critical') {
passedCritical = false;
}
}
// Summary
console.log('\nSummary:');
if (passedCritical) {
console.log('✅ Contract passes all critical checks');
} else {
console.log('❌ Contract is missing critical elements');
}
} catch (error) {
console.error(`Error reading contract: ${error.message}`);
process.exit(1);
}