From e0c62ccd02a72032c412882e85a0db72fa496946 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 3 Jul 2017 03:07:07 -0700 Subject: add JSON schema skeleton for #204 --- GeneralStateTests/schema/schema.json | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 GeneralStateTests/schema/schema.json diff --git a/GeneralStateTests/schema/schema.json b/GeneralStateTests/schema/schema.json new file mode 100644 index 000000000..f56ee61ca --- /dev/null +++ b/GeneralStateTests/schema/schema.json @@ -0,0 +1,71 @@ +{ + "type": "object", + "additionalProperties": { + "env": { + "type": "object", + "additionalProperties": { + "currentCoinbase": { + "type": "string" + }, + "currentDifficulty": { + "type": "string" + }, + "currentGasLimit": { + "type": "string" + }, + "currentNumber": { + "type": "string" + }, + "currentTimestamp": { + "type": "string" + }, + "previousHash": { + "type": "string" + } + } + }, + "post": { + "type": "object", + "additionalProperties": { + "EIP150": { + "type": "array" + }, + "EIP158": { + "type": "array" + }, + "Frontier": { + "type": "array" + }, + "Homestead": { + "type": "array" + } + } + }, + "pre": { + + }, + "transaction": { + "data": { + "type": "array" + }, + "gasLimit": { + "type": "array" + }, + "gasPrice": { + "type": "string" + }, + "nonce": { + "type": "string" + }, + "secretKey": { + "type": "string" + }, + "to": { + "type": "string" + }, + "value": { + "type": "array" + } + } + } +} -- cgit v1.2.3 From 2209036fb9ddf776b67b29e337e77175caf407bd Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 4 Jul 2017 00:34:57 -0700 Subject: add working schema outline --- GeneralStateTests/schema/run.sh | 1 + GeneralStateTests/schema/schema.json | 189 +++++++++++++++++++++++------------ GeneralStateTests/schema/validate.js | 66 ++++++++++++ 3 files changed, 194 insertions(+), 62 deletions(-) create mode 100755 GeneralStateTests/schema/run.sh create mode 100755 GeneralStateTests/schema/validate.js diff --git a/GeneralStateTests/schema/run.sh b/GeneralStateTests/schema/run.sh new file mode 100755 index 000000000..a2a0f2db8 --- /dev/null +++ b/GeneralStateTests/schema/run.sh @@ -0,0 +1 @@ +echo -e "$(find .. -name '*.json')" | node validate.js diff --git a/GeneralStateTests/schema/schema.json b/GeneralStateTests/schema/schema.json index f56ee61ca..178b80b9b 100644 --- a/GeneralStateTests/schema/schema.json +++ b/GeneralStateTests/schema/schema.json @@ -1,71 +1,136 @@ { "type": "object", - "additionalProperties": { - "env": { + "patternProperties": { + "^.*$": { "type": "object", - "additionalProperties": { - "currentCoinbase": { - "type": "string" + "properties": { + "post": { + "type": "object", + "properties": { + "EIP150": { + "type": "array" + }, + "EIP158": { + "type": "array" + }, + "Frontier": { + "type": "array" + }, + "Homestead": { + "type": "array" + }, + "Metropolis": { + "type": "array" + } + }, + "additionalProperties": false }, - "currentDifficulty": { - "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 }, - "currentGasLimit": { - "type": "string" - }, - "currentNumber": { - "type": "string" - }, - "currentTimestamp": { - "type": "string" - }, - "previousHash": { - "type": "string" - } - } - }, - "post": { - "type": "object", - "additionalProperties": { - "EIP150": { - "type": "array" - }, - "EIP158": { - "type": "array" - }, - "Frontier": { - "type": "array" + "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 }, - "Homestead": { - "type": "array" + "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 } - } - }, - "pre": { - - }, - "transaction": { - "data": { - "type": "array" - }, - "gasLimit": { - "type": "array" - }, - "gasPrice": { - "type": "string" }, - "nonce": { - "type": "string" - }, - "secretKey": { - "type": "string" - }, - "to": { - "type": "string" - }, - "value": { - "type": "array" - } - } - } + "additionalProperties": false + }, + "additionalProperties": false + }, + "additionalProperties": false } diff --git a/GeneralStateTests/schema/validate.js b/GeneralStateTests/schema/validate.js new file mode 100755 index 000000000..6f2feef9b --- /dev/null +++ b/GeneralStateTests/schema/validate.js @@ -0,0 +1,66 @@ +#! /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('simple-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) { + debugger; + } + + try { + var x = validate(testCode, schema); + } catch(e) { + console.log(line); + } + + }); + }); +}); + +/* +fs.readFile('simple-schema.json', function(err, data) { + if (err) { + throw err; + } + + schema = JSON.parse(data); + fs.readFile('example.json', function(err, data) { + if (err) { + throw err; + } + + testCode = JSON.parse(data); + var x = validate(testCode, schema); + console.log(x); + debugger; + }); +}); +*/ -- cgit v1.2.3 From 04350351733b1441a2b11502e674b16dd6c47659 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 4 Jul 2017 01:15:33 -0700 Subject: modify validation script to run against all test cases under GeneralStateTests --- GeneralStateTests/schema/run.sh | 2 +- GeneralStateTests/schema/validate.js | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/GeneralStateTests/schema/run.sh b/GeneralStateTests/schema/run.sh index a2a0f2db8..45cfbf363 100755 --- a/GeneralStateTests/schema/run.sh +++ b/GeneralStateTests/schema/run.sh @@ -1 +1 @@ -echo -e "$(find .. -name '*.json')" | node validate.js +echo -e "$(find .. -name '*.json' ! -path '../schema/*.json')" | node validate.js diff --git a/GeneralStateTests/schema/validate.js b/GeneralStateTests/schema/validate.js index 6f2feef9b..af3e3b495 100755 --- a/GeneralStateTests/schema/validate.js +++ b/GeneralStateTests/schema/validate.js @@ -15,15 +15,13 @@ var rl = readline.createInterface({ }); rl.on('line', function(line){ - fs.readFile('simple-schema.json', function(err, data) { + 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; @@ -32,35 +30,19 @@ rl.on('line', function(line){ try { testCode = JSON.parse(data); } catch(e) { - debugger; + 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(line); + console.log(e); } - }); }); }); - -/* -fs.readFile('simple-schema.json', function(err, data) { - if (err) { - throw err; - } - - schema = JSON.parse(data); - fs.readFile('example.json', function(err, data) { - if (err) { - throw err; - } - - testCode = JSON.parse(data); - var x = validate(testCode, schema); - console.log(x); - debugger; - }); -}); -*/ -- cgit v1.2.3 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 From 7378b9fa4e883484af856df99a65c28293613e98 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 4 Jul 2017 15:57:06 -0700 Subject: add schema validation with Travis integration. --- .travis.yml | 3 +++ JSONSchema/run.sh | 1 - JSONSchema/schema.json | 28 +++++++++------------------- JSONSchema/validate.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 20 deletions(-) delete mode 100755 JSONSchema/run.sh create mode 100755 JSONSchema/validate.py diff --git a/.travis.yml b/.travis.yml index dbced1cd9..24267e38a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ language: python python: 2.7 sudo: false +install: "pip install jsonschema" script: # won't fail, but print problems - find . -name "*.json" -not -name "*Filler.json" -exec echo {} \; -exec python -mjson.tool {} /dev/null \; 2>&1 | grep -v -B 1 "^\./" | cat # 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 "$(find GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | python JSONSchema/validate.py diff --git a/JSONSchema/run.sh b/JSONSchema/run.sh deleted file mode 100755 index 0624037bb..000000000 --- a/JSONSchema/run.sh +++ /dev/null @@ -1 +0,0 @@ -echo -e "$(find ../GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | node validate.js diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 1ca91c03d..5ac5e7a71 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -22,9 +22,7 @@ "Metropolis": { "type": "array" } - }, - "additionalProperties": false - }, + } }, "explanation": { "type": "string" }, @@ -55,8 +53,7 @@ "type": "string", "pattern": "^0x[0-9a-f]*$" } - }, - "additionalProperties": false + } }, "pre": { "type": "object", @@ -80,12 +77,9 @@ "storage": { "type": "object" } - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "additionalProperties": false + } + } + } }, "transaction": { "type": "object", @@ -127,13 +121,9 @@ "pattern": "^0x[0-9a-f]*$" } } - }, - "additionalProperties": false + } } - }, - "additionalProperties": false - }, - "additionalProperties": false - }, - "additionalProperties": false + } + } + } } diff --git a/JSONSchema/validate.py b/JSONSchema/validate.py new file mode 100755 index 000000000..086abfa93 --- /dev/null +++ b/JSONSchema/validate.py @@ -0,0 +1,30 @@ +#! /bin/env python + +import glob, json, sys, jsonschema + +with open('JSONSchema/schema.json') as schema_data: + schema = json.load(schema_data) + +#for filename in glob.glob('GeneralStateTests/*.json'): +# print(filename) + +while True: + line = sys.stdin.readline() + if not line: + if success: + sys.exit(0) + else: + sys.exit(-1) + + line = line.strip('\n') + with open(line) as test_data: + test = json.load(test_data) + + try: + jsonschema.validate(test, schema) + except jsonschema.exceptions.ValidationError as e: + success = False + print(line+':\n\n') + print(e) + print('\n') + -- cgit v1.2.3 From 6117849a700de4d1fcb7245b2cfffbd3382c6cf8 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 5 Jul 2017 13:00:01 -0700 Subject: use JS for json schema validation because the Node 'jsonschema' library is the only one (that I have found) to correctly handle 'additionalProperties' as a boolean (https://spacetelescope.github.io/understanding-json-schema/reference/object.html) --- .travis.yml | 9 ++++++--- JSONSchema/schema.json | 12 ++++++++---- JSONSchema/validate.js | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24267e38a..9aad47f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,14 @@ language: python -python: 2.7 +python: + - "2.7" +node_js: + - "7" sudo: false -install: "pip install jsonschema" +install: "npm install jsonschema" script: # won't fail, but print problems - find . -name "*.json" -not -name "*Filler.json" -exec echo {} \; -exec python -mjson.tool {} /dev/null \; 2>&1 | grep -v -B 1 "^\./" | cat # 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 "$(find GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | python JSONSchema/validate.py +- echo -e "$(find GeneralStateTests -name '*.json' ! -path '../schema/*.json')" | node JSONSchema/validate.js diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 5ac5e7a71..6e7113950 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -22,7 +22,8 @@ "Metropolis": { "type": "array" } - } }, + } + }, "explanation": { "type": "string" }, @@ -53,7 +54,8 @@ "type": "string", "pattern": "^0x[0-9a-f]*$" } - } + }, + "additionalproperties": false }, "pre": { "type": "object", @@ -79,7 +81,8 @@ } } } - } + }, + "additionalProperties": false }, "transaction": { "type": "object", @@ -121,7 +124,8 @@ "pattern": "^0x[0-9a-f]*$" } } - } + }, + "additionalProperties": false } } } diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index 368d28da2..6c44b834f 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -15,7 +15,7 @@ var rl = readline.createInterface({ }); rl.on('line', function(line){ - fs.readFile('schema.json', function(err, data) { + fs.readFile('JSONSchema/schema.json', function(err, data) { if (err) { throw err; } -- cgit v1.2.3 From 291c054b2731de7172579ca629d1499be44f15fa Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 5 Jul 2017 13:33:09 -0700 Subject: format code. Remove unused python code --- JSONSchema/schema.json | 187 ++++++++++++++++++++++++------------------------- JSONSchema/validate.js | 20 +++--- JSONSchema/validate.py | 30 -------- 3 files changed, 105 insertions(+), 132 deletions(-) delete mode 100755 JSONSchema/validate.py diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 6e7113950..74e796a88 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -1,131 +1,130 @@ { - "type": "object", - "patternProperties": { - "^.*$": { - "type": "object", - "properties": { - "post": { - "type": "object", - "properties": { - "EIP150": { - "type": "array" + "type":"object", + "patternProperties":{ + "^.*$":{ + "type":"object", + "properties":{ + "post":{ + "type":"object", + "properties":{ + "EIP150":{ + "type":"array" }, - "EIP158": { - "type": "array" + "EIP158":{ + "type":"array" }, - "Frontier": { - "type": "array" + "Frontier":{ + "type":"array" }, - "Homestead": { - "type": "array" + "Homestead":{ + "type":"array" }, - "Metropolis": { - "type": "array" + "Metropolis":{ + "type":"array" } - } - }, - "explanation": { - "type": "string" + } }, - "env": { - "type": "object", - "properties": { - "currentCoinbase": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "explanation":{ + "type":"string" + }, + "env":{ + "type":"object", + "properties":{ + "currentCoinbase":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "currentDifficulty": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "currentDifficulty":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "currentGasLimit": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "currentGasLimit":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "currentNumber": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "currentNumber":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "currentTimestamp": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "currentTimestamp":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "previousHash": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "previousHash":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" } }, - "additionalproperties": false + "additionalproperties":false }, - "pre": { - "type": "object", - "patternProperties": { - "^0x[0-9a-f]*": { - "type": "object", - "properties": { - "balance": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "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]*)?$" + "code":{ + "type":"string", + "pattern":"^(0x[0-9a-f]*)?$" }, - "nonce": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" - + "nonce":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "storage": { - "type": "object" + "storage":{ + "type":"object" } } } }, - "additionalProperties": false + "additionalProperties":false }, - "transaction": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string", - "pattern": "^(0x[0-9a-f]*)?$" + "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]*$" + "gasLimit":{ + "type":"array", + "items":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" } }, - "gasPrice": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "gasPrice":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "nonce": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "nonce":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "secretKey": { - "type": "string", - "pattern": "^0x[0-9a-f]*$" + "secretKey":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" }, - "to": { - "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]*$" + "value":{ + "type":"array", + "items":{ + "type":"string", + "pattern":"^0x[0-9a-f]*$" } } }, - "additionalProperties": false + "additionalProperties":false } } } diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index 6c44b834f..e3037ccad 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -4,17 +4,20 @@ var validate = require('jsonschema').validate; var fs = require('fs'); var readline = require('readline'); +var process = require('process'); + var schema = ''; var testCode = ''; +var success = true; var readline = require('readline'); var rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false + input: process.stdin, + output: process.stdout, + terminal: false }); -rl.on('line', function(line){ +rl.on('line', function(line) { fs.readFile('JSONSchema/schema.json', function(err, data) { if (err) { throw err; @@ -29,7 +32,7 @@ rl.on('line', function(line){ try { testCode = JSON.parse(data); - } catch(e) { + } catch (e) { console.log(e); } @@ -37,12 +40,13 @@ rl.on('line', function(line){ var x = validate(testCode, schema); if (x.errors.length > 0) { - console.log(line+':\n'); + success = false; + console.log(line + ':\n'); for (var i = 0; i < x.errors.length; i++) { - console.log(' '+x.errors[i]+'\n') + console.log(' ' + x.errors[i] + '\n') } } - } catch(e) { + } catch (e) { console.log(e); } }); diff --git a/JSONSchema/validate.py b/JSONSchema/validate.py deleted file mode 100755 index 086abfa93..000000000 --- a/JSONSchema/validate.py +++ /dev/null @@ -1,30 +0,0 @@ -#! /bin/env python - -import glob, json, sys, jsonschema - -with open('JSONSchema/schema.json') as schema_data: - schema = json.load(schema_data) - -#for filename in glob.glob('GeneralStateTests/*.json'): -# print(filename) - -while True: - line = sys.stdin.readline() - if not line: - if success: - sys.exit(0) - else: - sys.exit(-1) - - line = line.strip('\n') - with open(line) as test_data: - test = json.load(test_data) - - try: - jsonschema.validate(test, schema) - except jsonschema.exceptions.ValidationError as e: - success = False - print(line+':\n\n') - print(e) - print('\n') - -- cgit v1.2.3 From 2b523eb61c79bdc5f066e49c97c6ddfb971a2f03 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 5 Jul 2017 13:38:53 -0700 Subject: fix process error --- JSONSchema/validate.js | 1 - 1 file changed, 1 deletion(-) diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index e3037ccad..c98e4bbf8 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -4,7 +4,6 @@ var validate = require('jsonschema').validate; var fs = require('fs'); var readline = require('readline'); -var process = require('process'); var schema = ''; var testCode = ''; -- cgit v1.2.3 From 6bdff4b01b9bda7264b4208ee12d8b7206191f98 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 5 Jul 2017 23:37:04 -0700 Subject: make error output more informative. Make schema more comprehensive. Add exit code of -1 upon failure --- .travis.yml | 2 +- JSONSchema/schema.json | 48 ++++++++++++++++++++++++++++++----- 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); + } }); -- cgit v1.2.3 From 53332daeef413c1a3684cd834cb5757234c8326d Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 6 Jul 2017 23:38:14 -0700 Subject: add ECDSA parameters r, s, v. Make sure certain fields are marked as required. Add regex for GasAmount. --- JSONSchema/schema.json | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index c01e73b47..2b45077cf 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -40,8 +40,7 @@ "pattern":"^0x[0-9a-f]*$" }, "currentGasLimit":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "$ref": "#/definitions/GasAmount" }, "currentNumber":{ "type":"string", @@ -56,6 +55,7 @@ "pattern":"^0x[0-9a-f]*$" } }, + "required": ["currentCoinbase", "currentDifficulty", "currentGasLimit", "currentNumber", "currentTimestamp", "previousHash"], "additionalproperties":false }, "pre":{ @@ -79,7 +79,9 @@ "storage":{ "type":"object" } - } + }, + "required": ["balance", "code", "nonce"], + "additionalproperties": false } }, "additionalProperties":false @@ -114,8 +116,8 @@ "pattern":"^0x[0-9a-f]*$" }, "to":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "type": "string", + "pattern":"^(0x([0-9a-f]*){10})?$" }, "value":{ "type":"array", @@ -123,8 +125,18 @@ "type":"string", "pattern":"^0x[0-9a-f]*$" } + }, + "r": { + "type": "string" + }, + "s": { + "type": "string" + }, + "v": { + "type": "string" } }, + "required": ["data", "gasLimit", "gasPrice", "nonce", "secretKey", "to", "value"], "additionalProperties":false } } @@ -153,16 +165,21 @@ "type": "integer" } }, + "required": ["data", "gas", "value"], "additionalProperties": false } }, + "required": ["hash", "indexes"], "additionalProperties": false } }, - "HexString": { + "Address": { "type": "string", - "pattern":"^0x[0-9a-f]*$" + "pattern":"^(0x[0-9a-f]*)?$" + }, + "GasAmount": { + "type":"string", + "pattern": "(^0x[76543210][0-9a-f]{15}$)|(^0x[0-9a-f]{0,15}$)" } - } } -- cgit v1.2.3 From 858d4c6c693580ef60247ddb24c7de8c2c66dc63 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 6 Jul 2017 23:57:55 -0700 Subject: make log ordering consistent --- JSONSchema/validate.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index 4c63500d0..1c176e2a8 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -25,6 +25,17 @@ rl.on('line', function(line) { rl.on('close', function() { schema = JSON.parse(fs.readFileSync('JSONSchema/schema.json')); + //sort file names alphabetically so that log output ordering is consistent + fileNames.sort((a,b) => { + if(a Date: Fri, 7 Jul 2017 00:11:52 -0700 Subject: make travis use node8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0d54f3211..688906320 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: python python: - "2.7" node_js: - - "7" + - "8" sudo: false install: "npm install jsonschema" script: -- cgit v1.2.3 From 2f1708cc2810d36c37d48d5413677dd5bd8d8406 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Fri, 7 Jul 2017 00:32:58 -0700 Subject: remove es6 syntax from validation script. --- JSONSchema/validate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index 1c176e2a8..fa46ac39c 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -26,7 +26,7 @@ rl.on('close', function() { schema = JSON.parse(fs.readFileSync('JSONSchema/schema.json')); //sort file names alphabetically so that log output ordering is consistent - fileNames.sort((a,b) => { + fileNames.sort(function(a,b) { if(a Date: Thu, 13 Jul 2017 13:59:31 -0700 Subject: improve type checking. --- JSONSchema/schema.json | 338 +++++++++++++++++++++++++++---------------------- 1 file changed, 190 insertions(+), 148 deletions(-) diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 2b45077cf..78004e0c3 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -1,185 +1,227 @@ { - "type":"object", - "patternProperties":{ - "^.*$":{ - "type":"object", - "properties":{ - "post":{ - "type":"object", - "properties":{ - "EIP150":{ - "$ref":"#/definitions/TransactionResults" - }, - "EIP158":{ - "$ref":"#/definitions/TransactionResults" - }, - "Frontier":{ - "$ref":"#/definitions/TransactionResults" - }, - "Homestead":{ - "$ref":"#/definitions/TransactionResults" - }, - "Metropolis":{ - "$ref":"#/definitions/TransactionResults" + "definitions": { + "GasAmount": { + "pattern": "(^0x[76543210][0-9a-f]{15}$)|(^0x[0-9a-f]{0,15}$)", + "type": "string" + }, + "SecretKey": { + "pattern": "^0x[0-9a-f]{64}$", + "type": "string" + }, + "TransactionResults": { + "items": { + "additionalProperties": false, + "properties": { + "hash": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "indexes": { + "additionalProperties": false, + "properties": { + "data": { + "type": "integer" + }, + "gas": { + "type": "integer" + }, + "value": { + "type": "integer" + } + }, + "required": [ + "data", + "gas", + "value" + ], + "type": "object" + } + }, + "required": [ + "hash", + "indexes" + ], + "type": "object" + }, + "type": "array" + } + }, + "patternProperties": { + "^.*$": { + "properties": { + "env": { + "additionalproperties": false, + "properties": { + "currentCoinbase": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "currentDifficulty": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "currentGasLimit": { + "$ref": "#/definitions/GasAmount" + }, + "currentNumber": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "currentTimestamp": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "previousHash": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" } }, - "additionalProperties": false + "required": [ + "currentCoinbase", + "currentDifficulty", + "currentGasLimit", + "currentNumber", + "currentTimestamp", + "previousHash" + ], + "type": "object" }, - "explanation":{ - "type":"string" + "explanation": { + "type": "string" }, - "env":{ - "type":"object", - "properties":{ - "currentCoinbase":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" - }, - "currentDifficulty":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" - }, - "currentGasLimit":{ - "$ref": "#/definitions/GasAmount" + "post": { + "additionalProperties": false, + "properties": { + "EIP150": { + "$ref": "#/definitions/TransactionResults" }, - "currentNumber":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "EIP158": { + "$ref": "#/definitions/TransactionResults" }, - "currentTimestamp":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "Frontier": { + "$ref": "#/definitions/TransactionResults" }, - "previousHash":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "Homestead": { + "$ref": "#/definitions/TransactionResults" + }, + "Metropolis": { + "$ref": "#/definitions/TransactionResults" } }, - "required": ["currentCoinbase", "currentDifficulty", "currentGasLimit", "currentNumber", "currentTimestamp", "previousHash"], - "additionalproperties":false + "type": "object" }, - "pre":{ - "type":"object", - "patternProperties":{ - "^0x[0-9a-f]*":{ - "type":"object", - "properties":{ - "balance":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "pre": { + "additionalProperties": false, + "patternProperties": { + "^0x[0-9a-f]*": { + "additionalproperties": false, + "properties": { + "balance": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" }, - "code":{ - "type":"string", - "pattern":"^(0x[0-9a-f]*)?$" + "code": { + "pattern": "^(0x[0-9a-f]*)?$", + "type": "string" }, - "nonce":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "nonce": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" }, - "storage":{ - "type":"object" + "storage": { + "type": "object" } }, - "required": ["balance", "code", "nonce"], - "additionalproperties": false + "required": [ + "balance", + "code", + "nonce" + ], + "type": "object" } }, - "additionalProperties":false + "type": "object" }, - "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]*$" + "transaction": { + "additionalProperties": false, + "properties": { + "data": { + "items": { + "oneOf": [ + { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + { + "pattern": "^$", + "type": "string" + } + ] + }, + "type": "array" }, - "secretKey":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" + "gasLimit": { + "items": { + "$ref": "#/definitions/GasAmount" + }, + "type": "array" }, - "to":{ - "type": "string", - "pattern":"^(0x([0-9a-f]*){10})?$" + "gasPrice": { + "$ref": "#/definitions/GasAmount" }, - "value":{ - "type":"array", - "items":{ - "type":"string", - "pattern":"^0x[0-9a-f]*$" - } + "nonce": { + "pattern": "^0x[0-9a-f]{1,4}$", + "type": "string" }, "r": { + "pattern": "^0x[0-9a-f]{16}$", "type": "string" }, "s": { + "pattern": "^0x[0-9a-f]{16}$", "type": "string" }, + "secretKey": { + "$ref": "#/definitions/SecretKey" + }, + "to": { + "oneOf": [ + { + "pattern": "^0x[0-9a-f]{1,10}$", + "type": "string" + }, + { + "pattern": "", + "type": "string" + } + ] + }, "v": { + "pattern": "^0x[0-9a-f]{16}$", "type": "string" + }, + "value": { + "items": { + "pattern": "^0x[0-9a-f]*$", + "type": "string" + }, + "type": "array" } }, - "required": ["data", "gasLimit", "gasPrice", "nonce", "secretKey", "to", "value"], - "additionalProperties":false + "required": [ + "data", + "gasLimit", + "gasPrice", + "nonce", + "secretKey", + "to", + "value" + ], + "type": "object" } - } + }, + "type": "object" } }, - "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" - } - }, - "required": ["data", "gas", "value"], - "additionalProperties": false - } - }, - "required": ["hash", "indexes"], - "additionalProperties": false - } - }, - "Address": { - "type": "string", - "pattern":"^(0x[0-9a-f]*)?$" - }, - "GasAmount": { - "type":"string", - "pattern": "(^0x[76543210][0-9a-f]{15}$)|(^0x[0-9a-f]{0,15}$)" - } - } + "type": "object" } -- cgit v1.2.3 From 0570119b4075010dfb8b6611523e1d5c26829ccf Mon Sep 17 00:00:00 2001 From: cdetrio Date: Sat, 5 Aug 2017 17:10:03 -0400 Subject: validate.js takes schema file as argument --- .travis.yml | 2 +- JSONSchema/validate.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 688906320..a2b9a2757 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 'JSONSchema/schema.json')" | node JSONSchema/validate.js +- echo -e "$(find GeneralStateTests -name '*.json')" | node JSONSchema/validate.js JSONSchema/schema.json diff --git a/JSONSchema/validate.js b/JSONSchema/validate.js index fa46ac39c..1a1a605db 100755 --- a/JSONSchema/validate.js +++ b/JSONSchema/validate.js @@ -4,6 +4,7 @@ var fs = require('fs'); var validate = require('jsonschema').validate; var readline = require('readline'); +var schemaFile = process.argv[2]; var schema = ''; var testCode = ''; var success = true; @@ -23,7 +24,7 @@ rl.on('line', function(line) { }); rl.on('close', function() { - schema = JSON.parse(fs.readFileSync('JSONSchema/schema.json')); + schema = JSON.parse(fs.readFileSync(schemaFile)); //sort file names alphabetically so that log output ordering is consistent fileNames.sort(function(a,b) { @@ -40,6 +41,7 @@ rl.on('close', function() { try { testCode = JSON.parse(fs.readFileSync(fileNames[i])); } catch(e) { + console.log('error on file:', fileNames[i]) console.log(e); numFailed++; } -- cgit v1.2.3 From 110969e11c15c2d69e4a9666f6805497dfee70c3 Mon Sep 17 00:00:00 2001 From: cdetrio Date: Sat, 5 Aug 2017 17:14:02 -0400 Subject: use more type definitions in schema --- JSONSchema/schema.json | 330 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 214 insertions(+), 116 deletions(-) diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 78004e0c3..5dee66084 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -1,21 +1,217 @@ { "definitions": { - "GasAmount": { - "pattern": "(^0x[76543210][0-9a-f]{15}$)|(^0x[0-9a-f]{0,15}$)", + "EmptyString": { + "type": "string", + "pattern": "^$" + }, + "HexData": { + "pattern": "^0x([0-9a-fA-F][0-9a-fA-F])*$", + "type": "string" + }, + "HexQuantity": { + "pattern": "(^0x0$)|(^0x[1-9a-fA-F][0-9a-fA-F]*$)", + "type": "string" + }, + "ConfusedHexType": { + "anyOf": [ + { "$ref": "#/definitions/HexData" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "HexDataOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/HexData" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "HexNoPrefix" : { + "pattern": "^([0-9a-fA-F][0-9a-fA-F])+$", "type": "string" }, - "SecretKey": { - "pattern": "^0x[0-9a-f]{64}$", + "HexMaybePrefix": { + "oneOf": [ + { "$ref": "#/definitions/HexNoPrefix" }, + { "$ref": "#/definitions/HexData" } + ] + }, + "HexMaybePrefixOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/HexMaybePrefix" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "IntegerString": { + "pattern": "^[0-9]+$", "type": "string" }, + "IntegerOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "IntegerOrNumber": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "type": "number" } + ] + }, + "IntegerOrNumberOrConfusedHex": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrNumber" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "IntegerOrEmptyOrHexQuantity": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrEmpty" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "IntegerOrHexQuantity": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "IntegerOrConfusedHex": { + "anyOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "IntegerOrEmptyOrConfusedHex": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrEmpty" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "PreStateAccount": { + "type": "object", + "additionalproperties": true, + "properties": { + "balance": { "$ref": "#/definitions/ConfusedHexType" }, + "code": { "type": "string" }, + "nonce": { "$ref": "#/definitions/ConfusedHexType" }, + "storage": { "type": "object" } + }, + "required": [ + "balance", + "code", + "nonce" + ] + }, + "TxSigR": { + "oneOf": [ + { "enum" : [ "0x00" ] } + ] + }, + "TxSigS": { + "oneOf": [ + { "enum" : [ "0x00" ] } + ] + }, + "TxSigV": { + "description": "a value of 0 is an invalid chainId, but used in a test case", + "oneOf": [ + { "enum" : [ "0x00", "0x01" ] } + ] + }, + "HexLen40": { + "pattern": "^0x[0-9a-fA-F]{40}$", + "type": "string" + }, + "HexNoPrefixLen40": { + "pattern": "^[0-9a-fA-F]{40}$", + "type": "string" + }, + "AddressMaybePrefixOrEmpty" : { + "oneOf": [ + { "$ref": "#/definitions/HexLen40" }, + { "$ref": "#/definitions/HexNoPrefixLen40" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "Transaction": { + "type": "object", + "additionalProperties": true, + "not": { + "required": ["r, s, v"] + }, + "properties": { + "data": { + "items": { "$ref": "#/definitions/HexDataOrEmpty" }, + "type": "array" + }, + "gasLimit": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + }, + "gasPrice": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "secretKey": { "$ref": "#/definitions/HexMaybePrefix" }, + "to": { "$ref": "#/definitions/AddressMaybePrefixOrEmpty"}, + "value": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + } + }, + "required": [ + "data", + "gasLimit", + "gasPrice", + "nonce", + "secretKey", + "to", + "value" + ] + }, + "NullSenderTransaction": { + "type": "object", + "additionalProperties": true, + "not": { + "required": ["secretKey"] + }, + "properties": { + "data": { + "items": { "$ref": "#/definitions/HexMaybePrefixOrEmpty" }, + "type": "array" + }, + "gasLimit": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + }, + "gasPrice": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "r": { "$ref": "#/definitions/TxSigR" }, + "s": { "$ref": "#/definitions/TxSigS" }, + "to": { "$ref": "#/definitions/AddressMaybePrefixOrEmpty"}, + "v": { "$ref": "#/definitions/TxSigV" }, + "value": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + } + }, + "required": [ + "data", + "gasLimit", + "gasPrice", + "nonce", + "r", + "s", + "v", + "to", + "value" + ] + }, "TransactionResults": { "items": { "additionalProperties": false, "properties": { "hash": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/HexData" }, + "logs": {}, "indexes": { "additionalProperties": false, "properties": { @@ -53,27 +249,22 @@ "additionalproperties": false, "properties": { "currentCoinbase": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/HexData" }, "currentDifficulty": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/ConfusedHexType" }, "currentGasLimit": { - "$ref": "#/definitions/GasAmount" + "$ref": "#/definitions/ConfusedHexType" }, "currentNumber": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/ConfusedHexType" }, "currentTimestamp": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/ConfusedHexType" }, "previousHash": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" + "$ref": "#/definitions/HexData" } }, "required": [ @@ -114,110 +305,17 @@ "additionalProperties": false, "patternProperties": { "^0x[0-9a-f]*": { - "additionalproperties": false, - "properties": { - "balance": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" - }, - "code": { - "pattern": "^(0x[0-9a-f]*)?$", - "type": "string" - }, - "nonce": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" - }, - "storage": { - "type": "object" - } - }, - "required": [ - "balance", - "code", - "nonce" - ], - "type": "object" + "description": "prestate account address with 0x prefix", + "$ref": "#/definitions/PreStateAccount" } }, "type": "object" }, "transaction": { - "additionalProperties": false, - "properties": { - "data": { - "items": { - "oneOf": [ - { - "pattern": "^0x[0-9a-f]*$", - "type": "string" - }, - { - "pattern": "^$", - "type": "string" - } - ] - }, - "type": "array" - }, - "gasLimit": { - "items": { - "$ref": "#/definitions/GasAmount" - }, - "type": "array" - }, - "gasPrice": { - "$ref": "#/definitions/GasAmount" - }, - "nonce": { - "pattern": "^0x[0-9a-f]{1,4}$", - "type": "string" - }, - "r": { - "pattern": "^0x[0-9a-f]{16}$", - "type": "string" - }, - "s": { - "pattern": "^0x[0-9a-f]{16}$", - "type": "string" - }, - "secretKey": { - "$ref": "#/definitions/SecretKey" - }, - "to": { - "oneOf": [ - { - "pattern": "^0x[0-9a-f]{1,10}$", - "type": "string" - }, - { - "pattern": "", - "type": "string" - } - ] - }, - "v": { - "pattern": "^0x[0-9a-f]{16}$", - "type": "string" - }, - "value": { - "items": { - "pattern": "^0x[0-9a-f]*$", - "type": "string" - }, - "type": "array" - } - }, - "required": [ - "data", - "gasLimit", - "gasPrice", - "nonce", - "secretKey", - "to", - "value" - ], - "type": "object" + "oneOf": [ + { "$ref": "#/definitions/Transaction" }, + { "$ref": "#/definitions/NullSenderTransaction" } + ] } }, "type": "object" -- cgit v1.2.3 From d0b88b939f0eceff79b82b53eda1920a8ca35531 Mon Sep 17 00:00:00 2001 From: cdetrio Date: Sat, 5 Aug 2017 17:15:38 -0400 Subject: add schema for state test fillers --- .travis.yml | 1 + JSONSchema/filler-schema.json | 257 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 JSONSchema/filler-schema.json diff --git a/.travis.yml b/.travis.yml index a2b9a2757..d9d7c58fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,3 +12,4 @@ script: - 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')" | node JSONSchema/validate.js JSONSchema/schema.json +- echo -e "$(find src/GeneralStateTestsFiller -name '*.json')" | node JSONSchema/validate.js JSONSchema/filler-schema.json \ No newline at end of file diff --git a/JSONSchema/filler-schema.json b/JSONSchema/filler-schema.json new file mode 100644 index 000000000..07731f7b9 --- /dev/null +++ b/JSONSchema/filler-schema.json @@ -0,0 +1,257 @@ +{ + "definitions": { + "EmptyString": { + "type": "string", + "pattern": "^$" + }, + "HexData": { + "pattern": "^0x([0-9a-fA-F][0-9a-fA-F])*$", + "type": "string" + }, + "HexQuantity": { + "pattern": "(^0x0$)|(^0x[1-9a-fA-F][0-9a-fA-F]*$)", + "type": "string" + }, + "ConfusedHexType": { + "anyOf": [ + { "$ref": "#/definitions/HexData" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "HexDataOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/HexData" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "HexNoPrefix" : { + "pattern": "^([0-9a-fA-F][0-9a-fA-F])+$", + "type": "string" + }, + "HexMaybePrefix": { + "oneOf": [ + { "$ref": "#/definitions/HexNoPrefix" }, + { "$ref": "#/definitions/HexData" } + ] + }, + "HexMaybePrefixOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/HexMaybePrefix" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "IntegerString": { + "pattern": "^[0-9]+$", + "type": "string" + }, + "IntegerOrEmpty": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "IntegerOrNumber": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "type": "number" } + ] + }, + "IntegerOrNumberOrConfusedHex": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrNumber" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "IntegerOrEmptyOrHexQuantity": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrEmpty" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "IntegerOrHexQuantity": { + "oneOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/HexQuantity" } + ] + }, + "IntegerOrConfusedHex": { + "anyOf": [ + { "$ref": "#/definitions/IntegerString" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "IntegerOrEmptyOrConfusedHex": { + "oneOf": [ + { "$ref": "#/definitions/IntegerOrEmpty" }, + { "$ref": "#/definitions/ConfusedHexType" } + ] + }, + "PreStateAccount": { + "type": "object", + "additionalproperties": true, + "properties": { + "balance": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "code": { "type": "string" }, + "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "storage": { "type": "object" } + }, + "required": [ + "balance", + "code", + "nonce" + ] + }, + "TxSigR": { + "oneOf": [ + { "enum" : [ "0" ] } + ] + }, + "TxSigS": { + "oneOf": [ + { "enum" : [ "0" ] } + ] + }, + "TxSigV": { + "description": "a value of 0 is an invalid chainId, but used in a test case", + "oneOf": [ + { "enum" : [ "0", "1" ] } + ] + }, + "HexLen40": { + "pattern": "^0x[0-9a-fA-F]{40}$", + "type": "string" + }, + "HexNoPrefixLen40": { + "pattern": "^[0-9a-fA-F]{40}$", + "type": "string" + }, + "AddressMaybePrefixOrEmpty" : { + "oneOf": [ + { "$ref": "#/definitions/HexLen40" }, + { "$ref": "#/definitions/HexNoPrefixLen40" }, + { "$ref": "#/definitions/EmptyString" } + ] + }, + "Transaction": { + "type": "object", + "additionalProperties": true, + "not": { + "required": ["r, s, v"] + }, + "properties": { + "data": { + "items": { "$ref": "#/definitions/HexDataOrEmpty" }, + "type": "array" + }, + "gasLimit": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + }, + "gasPrice": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "secretKey": { "$ref": "#/definitions/HexMaybePrefix" }, + "to": { "$ref": "#/definitions/AddressMaybePrefixOrEmpty"}, + "value": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + } + }, + "required": [ + "data", + "gasLimit", + "gasPrice", + "nonce", + "secretKey", + "to", + "value" + ] + }, + "NullSenderTransaction": { + "type": "object", + "additionalProperties": true, + "not": { + "required": ["secretKey"] + }, + "properties": { + "data": { + "items": { "$ref": "#/definitions/HexMaybePrefixOrEmpty" }, + "type": "array" + }, + "gasLimit": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + }, + "gasPrice": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "r": { "$ref": "#/definitions/TxSigR" }, + "s": { "$ref": "#/definitions/TxSigS" }, + "to": { "$ref": "#/definitions/AddressMaybePrefixOrEmpty"}, + "v": { "$ref": "#/definitions/TxSigV" }, + "value": { + "items": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, + "type": "array" + } + }, + "required": [ + "data", + "gasLimit", + "gasPrice", + "nonce", + "r", + "s", + "v", + "to", + "value" + ] + } + }, + "patternProperties": { + "^.*$": { + "properties": { + "env": { + "additionalproperties": false, + "properties": { + "currentCoinbase": { "$ref": "#/definitions/HexMaybePrefix" }, + "currentDifficulty": { "$ref": "#/definitions/IntegerOrConfusedHex" }, + "currentGasLimit": { "$ref": "#/definitions/IntegerOrConfusedHex" }, + "currentNumber": { "$ref": "#/definitions/IntegerOrConfusedHex" }, + "currentTimestamp": { "$ref": "#/definitions/IntegerOrNumberOrConfusedHex" }, + "previousHash": { "$ref": "#/definitions/HexMaybePrefix" } + }, + "required": [ + "currentCoinbase", + "currentDifficulty", + "currentGasLimit", + "currentNumber", + "currentTimestamp", + "previousHash" + ], + "type": "object" + }, + "expect": {}, + "pre": { + "additionalProperties": false, + "patternProperties": { + "^[0-9a-fA-F]{40}": { + "description": "filler prestate addresses without 0x prefix", + "$ref": "#/definitions/PreStateAccount" + }, + "^0x[0-9a-fA-F]{40}": { + "description": "filler prestate addresses with 0x prefix", + "$ref": "#/definitions/PreStateAccount" + } + }, + "type": "object" + }, + "transaction": { + "oneOf": [ + { "$ref": "#/definitions/Transaction" }, + { "$ref": "#/definitions/NullSenderTransaction" } + ] + } + }, + "type": "object" + } + }, + "type": "object" +} -- cgit v1.2.3 From 4a582cf596bd4d4374e24ef6a7dd352fcd40d87f Mon Sep 17 00:00:00 2001 From: cdetrio Date: Sat, 5 Aug 2017 17:49:03 -0400 Subject: replace Metropolis with Byzantium and Constantinople in state test schema --- JSONSchema/schema.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index 5dee66084..ef08eef1b 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -295,7 +295,10 @@ "Homestead": { "$ref": "#/definitions/TransactionResults" }, - "Metropolis": { + "Byzantium": { + "$ref": "#/definitions/TransactionResults" + }, + "Constantinople": { "$ref": "#/definitions/TransactionResults" } }, -- cgit v1.2.3 From 28ccaf0bbd9d02cb63095da08feedd927021622d Mon Sep 17 00:00:00 2001 From: cdetrio Date: Mon, 7 Aug 2017 19:48:31 -0400 Subject: add storage and code restrictions to json schema --- JSONSchema/filler-schema.json | 13 ++++++++++++- JSONSchema/schema.json | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/JSONSchema/filler-schema.json b/JSONSchema/filler-schema.json index 07731f7b9..da9f2fea6 100644 --- a/JSONSchema/filler-schema.json +++ b/JSONSchema/filler-schema.json @@ -5,10 +5,12 @@ "pattern": "^$" }, "HexData": { + "description": "Hex data. see https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding", "pattern": "^0x([0-9a-fA-F][0-9a-fA-F])*$", "type": "string" }, "HexQuantity": { + "description": "Hex quantity. see https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding", "pattern": "(^0x0$)|(^0x[1-9a-fA-F][0-9a-fA-F]*$)", "type": "string" }, @@ -93,7 +95,16 @@ "balance": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, "code": { "type": "string" }, "nonce": { "$ref": "#/definitions/IntegerOrEmptyOrConfusedHex" }, - "storage": { "type": "object" } + "storage": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^0x[0-9a-f]+": { + "description": "storage key with 0x prefix, just the prefix `0x` is null and thus not permitted, a hex quantity is permitted. for the storage value, only hex data is permitted.", + "$ref": "#/definitions/HexData" + } + } + } }, "required": [ "balance", diff --git a/JSONSchema/schema.json b/JSONSchema/schema.json index ef08eef1b..7b1536dae 100644 --- a/JSONSchema/schema.json +++ b/JSONSchema/schema.json @@ -5,10 +5,12 @@ "pattern": "^$" }, "HexData": { + "description": "Hex data. see https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding", "pattern": "^0x([0-9a-fA-F][0-9a-fA-F])*$", "type": "string" }, "HexQuantity": { + "description": "Hex quantity. see https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding", "pattern": "(^0x0$)|(^0x[1-9a-fA-F][0-9a-fA-F]*$)", "type": "string" }, @@ -91,9 +93,18 @@ "additionalproperties": true, "properties": { "balance": { "$ref": "#/definitions/ConfusedHexType" }, - "code": { "type": "string" }, + "code": { "$ref": "#/definitions/HexMaybePrefixOrEmpty" }, "nonce": { "$ref": "#/definitions/ConfusedHexType" }, - "storage": { "type": "object" } + "storage": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^0x[0-9a-f]+": { + "description": "storage key with 0x. data is HexData", + "$ref": "#/definitions/HexData" + } + } + } }, "required": [ "balance", -- cgit v1.2.3