From 929a042c95f9bd7dfa31bc236f00aded9db43640 Mon Sep 17 00:00:00 2001 From: lash Date: Thu, 9 Mar 2023 08:30:47 +0000 Subject: [PATCH] Reorganize files, set up testings --- Makefile | 19 +++++++--- dist/cic.json | 1 - python/Makefile | 3 ++ python/cic_schema/__init__.py | 1 + .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 209 bytes .../__pycache__/cert.cpython-310.pyc | Bin 0 -> 744 bytes python/cic_schema/cert.py | 17 +++++++++ evm.rdfs => python/cic_schema/data/evm.rdfs | 0 python/requirements.txt | 4 +++ python/test_requirements.txt | 1 + python/tests/test_json.py | 33 ++++++++++++++++++ python/tests/test_nft.py | 33 ++++++++++++++++++ .../tests/testdata/test_tx.rdf | 2 +- .../tests/testdata/test_valid.json | 0 .../tests/testdata/test_voucher.rdf | 6 ++-- requirements.txt | 1 - schema/json/Makefile | 12 +++++++ bundle.py => schema/json/bundle.py | 0 cic.in.json => schema/json/cic.in.json | 0 mime.in.json => schema/json/mime.in.json | 0 nft.in.json => schema/json/nft.in.json | 0 .../json/opensea_part.in.json | 0 schema/rdf/Makefile | 5 +++ schema/rdf/evm.rdfs | 14 ++++++++ 24 files changed, 141 insertions(+), 11 deletions(-) delete mode 100644 dist/cic.json create mode 100644 python/Makefile create mode 100644 python/cic_schema/__init__.py create mode 100644 python/cic_schema/__pycache__/__init__.cpython-310.pyc create mode 100644 python/cic_schema/__pycache__/cert.cpython-310.pyc create mode 100644 python/cic_schema/cert.py rename evm.rdfs => python/cic_schema/data/evm.rdfs (100%) create mode 100644 python/requirements.txt create mode 100644 python/test_requirements.txt create mode 100644 python/tests/test_json.py create mode 100644 python/tests/test_nft.py rename test_tx.rdf => python/tests/testdata/test_tx.rdf (83%) rename test_valid.json => python/tests/testdata/test_valid.json (100%) rename test_voucher.rdf => python/tests/testdata/test_voucher.rdf (83%) delete mode 100644 requirements.txt create mode 100644 schema/json/Makefile rename bundle.py => schema/json/bundle.py (100%) rename cic.in.json => schema/json/cic.in.json (100%) rename mime.in.json => schema/json/mime.in.json (100%) rename nft.in.json => schema/json/nft.in.json (100%) rename opensea_part.in.json => schema/json/opensea_part.in.json (100%) create mode 100644 schema/rdf/Makefile create mode 100644 schema/rdf/evm.rdfs diff --git a/Makefile b/Makefile index c0ea30d..4cf77f7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,17 @@ -all: build +all: json rdf python -build: - python bundle.py > cic.json +.PHONY: json rdf python -test: build - check-jsonschema --schemafile dist/cic.json test_valid.json +json: + make -C schema/json + +rdf: + make -C schema/rdf + +python: + make -C python + +install: python + make -C schema/json install + make -C schema/rdf install diff --git a/dist/cic.json b/dist/cic.json deleted file mode 100644 index 10cc27a..0000000 --- a/dist/cic.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema": "https://json-schema.org/draft/2020-12/schema", "title": "CIC core metadata container", "$id": "/cic/core", "type": "object", "properties": {"version": {"type": "integer"}, "attachments": {"type": "array", "items": {"$ref": "/mime"}}, "certifications": {"type": "array", "items": {"type": "string", "format": "uri"}, "minItems": 1}, "image_data": {"type": "string", "description": "Raw SVG image data, if you want to generate images on the fly (not recommended). Only use this if you're not including the image parameter.", "contentEncoding": "base64", "contentMediaType": "image/svg+xml"}, "image": {"type": "string", "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive.", "format": "uri"}, "external_url": {"type": "string", "description": "This is the URL that will appear below the asset's image on OpenSea and will allow users to leave OpenSea and view the item on your site.", "format": "uri"}, "attributes": {"type": "array", "description": "These are the attributes for the item, which will show up on the OpenSea page for the item. (see below)", "items": {"type": "object", "properties": {"trait_type": {"type": "string"}, "value": {"oneOf": [{"type": "string"}, {"type": "number"}]}, "display_type": {"type": "string"}}, "required": ["trait_type", "value"]}}, "animation_url": {"type": "string", "description": "Animation_url also supports HTML pages, allowing you to build rich experiences and interactive NFTs using JavaScript canvas, WebGL, and more. Scripts and relative paths within the HTML page are now supported. However, access to browser extensions is not supported.", "format": "uri"}, "name": {"type": "string", "description": "Identifies the asset to which this NFT represents"}, "description": {"type": "string", "description": "Describes the asset to which this NFT represents"}}, "required": ["version", "attachments", "attributes"], "mime": {"$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "/mime", "title": "A single generic attachment for documenting any asset", "type": "object", "properties": {"contentType": {"type": "string", "$comment": "valid mime type"}, "contentTransferEncoding": {"type": "string", "enum": ["BASE64", "QUOTED-PRINTABLE", "8BIT", "7BIT"]}, "subject": {"type": "string", "$comment": "utf-8"}, "body": {"type": "string", "$comment": "uri including dataurl"}, "ref": {"type": "string", "format": "uri"}}, "required": ["contentType", "subject"], "oneOf": [{"required": ["body"]}, {"required": ["ref"]}]}, "oneOf": [{"required": ["image"]}, {"required": ["image_data"]}]} \ No newline at end of file diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 0000000..d36928e --- /dev/null +++ b/python/Makefile @@ -0,0 +1,3 @@ +.PHONY: all + +all: diff --git a/python/cic_schema/__init__.py b/python/cic_schema/__init__.py new file mode 100644 index 0000000..8c2723c --- /dev/null +++ b/python/cic_schema/__init__.py @@ -0,0 +1 @@ +from .cert import Cert diff --git a/python/cic_schema/__pycache__/__init__.cpython-310.pyc b/python/cic_schema/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e0fc395b38aaf536db178276fbd731ba495ca0a GIT binary patch literal 209 zcmd1j<>g`kf{5vyDdIr-F^Gc(44TX@8G*u@ zjJH^vQ;SOcG?{L(Bm)^mAYCgNidcXYnD`Z}pOK%Ns-KfsoS|P_l&qhepI1_pnWUdy zlvrF`l%HQxoC*}m&&^CO)=$n%)-6uXNX<>uFQ_cZ$j<|b#6v~m<1_OzOXB183My}L U*yQG?l;)(`fgDi`vQvNo0EhlG(*OVf literal 0 HcmV?d00001 diff --git a/python/cic_schema/__pycache__/cert.cpython-310.pyc b/python/cic_schema/__pycache__/cert.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ba65e9369990b9d5d08f6600fe9427e7302cb2e4 GIT binary patch literal 744 zcmZvaF>ll`6vzGSB)x0zid2wTSYSZPK=TCq2WEt)1UM#o8=JFb5wm@#qIuhFnvL)VI^o*at)f_vQn62 zkdNw#Y$S5!^)%2l=LRMD?}ZI@Az_ewUrmonbGiwq-p0-I?>JpEJq zhc(_;j0aX?B+7vhJ`w9zzUANGFRQrjT1@E;VmzQFjGe(owavza^a>kqs4$KNxC-!b z0NqWKC}!rmx9A^HKJ<4C$FMmX`rB1z`9Z{3s?JCm4yEj@UbQiwNcmx<+Fb>w(M`Cu z3z_rUt~@>_W$(Cn!x+!R$Ty;J*^rF*NjhkGf=@{a8R~i4TnwLVDE!YQj9%|Lc|-s5 Ky%kKviTDlXTckSx literal 0 HcmV?d00001 diff --git a/python/cic_schema/cert.py b/python/cic_schema/cert.py new file mode 100644 index 0000000..e197212 --- /dev/null +++ b/python/cic_schema/cert.py @@ -0,0 +1,17 @@ +# standard imports +import sys + +# external imports +from rdflib import Graph + + +class Cert: + + def __init__(self, path): + self.g = Graph() + self.g.parse(path, format='turtle') + + + def export(self, w=sys.stdout): + v = self.g.serialize(format='xml') + w.write(v) diff --git a/evm.rdfs b/python/cic_schema/data/evm.rdfs similarity index 100% rename from evm.rdfs rename to python/cic_schema/data/evm.rdfs diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..5944c66 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,4 @@ +check-jsonschema==0.21.0 +rdflib==6.2.0 +jsonschema==4.17.3 + diff --git a/python/test_requirements.txt b/python/test_requirements.txt new file mode 100644 index 0000000..3eaeb89 --- /dev/null +++ b/python/test_requirements.txt @@ -0,0 +1 @@ +hypothesis==6.68.2 diff --git a/python/tests/test_json.py b/python/tests/test_json.py new file mode 100644 index 0000000..332c931 --- /dev/null +++ b/python/tests/test_json.py @@ -0,0 +1,33 @@ +# standard imports +import unittest +import json +import os + +# external imports +from jsonschema import validate as json_validate + +test_dir = os.path.realpath(os.path.dirname(__file__)) +testdata_dir = os.path.join(test_dir, 'testdata') +data_dir = os.path.join(test_dir, '..', 'cic_schema', 'data') + + +class TestJsonData(unittest.TestCase): + + def setUp(self): + fp = os.path.join(data_dir, 'cic.json') + f = open(fp, 'r') + self.schema = json.load(f) + f.close() + + + def test_schema_load(self): + fp = os.path.join(testdata_dir, 'test_valid.json') + f = open(fp, 'r') + o = json.load(f) + f.close() + validator = json_validate(o, self.schema) + + + +if __name__ == '__main__': + unittest.main() diff --git a/python/tests/test_nft.py b/python/tests/test_nft.py new file mode 100644 index 0000000..790aa15 --- /dev/null +++ b/python/tests/test_nft.py @@ -0,0 +1,33 @@ +# standard imports +import unittest +import json +import os + +# external imports +from jsonschema import validate as json_validate +from rdflib import Graph +#from hypothesis import given, strategies + +# local imports +from cic_schema import Cert + +test_dir = os.path.realpath(os.path.dirname(__file__)) +testdata_dir = os.path.join(test_dir, 'testdata') +data_dir = os.path.join(test_dir, '..', 'cic_schema', 'data') + + +class TestNft(unittest.TestCase): + + def setUp(self): + fp = os.path.join(testdata_dir, 'test_voucher.rdf') + self.graph_voucher = Cert(fp) + fp = os.path.join(testdata_dir, 'test_tx.rdf') + self.graph_tx = Cert(fp) + + + def test_simplest(self): + print(self.graph_tx.export()) + + +if __name__ == '__main__': + unittest.main() diff --git a/test_tx.rdf b/python/tests/testdata/test_tx.rdf similarity index 83% rename from test_tx.rdf rename to python/tests/testdata/test_tx.rdf index 4b09388..0f32ea7 100644 --- a/test_tx.rdf +++ b/python/tests/testdata/test_tx.rdf @@ -6,7 +6,7 @@ @prefix xsd: . evm:voucherTransfer - evm:id "0x6f4ed36c11345a9a48353cd2f93f1f92958c96df15f3112a192bc994250e8d03"^^xsd:hexBinary ; + evm:id "6f4ed36c11345a9a48353cd2f93f1f92958c96df15f3112a192bc994250e8d03"^^xsd:hexBinary ; ge:approvedActor ; redcross:interest ge:foodforest ; un:esg "deforestation" ; diff --git a/test_valid.json b/python/tests/testdata/test_valid.json similarity index 100% rename from test_valid.json rename to python/tests/testdata/test_valid.json diff --git a/test_voucher.rdf b/python/tests/testdata/test_voucher.rdf similarity index 83% rename from test_voucher.rdf rename to python/tests/testdata/test_voucher.rdf index 3a877bd..090eaab 100644 --- a/test_voucher.rdf +++ b/python/tests/testdata/test_voucher.rdf @@ -5,7 +5,7 @@ @prefix xsd: . evm:voucherContract - evm:id "0x1f92958c96df15f3112a192bc994250e8defef93f"^^xsd:hexBinary ; + evm:id "01f92958c96df15f3112a192bc994250e8defef93f"^^xsd:hexBinary ; cic:unitOfAccount cic:ref:wampum ; cic:validFrom "2023-03-05T19:04:40+00:00"^^xsd:dateTime ; cic:validUntil "2024-03-05T19:04:40+00:00"^^xsd:dateTime ; @@ -17,8 +17,8 @@ evm:voucherContract ge:community "Foo tribe" . evm:voucherContract - evm:id "0x58c96df15f3112a192bc994250e8defef93f12345"^^xsd:hexBinary ; + evm:id "058c96df15f3112a192bc994250e8defef93f12345"^^xsd:hexBinary ; cic:unitOfAccount "seashells" ; cic:validFrom "2023-03-04T09:34:33+00:00"^^xsd:dateTime ; - foaf:name "Busy Bee" + foaf:name "Busy Bee" ; ge:approvedActor . diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index fee269a..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -check-jsonschema==0.21.0 diff --git a/schema/json/Makefile b/schema/json/Makefile new file mode 100644 index 0000000..cc7efab --- /dev/null +++ b/schema/json/Makefile @@ -0,0 +1,12 @@ +all: build + +build: + python bundle.py + + +test: build + check-jsonschema --schemafile dist/cic.json test_valid.json + + +install: build + cp -v dist/cic.json ../../python/cic_schema/data/ diff --git a/bundle.py b/schema/json/bundle.py similarity index 100% rename from bundle.py rename to schema/json/bundle.py diff --git a/cic.in.json b/schema/json/cic.in.json similarity index 100% rename from cic.in.json rename to schema/json/cic.in.json diff --git a/mime.in.json b/schema/json/mime.in.json similarity index 100% rename from mime.in.json rename to schema/json/mime.in.json diff --git a/nft.in.json b/schema/json/nft.in.json similarity index 100% rename from nft.in.json rename to schema/json/nft.in.json diff --git a/opensea_part.in.json b/schema/json/opensea_part.in.json similarity index 100% rename from opensea_part.in.json rename to schema/json/opensea_part.in.json diff --git a/schema/rdf/Makefile b/schema/rdf/Makefile new file mode 100644 index 0000000..05e55f5 --- /dev/null +++ b/schema/rdf/Makefile @@ -0,0 +1,5 @@ +all: install + +install: + cp -v evm.rdfs ../../python/cic_schema/data/ + diff --git a/schema/rdf/evm.rdfs b/schema/rdf/evm.rdfs new file mode 100644 index 0000000..1e3d575 --- /dev/null +++ b/schema/rdf/evm.rdfs @@ -0,0 +1,14 @@ +@base . +@prefix xsd: . +@prefix rdfs: . + +<#location> a rdfs:Class . +<#tx> a rdfs:Class . +<#account> rdfs:subClassOf <#location> . +<#contract> rdfs:subClassOf <#location> . +<#voucherContract> rdfs:subClassOf <#contract> . +<#nftContract> rdfs:subClassOf <#contract> . +<#gasTransfer> rdfs:subClassOf <#tx> . +<#voucherTransfer> rdfs:subClassOf <#tx> . +<#nftTransfer> rdfs:subClassOf <#tx> . +<#id> rdfs:Datatype xsd:hexBinary .