Reorganize files, set up testings

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

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)

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 .

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

13
python/tests/testdata/test_tx.rdf vendored Normal file
View File

@@ -0,0 +1,13 @@
@prefix evm: <https://defalsify.org/rdf-eth/0.1/#> .
@prefix cic: <https://cicnet.org/rdf/0.1/> .
@prefix ge: <https://grassrootseconomics.net/rdf/0.1/ge#> .
@prefix redcross: <https://redcross.com/cic-def/0.1/> .
@prefix un: <https://un.com/esg/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
evm:voucherTransfer
evm:id "6f4ed36c11345a9a48353cd2f93f1f92958c96df15f3112a192bc994250e8d03"^^xsd:hexBinary ;
ge:approvedActor <URN:uuid:18daebc7-23b9-41e4-af00-2559f7840f78> ;
redcross:interest ge:foodforest ;
un:esg "deforestation" ;
ge:impactRatio 0.3 .

46
python/tests/testdata/test_valid.json vendored Normal file

File diff suppressed because one or more lines are too long

24
python/tests/testdata/test_voucher.rdf vendored Normal file
View File

@@ -0,0 +1,24 @@
@prefix evm: <https://defalsify.org/rdf-eth/0.1/> .
@prefix cic: <https://cicnet.org/rdf/0.1/> .
@prefix ge: <https://grassrootseconomics.net/rdf/0.1/ge#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
evm:voucherContract
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 ;
foaf:name "John Doe" ;
cic:humanDescription <URN:sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae> ;
ge:areaSovereign "Kenya" ;
ge:areaGreater "Kilifi" ;
ge:areaLesser "Mnarani" ;
ge:community "Foo tribe" .
evm:voucherContract
evm:id "058c96df15f3112a192bc994250e8defef93f12345"^^xsd:hexBinary ;
cic:unitOfAccount "seashells" ;
cic:validFrom "2023-03-04T09:34:33+00:00"^^xsd:dateTime ;
foaf:name "Busy Bee" ;
ge:approvedActor <URN:uuid:18daebc7-23b9-41e4-af00-2559f7840f78> .