forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkContract.js
61 lines (58 loc) · 1.52 KB
/
checkContract.js
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
const fs = require('fs');
const web3 = require('web3');
const path = require('path');
const contractsDirectory = './src/contracts';
const validate = require('validate.js');
const validateObject = require('./validateObject');
const constraints = {
name: {
presence: {
allowEmpty: false
}
},
address: function(value) {
if (web3.utils.isAddress(value)) {
return null;
}
return {
presence: { message: 'Token Address missing' },
length: { is: 42 }
};
},
comment: {
presence: true
},
abi: {
presence: {
allowEmpty: false
}
}
};
function checkContract() {
fs.readdirSync(contractsDirectory).forEach(folder => {
fs.readdirSync(`${contractsDirectory}/${folder}`).forEach(file => {
if (
path.extname(file) === '.json' &&
web3.utils.isAddress(file.replace('.json', ''))
) {
const fullPath = `${contractsDirectory}/${folder}/${file}`;
const obj = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
validateObject(constraints, obj, fullPath);
if (validate(obj, constraints) !== undefined) {
const errs = validate(obj, constraints);
Object.keys(errs).forEach(key => {
console.log(
`${errs[key][0]} for ${file} in ${contractsDirectory}/${folder}`
);
});
process.exit(1);
}
} else {
console.log('Incorrect file name or file extension');
process.exit(1);
}
});
});
process.exit(0);
}
checkContract();