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