diff options
author | Jared Wasinger <j-wasinger@hotmail.com> | 2017-07-04 16:45:52 +0800 |
---|---|---|
committer | Ubuntu <ubuntu@ip-172-31-32-43.us-west-2.compute.internal> | 2017-08-08 04:41:46 +0800 |
commit | 6e8afe6563febbf3f54ab0702aba7056eca762f0 (patch) | |
tree | 568f1db52846bf1cf5f64f6d480bdd377838c719 /JSONSchema | |
parent | 04350351733b1441a2b11502e674b16dd6c47659 (diff) | |
download | dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar.gz dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar.bz2 dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar.lz dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar.xz dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.tar.zst dexon-tests-6e8afe6563febbf3f54ab0702aba7056eca762f0.zip |
add "explanation" field. Reduce number of schema errors
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); + } + }); + }); +}); |