From 6e8afe6563febbf3f54ab0702aba7056eca762f0 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 4 Jul 2017 01:45:52 -0700 Subject: add "explanation" field. Reduce number of schema errors --- GeneralStateTests/schema/run.sh | 1 - GeneralStateTests/schema/schema.json | 136 ---------------------------------- GeneralStateTests/schema/validate.js | 48 ------------ JSONSchema/run.sh | 1 + JSONSchema/schema.json | 139 +++++++++++++++++++++++++++++++++++ JSONSchema/validate.js | 50 +++++++++++++ 6 files changed, 190 insertions(+), 185 deletions(-) delete mode 100755 GeneralStateTests/schema/run.sh delete mode 100644 GeneralStateTests/schema/schema.json delete mode 100755 GeneralStateTests/schema/validate.js create mode 100755 JSONSchema/run.sh create mode 100644 JSONSchema/schema.json create mode 100755 JSONSchema/validate.js diff --git a/GeneralStateTests/schema/run.sh b/GeneralStateTests/schema/run.sh deleted file mode 100755 index 45cfbf363..000000000 --- a/GeneralStateTests/schema/run.sh +++ /dev/null @@ -1 +0,0 @@ -echo -e "$(find .. -name '*.json' ! -path '../schema/*.json')" | node validate.js diff --git a/GeneralStateTests/schema/schema.json b/GeneralStateTests/schema/schema.json deleted file mode 100644 index 178b80b9b..000000000 --- a/GeneralStateTests/schema/schema.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "type": "object", - "patternProperties": { - "^.*$": { - "type": "object", - "properties": { - "post": { - "type": "object", - "properties": { - "EIP150": { - "type": "array" - }, - "EIP158": { - "type": "array" - }, - "Frontier": { - "type": "array" - }, - "Homestead": { - "type": "array" - }, - "Metropolis": { - "type": "array" - } - }, - "additionalProperties": false - }, - "env": { - "type": "object", - "properties": { - "currentCoinbase": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "currentDifficulty": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "currentGasLimit": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "currentNumber": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "currentTimestamp": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "previousHash": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - } - }, - "additionalProperties": false - }, - "pre": { - "type": "object", - "patternProperties": { - "^0x[0-9a-f]*": { - "type": "object", - "properties": { - "balance": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "code": { - "type": "string", - "pattern": "^(0x[0-9a-f]*)?$" - }, - "nonce": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - - }, - "storage": { - "type": "object" - } - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "transaction": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string", - "pattern": "^(0x[0-9a-f]*)?$" - } - }, - "gasLimit": { - "type": "array", - "items": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - } - }, - "gasPrice": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "nonce": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "secretKey": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "to": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - }, - "value": { - "type": "array", - "items": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - } - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "additionalProperties": false -} diff --git a/GeneralStateTests/schema/validate.js b/GeneralStateTests/schema/validate.js deleted file mode 100755 index af3e3b495..000000000 --- a/GeneralStateTests/schema/validate.js +++ /dev/null @@ -1,48 +0,0 @@ -#! /bin/env node - -var validate = require('jsonschema').validate; -var fs = require('fs'); - -var readline = require('readline'); -var schema = ''; -var testCode = ''; - -var readline = require('readline'); -var rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -rl.on('line', function(line){ - fs.readFile('schema.json', function(err, data) { - if (err) { - throw err; - } - - schema = JSON.parse(data); - - fs.readFile(line, function(err, data) { - if (err) { - throw err; - } - - try { - testCode = JSON.parse(data); - } catch(e) { - console.log(e); - } - - try { - var x = validate(testCode, schema); - - if (x.errors.length > 0) { - console.log(line+':\n'); - console.log(x.errors+'\n') - } - } catch(e) { - console.log(e); - } - }); - }); -}); diff --git a/JSONSchema/run.sh b/JSONSchema/run.sh new file mode 100755 index 000000000..0624037bb --- /dev/null +++ b/JSONSchema/run.sh @@ -0,0 +1 @@ +echo -e "$(find ../GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | node validate.js diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json new file mode 100644 index 000000000..1ca91c03d --- /dev/null +++ b/JSONSchema/schema.json @@ -0,0 +1,139 @@ +{ + "type": "object", + "patternProperties": { + "^.*$": { + "type": "object", + "properties": { + "post": { + "type": "object", + "properties": { + "EIP150": { + "type": "array" + }, + "EIP158": { + "type": "array" + }, + "Frontier": { + "type": "array" + }, + "Homestead": { + "type": "array" + }, + "Metropolis": { + "type": "array" + } + }, + "additionalProperties": false + }, + "explanation": { + "type": "string" + }, + "env": { + "type": "object", + "properties": { + "currentCoinbase": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "currentDifficulty": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "currentGasLimit": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "currentNumber": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "currentTimestamp": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "previousHash": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + } + }, + "additionalProperties": false + }, + "pre": { + "type": "object", + "patternProperties": { + "^0x[0-9a-f]*": { + "type": "object", + "properties": { + "balance": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "code": { + "type": "string", + "pattern": "^(0x[0-9a-f]*)?$" + }, + "nonce": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + + }, + "storage": { + "type": "object" + } + }, + "additionalProperties": false + }, + "additionalProperties": false + }, + "additionalProperties": false + }, + "transaction": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "pattern": "^(0x[0-9a-f]*)?$" + } + }, + "gasLimit": { + "type": "array", + "items": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + } + }, + "gasPrice": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "nonce": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "secretKey": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "to": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "value": { + "type": "array", + "items": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + "additionalProperties": false + }, + "additionalProperties": false +} diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js new file mode 100755 index 000000000..368d28da2 --- /dev/null +++ b/JSONSchema/validate.js @@ -0,0 +1,50 @@ +#! /bin/env node + +var validate = require('jsonschema').validate; +var fs = require('fs'); + +var readline = require('readline'); +var schema = ''; +var testCode = ''; + +var readline = require('readline'); +var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false +}); + +rl.on('line', function(line){ + fs.readFile('schema.json', function(err, data) { + if (err) { + throw err; + } + + schema = JSON.parse(data); + + fs.readFile(line, function(err, data) { + if (err) { + throw err; + } + + try { + testCode = JSON.parse(data); + } catch(e) { + console.log(e); + } + + try { + var x = validate(testCode, schema); + + if (x.errors.length > 0) { + console.log(line+':\n'); + for (var i = 0; i < x.errors.length; i++) { + console.log(' '+x.errors[i]+'\n') + } + } + } catch(e) { + console.log(e); + } + }); + }); +}); -- cgit v1.2.3