Skip to content

Commit

Permalink
Recompile, refactor validations, replace library, use validate script…
Browse files Browse the repository at this point in the history
… in travis
  • Loading branch information
gamalielhere committed Aug 24, 2018
1 parent 62f78d9 commit 8c0ea02
Show file tree
Hide file tree
Showing 68 changed files with 6,998 additions and 439 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
language: node_js
node_js: '8'
stages:
- name: check contract format
- name: check token format
- name: check formatting issues

jobs:
fast_finish: true
include:
- stage: check contract format
- stage: check formatting issues
script:
- |
node checkContract.js;
- stage: check token format
script:
- |
node checkToken.js;
npm run validate
38 changes: 25 additions & 13 deletions checkContract.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
const fs = require('fs');
const web3 = require('web3');
const path = require('path');
const contractsDirectory = './src/contracts/';
const Schema = require('validate');
const contract = new Schema({
const contractsDirectory = './src/contracts';
const validate = require('validate.js');
const constraints = {
name: {
type: String,
required: true
presence: {
allowEmpty: false
}
},
address: {
type: String,
required: true
presence: {
allowEmpty: false
},
length: {
is: 42
}
},
comment: {
type: String,
required: true
presence: true
},
abi: {
type: Array,
required: true
presence: {
allowEmpty: false
}
}
});
};

function run() {
fs.readdirSync(contractsDirectory).forEach(folder => {
Expand All @@ -32,10 +37,17 @@ function run() {
const obj = JSON.parse(
fs.readFileSync(`${contractsDirectory}/${folder}/${file}`, 'utf8')
);
if (contract.validate(obj) === false) {
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);
}
});
Expand Down
167 changes: 93 additions & 74 deletions checkToken.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,111 @@
const fs = require('fs');
const tokensDirectory = './src/tokens/';
const tokensDirectory = './src/tokens';
const web3 = require('web3');
const path = require('path');
const Schema = require('validate');
const token = new Schema({
const validate = require('validate.js');

const constraints = {
symbol: {
type: String,
required: true
presence: {
allowEmpty: false
}
},
name: {
type: String,
required: true
presence: {
allowEmpty: false
}
},
type: {
type: String,
required: true
presence: {
allowEmpty: false
}
},
address: {
type: String,
required: true
presence: {
allowEmpty: false
},
length: {
is: 42
}
},
ens_address: {
type: String
presence: true
},
decimals: {
type: Number,
required: true
presence: {
allowEmpty: false
}
},
website: {
type: String
presence: true
},
logo: {
src: {
type: String
},
width: {
type: String
},
height: {
type: String
},
ipfs_hash: {
type: String
}
presence: true
},
'logo.src': {
presence: true
},
'logo.width': {
presence: true
},
'logo.height': {
presence: true
},
'logo.ipfs_hash': {
presence: true
},
support: {
email: {
type: String
},
url: {
type: String
}
presence: true
},
'support.email': {
presence: true
},
'support.url': {
presence: true
},
social: {
blog: {
type: String
},
chat: {
type: String
},
facebook: {
type: String
},
forum: {
type: String
},
github: {
type: String
},
gitter: {
type: String
},
instagram: {
type: String
},
linkedin: {
type: String
},
reddit: {
type: String
},
slack: {
type: String
},
telegram: {
type: String
},
twitter: {
type: String
},
youtube: {
type: String
}
presence: true
},
'social.blog': {
presence: true
},
'social.chat': {
presence: true
},
'social.facebook': {
presence: true
},
'social.forum': {
presence: true
},
'social.github': {
presence: true
},
'social.gitter': {
presence: true
},
'social.instagram': {
presence: true
},
'social.linkedin': {
presence: true
},
'social.reddit': {
presence: true
},
'social.slack': {
presence: true
},
'social.telegram': {
presence: true
},
'social.twitter': {
presence: true
},
'social.youtube': {
presence: true
}
});
};

function run() {
fs.readdirSync(tokensDirectory).forEach(folder => {
Expand All @@ -105,10 +117,17 @@ function run() {
const obj = JSON.parse(
fs.readFileSync(`${tokensDirectory}/${folder}/${file}`, 'utf8')
);
if (token.validate(obj) === false) {
if (validate(obj, constraints) !== undefined) {
const errs = validate(obj, constraints);
Object.keys(errs).forEach(key => {
console.log(
`${errs[key][0]} for ${file} in ${tokensDirectory}/${folder}`
);
});
process.exit(1);
}
} else {
console.log('Incorrect file name or file extension');
process.exit(1);
}
});
Expand Down
Loading

0 comments on commit 8c0ea02

Please sign in to comment.