diff options
Diffstat (limited to 'JSONSchema')
-rwxr-xr-x | JSONSchema/run.sh | 1 | ||||
-rw-r--r-- | JSONSchema/schema.json | 139 | ||||
-rwxr-xr-x | JSONSchema/validate.js | 50 |
3 files changed, 190 insertions, 0 deletions
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); + } + }); + }); +}); |