Reorganize files, set up testings

This commit is contained in:
lash 2023-03-09 08:30:47 +00:00
parent 73e53c6859
commit 929a042c95
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
24 changed files with 141 additions and 11 deletions

View File

@ -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

1
dist/cic.json vendored
View File

@ -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"]}]}

3
python/Makefile Normal file
View File

@ -0,0 +1,3 @@
.PHONY: all
all:

View File

@ -0,0 +1 @@
from .cert import Cert

Binary file not shown.

Binary file not shown.

17
python/cic_schema/cert.py Normal file
View File

@ -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)

4
python/requirements.txt Normal file
View File

@ -0,0 +1,4 @@
check-jsonschema==0.21.0
rdflib==6.2.0
jsonschema==4.17.3

View File

@ -0,0 +1 @@
hypothesis==6.68.2

33
python/tests/test_json.py Normal file
View File

@ -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()

33
python/tests/test_nft.py Normal file
View File

@ -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()

View File

@ -6,7 +6,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
evm:voucherTransfer
evm:id "0x6f4ed36c11345a9a48353cd2f93f1f92958c96df15f3112a192bc994250e8d03"^^xsd:hexBinary ;
evm:id "6f4ed36c11345a9a48353cd2f93f1f92958c96df15f3112a192bc994250e8d03"^^xsd:hexBinary ;
ge:approvedActor <URN:uuid:18daebc7-23b9-41e4-af00-2559f7840f78> ;
redcross:interest ge:foodforest ;
un:esg "deforestation" ;

View File

@ -5,7 +5,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
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 <URN:uuid:18daebc7-23b9-41e4-af00-2559f7840f78> .

View File

@ -1 +0,0 @@
check-jsonschema==0.21.0

12
schema/json/Makefile Normal file
View File

@ -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/

5
schema/rdf/Makefile Normal file
View File

@ -0,0 +1,5 @@
all: install
install:
cp -v evm.rdfs ../../python/cic_schema/data/

14
schema/rdf/evm.rdfs Normal file
View File

@ -0,0 +1,14 @@
@base <https://defalsify.org/rdf-eth/0.1/evm.rdfs> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <https://www.w3.org/TR/rdf-schema/#> .
<#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 .