diff options
author | Jared Wasinger <j-wasinger@hotmail.com> | 2017-07-06 14:37:04 +0800 |
---|---|---|
committer | Ubuntu <ubuntu@ip-172-31-32-43.us-west-2.compute.internal> | 2017-08-08 04:41:46 +0800 |
commit | 6bdff4b01b9bda7264b4208ee12d8b7206191f98 (patch) | |
tree | 2e538911d18705d9c8c3b22cf48bc54f4bc801b7 /JSONSchema | |
parent | 2b523eb61c79bdc5f066e49c97c6ddfb971a2f03 (diff) | |
download | tangerine-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.tar.gz tangerine-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.tar.zst tangerine-tests-6bdff4b01b9bda7264b4208ee12d8b7206191f98.zip |
make error output more informative. Make schema more comprehensive. Add exit code of -1 upon failure
Diffstat (limited to 'JSONSchema')
-rw-r--r-- | JSONSchema/schema.json | 48 | ||||
-rwxr-xr-x | JSONSchema/validate.js | 69 |
2 files changed, 80 insertions, 37 deletions
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); + } }); |