Skip to content

Commit

Permalink
basic integrity check command
Browse files Browse the repository at this point in the history
  • Loading branch information
szerintedmi committed Apr 4, 2019
1 parent dd007fa commit 729568e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Options:
Commands:
generate|gen [options] Generate deployment and abi files from Truffle generated JSON files
removeSourceEntries|removeSrc [options] remove source entries from all deployment files
check [options] Basic integrity check of files generated. Checks references between Abi files and deployment files
More info: https://github.com/Augmint/abiniser
Expand Down Expand Up @@ -125,6 +126,20 @@ Each file contains the contract's Abi in [Solidity ABI JSON format](https://soli

## Maintenance features

### Checks on generated files

```
$ abiniser check -h
Usage: check [options]
Basic integrity check of files generated. Checks references between Abi files and deployment files
Options:
-a, --abi-output-dir [value] Sets abi output directory to work on. (default: "./abiniser/abis")
-d, --deployments-output-dir [value] Sets deployments output directory to work on. (default: "./abiniser/deployments")
-h, --help output usage information
```

### Remove all source entries from deploy files already generated by abiniser

```
Expand Down
12 changes: 12 additions & 0 deletions abiniser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const pjson = require('./package.json');
const program = require('commander');
const generate = require('./lib/generate.js');
const removeSourceEntries = require('./lib/removeSourceEntries.js');
const checkIntegrity = require('./lib/checkIntegrity.js');

function help() {
console.log(
Expand Down Expand Up @@ -46,6 +47,17 @@ program
)
.action(options => removeSourceEntries(options));

program
.command('check')
.description('Basic integrity check of files generated. Checks references between Abi files and deployment files')
.option('-a, --abi-output-dir [value]', 'Sets abi output directory to work on.', './abiniser/abis')
.option(
'-d, --deployments-output-dir [value]',
'Sets deployments output directory to work on.',
'./abiniser/deployments'
)
.action(options => checkIntegrity(options));

program.on('--help', () => help());

program.on('command:*', () => {
Expand Down
68 changes: 68 additions & 0 deletions lib/checkIntegrity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const filesLib = require('./files');

async function checkIntegrity(options) {
try {
let config;
if (filesLib.fileExists(options.configFile)) {
config = filesLib.readJsonFile(options.configFile);
}

const abiOutputDir = options.abiOutputDir || config.abiOutputDir;
const deploymentsOutputDir = options.deploymentsOutputDir || config.deploymentsOutputDir;

if (!filesLib.directoryExists(abiOutputDir)) {
console.error(`Can't find abi output directory ${abiOutputDir}`);
process.exit(1);
}

if (!filesLib.directoryExists(deploymentsOutputDir)) {
console.error(`Can't find deployments output directory ${deploymentsOutputDir}`);
process.exit(1);
}

const abiFiles = await filesLib.fileWalker(abiOutputDir);

const abis = [];
abiFiles.forEach(abiFile => {
const abiFileContent = filesLib.readJsonFile(abiFile);
abis.push({
abiHash: abiFileContent.abiHash,
contractName: abiFileContent.contractName,
file: abiFile,
referenceCount: 0
});
});

const deploymentFiles = await filesLib.fileWalker(deploymentsOutputDir);

const deploymentsWithoutAbiFile = [];
deploymentFiles.forEach(file => {
const content = filesLib.readJsonFile(file);

for (const abiHash in content.deployedAbis) {
const abi = abis.find(abi => abi.abiHash === abiHash);
if (abi) {
abi.referenceCount++;
} else {
deploymentsWithoutAbiFile.push({ abiHash, fileName: file });
}
}
});

console.log(
'***** ABI files with references from deployment files:\n',
abis.filter(abi => abi.referenceCount !== 0)
);
console.log(
'***** ABI files WITHOUT reference from deployment files:\n',
abis.filter(abi => abi.referenceCount === 0)
);
console.log('***** Deployments without ABI file:\n', deploymentsWithoutAbiFile);
} catch (error) {
console.error('Error:\n', error);
}
}

module.exports = checkIntegrity;

0 comments on commit 729568e

Please sign in to comment.