diff options
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | JSONSchema/schema.json | 48 | ||||
-rwxr-xr-x | JSONSchema/validate.js | 69 |
3 files changed, 81 insertions, 38 deletions
diff --git a/.travis.yml b/.travis.yml index 9aad47f7a..0d54f3211 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ script: # will fail, if linting fails - find . -name "*.json" -not -name "*Filler.json" -print0 | xargs -I file -n1 -0 python -mjson.tool file /dev/null # run schema tests against GeneralStateTests -- echo -e "$(find GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | node JSONSchema/validate.js +- echo -e "$(find GeneralStateTests -name '*.json' ! -path 'JSONSchema/schema.json')" | node JSONSchema/validate.js diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 74e796a88..c01e73b47 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -8,21 +8,22 @@ "type":"object", "properties":{ "EIP150":{ - "type":"array" + "$ref":"#/definitions/TransactionResults" }, "EIP158":{ - "type":"array" + "$ref":"#/definitions/TransactionResults" }, "Frontier":{ - "type":"array" + "$ref":"#/definitions/TransactionResults" }, "Homestead":{ - "type":"array" + "$ref":"#/definitions/TransactionResults" }, "Metropolis":{ - "type":"array" + "$ref":"#/definitions/TransactionResults" } - } + }, + "additionalProperties": false }, "explanation":{ "type":"string" @@ -128,5 +129,40 @@ } } } + }, + "definitions": { + "TransactionResults": { + "type": "array", + "items": { + "type": "object", + "properties": { + "hash": { + "type": "string", + "pattern":"^0x[0-9a-f]*$" + }, + "indexes": { + "type": "object", + "properties": { + "data": { + "type": "integer" + }, + "gas": { + "type": "integer" + }, + "value": { + "type": "integer" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "HexString": { + "type": "string", + "pattern":"^0x[0-9a-f]*$" + } + } } diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index c98e4bbf8..4c63500d0 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -1,15 +1,17 @@ #! /bin/env node -var validate = require('jsonschema').validate; var fs = require('fs'); - +var validate = require('jsonschema').validate; var readline = require('readline'); var schema = ''; var testCode = ''; var success = true; +var numFiles = 0; +var numFailed = 0; +var numSucceeded = 0; +var fileNames = []; -var readline = require('readline'); var rl = readline.createInterface({ input: process.stdin, output: process.stdout, @@ -17,37 +19,42 @@ var rl = readline.createInterface({ }); rl.on('line', function(line) { - fs.readFile('JSONSchema/schema.json', function(err, data) { - if (err) { - throw err; - } - - schema = JSON.parse(data); - - fs.readFile(line, function(err, data) { - if (err) { - throw err; - } + fileNames.push(line); +}); - try { - testCode = JSON.parse(data); - } catch (e) { - console.log(e); - } +rl.on('close', function() { + schema = JSON.parse(fs.readFileSync('JSONSchema/schema.json')); + + for (var i = 0; i < fileNames.length; i++) { + try { + testCode = JSON.parse(fs.readFileSync(fileNames[i])); + } catch(e) { + console.log(e); + numFailed++; + } - try { - var x = validate(testCode, schema); + try { + var x = validate(testCode, schema); - if (x.errors.length > 0) { - success = false; - console.log(line + ':\n'); - for (var i = 0; i < x.errors.length; i++) { - console.log(' ' + x.errors[i] + '\n') - } + if (x.errors.length > 0) { + numFailed++; + console.log(fileNames[i]+ ':\n'); + for (var j = 0; j < x.errors.length; j++) { + console.log(' ' + x.errors[j] + '\n') } - } catch (e) { - console.log(e); + } else { + numSucceeded++; } - }); - }); + } catch (e) { + console.log(e); + numFailed++; + } + } + + console.log("Valid: "+numSucceeded+"\n"); + console.log("Failed: "+numFailed+"\n"); + + if(numFailed > 0) { + process.exit(-1); + } }); |