Skip to content
Snippets Groups Projects
Commit d24b68a8 authored by inso's avatar inso
Browse files

Fix bug with validationerror not being raised

Added tests to check that all requests returns an error
when the data is incorrect
parent 521a15f2
No related branches found
No related tags found
No related merge requests found
import unittest import unittest
import jsonschema import jsonschema
from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \ from ucoinpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \
Certifications, Joiners, Actives, Leavers, UD, TX Certifications, Joiners, Actives, Leavers, UD, TX
class Test_BMA_Blockchain(unittest.TestCase): class Test_BMA_Blockchain(WebFunctionalSetupMixin, unittest.TestCase):
def test_parameters(self): def test_parameters(self):
json_sample = { json_sample = {
"currency": "meta_brouzouf", "currency": "meta_brouzouf",
...@@ -25,6 +26,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -25,6 +26,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Parameters.schema) jsonschema.validate(json_sample, Parameters.schema)
def test_parameters_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
params = Parameters(None)
params.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from params.get()
self.loop.run_until_complete(go())
def test_schema_block_0(self): def test_schema_block_0(self):
json_sample = { json_sample = {
"version": 1, "version": 1,
...@@ -79,6 +96,38 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -79,6 +96,38 @@ class Test_BMA_Blockchain(unittest.TestCase):
jsonschema.validate(json_sample, Block.schema) jsonschema.validate(json_sample, Block.schema)
jsonschema.validate(json_sample, Current.schema) jsonschema.validate(json_sample, Current.schema)
def test_block_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/100', handler)
block = Block(None, 100)
block.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from block.get()
self.loop.run_until_complete(go())
def test_current_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
current = Current(None)
current.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from current.get()
self.loop.run_until_complete(go())
def test_schema_block(self): def test_schema_block(self):
json_sample = { json_sample = {
"version": 1, "version": 1,
...@@ -125,6 +174,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -125,6 +174,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Hardship.schema) jsonschema.validate(json_sample, Hardship.schema)
def test_hardship_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/fingerprint', handler)
hardship = Hardship(None, "fingerprint")
hardship.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from hardship.get()
self.loop.run_until_complete(go())
def test_schema_membership(self): def test_schema_membership(self):
json_sample = { json_sample = {
"pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU", "pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU",
...@@ -149,6 +214,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -149,6 +214,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Membership.schema) jsonschema.validate(json_sample, Membership.schema)
def test_membership_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
membership = Membership(None, "pubkey")
membership.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from membership.get()
self.loop.run_until_complete(go())
def test_schema_newcomers(self): def test_schema_newcomers(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -157,6 +238,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -157,6 +238,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Newcomers.schema) jsonschema.validate(json_sample, Newcomers.schema)
def test_newcomers_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
newcomers = Newcomers(None)
newcomers.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from newcomers.get()
self.loop.run_until_complete(go())
def test_schema_certifications(self): def test_schema_certifications(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -165,6 +262,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -165,6 +262,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Certifications.schema) jsonschema.validate(json_sample, Certifications.schema)
def test_certifications_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
certs = Certifications(None)
certs.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from certs.get()
self.loop.run_until_complete(go())
def test_schema_joiners(self): def test_schema_joiners(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -173,6 +286,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -173,6 +286,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Joiners.schema) jsonschema.validate(json_sample, Joiners.schema)
def test_joiners_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
joiners = Joiners(None)
joiners.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from joiners.get()
self.loop.run_until_complete(go())
def test_schema_actives(self): def test_schema_actives(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -181,6 +310,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -181,6 +310,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Actives.schema) jsonschema.validate(json_sample, Actives.schema)
def test_actives_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
actives = Actives(None)
actives.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from actives.get()
self.loop.run_until_complete(go())
def test_schema_leavers(self): def test_schema_leavers(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -189,6 +334,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -189,6 +334,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, Leavers.schema) jsonschema.validate(json_sample, Leavers.schema)
def test_leavers_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
leavers = Leavers(None)
leavers.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from leavers.get()
self.loop.run_until_complete(go())
def test_schema_ud(self): def test_schema_ud(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -197,6 +358,22 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -197,6 +358,22 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
jsonschema.validate(json_sample, UD.schema) jsonschema.validate(json_sample, UD.schema)
def test_ud_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
ud = UD(None)
ud.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from ud.get()
self.loop.run_until_complete(go())
def test_schema_tx(self): def test_schema_tx(self):
json_sample = { json_sample = {
"result": { "result": {
...@@ -204,3 +381,19 @@ class Test_BMA_Blockchain(unittest.TestCase): ...@@ -204,3 +381,19 @@ class Test_BMA_Blockchain(unittest.TestCase):
} }
} }
jsonschema.validate(json_sample, TX.schema) jsonschema.validate(json_sample, TX.schema)
def test_tx_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
tx = TX(None)
tx.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from tx.get()
self.loop.run_until_complete(go())
\ No newline at end of file
import unittest import unittest
import jsonschema import jsonschema
from ucoinpy.api.bma.network import Peering from ucoinpy.api.bma.network import Peering
from ucoinpy.api.bma.network.peering import Peers, Status from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.network.peering import Peers
class Test_BMA_Network(unittest.TestCase): class Test_BMA_Network(WebFunctionalSetupMixin, unittest.TestCase):
def test_peering(self): def test_peering(self):
json_sample = { json_sample = {
...@@ -20,6 +21,21 @@ class Test_BMA_Network(unittest.TestCase): ...@@ -20,6 +21,21 @@ class Test_BMA_Network(unittest.TestCase):
} }
jsonschema.validate(json_sample, Peering.schema) jsonschema.validate(json_sample, Peering.schema)
def test_peering_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
peering = Peering(None)
peering.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from peering.get()
self.loop.run_until_complete(go())
def test_peers_root(self): def test_peers_root(self):
json_sample = { json_sample = {
...@@ -46,3 +62,19 @@ class Test_BMA_Network(unittest.TestCase): ...@@ -46,3 +62,19 @@ class Test_BMA_Network(unittest.TestCase):
} }
} }
jsonschema.validate(json_sample, Peers.schema) jsonschema.validate(json_sample, Peers.schema)
def test_peers_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
peers = Peers(None)
peers.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from peers.get()
self.loop.run_until_complete(go())
\ No newline at end of file
import unittest import unittest
import jsonschema import jsonschema
from ucoinpy.api.bma.tx import History, Sources from ucoinpy.api.bma.tx import History, Sources
from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.tx.history import Blocks from ucoinpy.api.bma.tx.history import Blocks
class Test_BMA_TX(unittest.TestCase): class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
def test_bma_tx_history(self): def test_bma_tx_history(self):
json_sample = { json_sample = {
"currency": "meta_brouzouf", "currency": "meta_brouzouf",
...@@ -119,6 +120,38 @@ class Test_BMA_TX(unittest.TestCase): ...@@ -119,6 +120,38 @@ class Test_BMA_TX(unittest.TestCase):
jsonschema.validate(json_sample, History.schema) jsonschema.validate(json_sample, History.schema)
jsonschema.validate(json_sample, Blocks.schema) jsonschema.validate(json_sample, Blocks.schema)
def test_bma_tx_history_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
history = History(None, 'pubkey')
history.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from history.get()
self.loop.run_until_complete(go())
def test_bma_tx_history_blocks_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey/0/100', handler)
blocks = Blocks(None, 'pubkey', 0, 100)
blocks.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from blocks.get()
self.loop.run_until_complete(go())
def test_bma_tx_sources(self): def test_bma_tx_sources(self):
json_sample = { json_sample = {
"currency": "meta_brouzouf", "currency": "meta_brouzouf",
...@@ -141,3 +174,19 @@ class Test_BMA_TX(unittest.TestCase): ...@@ -141,3 +174,19 @@ class Test_BMA_TX(unittest.TestCase):
] ]
} }
jsonschema.validate(json_sample, Sources.schema) jsonschema.validate(json_sample, Sources.schema)
def test_bma_tx_sources_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
sources = Sources(None, 'pubkey')
sources.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from sources.get()
self.loop.run_until_complete(go())
\ No newline at end of file
import unittest import unittest
import jsonschema import jsonschema
from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio
from ucoinpy.api.bma.wot import Lookup, Members, CertifiedBy, CertifiersOf from ucoinpy.api.bma.wot import Lookup, Members, CertifiedBy, CertifiersOf
class Test_BMA_Wot(unittest.TestCase): class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
def test_bma_wot_lookup(self): def test_bma_wot_lookup(self):
json_sample = { json_sample = {
"partial": False, "partial": False,
...@@ -65,7 +66,23 @@ class Test_BMA_Wot(unittest.TestCase): ...@@ -65,7 +66,23 @@ class Test_BMA_Wot(unittest.TestCase):
} }
] ]
} }
jsonschema.validate(Lookup.schema, json_sample) jsonschema.validate(json_sample, Lookup.schema)
def test_bma_wot_lookup_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
lookup = Lookup(None, "pubkey")
lookup.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from lookup.get()
self.loop.run_until_complete(go())
def test_bma_wot_members(self): def test_bma_wot_members(self):
json_sample = { json_sample = {
...@@ -77,6 +94,22 @@ class Test_BMA_Wot(unittest.TestCase): ...@@ -77,6 +94,22 @@ class Test_BMA_Wot(unittest.TestCase):
} }
jsonschema.validate(Members.schema, json_sample) jsonschema.validate(Members.schema, json_sample)
def test_bma_wot_members_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
members = Members(None)
members.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from members.get()
self.loop.run_until_complete(go())
def test_bma_wot_cert(self): def test_bma_wot_cert(self):
json_sample = { json_sample = {
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY", "pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
...@@ -101,3 +134,35 @@ class Test_BMA_Wot(unittest.TestCase): ...@@ -101,3 +134,35 @@ class Test_BMA_Wot(unittest.TestCase):
} }
jsonschema.validate(json_sample, CertifiersOf.schema) jsonschema.validate(json_sample, CertifiersOf.schema)
jsonschema.validate(json_sample, CertifiedBy.schema) jsonschema.validate(json_sample, CertifiedBy.schema)
def test_bma_wot_certifiers_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
certsof = CertifiersOf(None, 'pubkey')
certsof.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from certsof.get()
self.loop.run_until_complete(go())
def test_bma_wot_certified_bad(self):
@asyncio.coroutine
def handler(request):
yield from request.read()
return web.Response(body=b'{}', content_type='application/json')
@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/pubkey', handler)
certby = CertifiedBy(None, 'pubkey')
certby.reverse_url = lambda path: url
with self.assertRaises(jsonschema.exceptions.ValidationError):
yield from certby.get()
self.loop.run_until_complete(go())
import asyncio
import socket
from aiohttp import web
from aiohttp import log
# Thanks to aiohttp tests courtesy
# Here is a nice mocking server
class WebFunctionalSetupMixin:
def setUp(self):
self.handler = None
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def tearDown(self):
if self.handler:
self.loop.run_until_complete(self.handler.finish_connections())
try:
self.loop.stop()
self.loop.close()
finally:
asyncio.set_event_loop(None)
def find_unused_port(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 0))
port = s.getsockname()[1]
s.close()
return port
@asyncio.coroutine
def create_server(self, method, path, handler=None, ssl_ctx=None):
app = web.Application(loop=self.loop)
if handler:
app.router.add_route(method, path, handler)
port = self.find_unused_port()
self.handler = app.make_handler(
keep_alive_on=False,
access_log=log.access_logger)
srv = yield from self.loop.create_server(
self.handler, '127.0.0.1', port, ssl=ssl_ctx)
protocol = "https" if ssl_ctx else "http"
url = "{}://127.0.0.1:{}".format(protocol, port) + path
self.addCleanup(srv.close)
return app, srv, url
\ No newline at end of file
...@@ -16,20 +16,19 @@ BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30 ...@@ -16,20 +16,19 @@ BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r 42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r
""" """
tx_raw = """Version: 1 tx_raw = ("Version: 1\n"
Type: Transaction "Type: Transaction\n"
Currency: beta_brousouf "Currency: beta_brousouf\n"
Issuers: "Issuers:\n"
HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY\n"
Inputs: "Inputs:\n"
0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4 "0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4\n"
0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15 "0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15\n"
0:D:88:F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B:11 "0:D:88:F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B:11\n"
Outputs: "Outputs:\n"
BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30 "BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30\n"
Comment: "Comment: \n"
42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r\n")
"""
class Test_Transaction(unittest.TestCase): class Test_Transaction(unittest.TestCase):
......
...@@ -21,7 +21,7 @@ PROTOCOL_VERSION="1" ...@@ -21,7 +21,7 @@ PROTOCOL_VERSION="1"
MANAGED_API=["BASIC_MERKLED_API"] MANAGED_API=["BASIC_MERKLED_API"]
__author__ = 'Caner Candan & inso' __author__ = 'Caner Candan & inso'
__version__ = '0.12.0' __version__ = '0.12.1'
__nonsense__ = 'uCoin' __nonsense__ = 'uCoin'
from . import api, documents, key from . import api, documents, key
\ No newline at end of file
...@@ -77,7 +77,9 @@ class Parameters(Blockchain): ...@@ -77,7 +77,9 @@ class Parameters(Blockchain):
"percentRot": { "percentRot": {
"type": "number" "type": "number"
}, },
} },
"required": ["currency", "c", "dt", "ud0","sigDelay","sigValidity","sigQty","sigWoT","msValidity",
"stepMax", "medianTimeBlocks", "avgGenTime", "dtDiffEval", "blocksRot", "percentRot"]
} }
def __get__(self, **kwargs): def __get__(self, **kwargs):
r = yield from self.requests_get('/parameters', **kwargs) r = yield from self.requests_get('/parameters', **kwargs)
...@@ -120,9 +122,11 @@ class Membership(Blockchain): ...@@ -120,9 +122,11 @@ class Membership(Blockchain):
"type": "string" "type": "string"
} }
}, },
"required": ["version", "currency", "membership", "blockNumber", "blockHash"]
} }
} }
} },
"required": ["pubkey", "uid", "sigDate", "memberships"]
} }
def __init__(self, connection_handler, search=None): def __init__(self, connection_handler, search=None):
...@@ -159,7 +163,10 @@ class Block(Blockchain): ...@@ -159,7 +163,10 @@ class Block(Blockchain):
"number": { "number": {
"type": "number" "type": "number"
}, },
"timestamp": { "time": {
"type": "number"
},
"medianTime": {
"type": "number" "type": "number"
}, },
"dividend": { "dividend": {
...@@ -245,13 +252,17 @@ class Block(Blockchain): ...@@ -245,13 +252,17 @@ class Block(Blockchain):
"type": "string" "type": "string"
} }
} }
} },
"required": ["signatures", "version", "currency", "issuers", "inputs", "outputs"]
} }
}, },
"signature": { "signature": {
"type": "string" "type": "string"
} },
} },
"required": ["version", "currency", "nonce", "number", "time", "medianTime", "dividend", "monetaryMass",
"issuer", "previousHash", "previousIssuer", "membersCount", "hash", "identities",
"joiners", "leavers", "excluded", "certifications", "transactions", "signature"]
} }
def __init__(self, connection_handler, number=None): def __init__(self, connection_handler, number=None):
...@@ -300,7 +311,8 @@ class Hardship(Blockchain): ...@@ -300,7 +311,8 @@ class Hardship(Blockchain):
"level": { "level": {
"type": "number" "type": "number"
} }
} },
"required": ["block", "level"]
} }
def __init__(self, connection_handler, fingerprint): def __init__(self, connection_handler, fingerprint):
...@@ -327,13 +339,18 @@ class Newcomers(Blockchain): ...@@ -327,13 +339,18 @@ class Newcomers(Blockchain):
schema = { schema = {
"type": "object", "type": "object",
"properties": { "properties": {
"block": { "result":{
"type": "number" "type": "object",
"properties": {
"blocks": {
"type": "array",
"item": "number"
}, },
"level": { },
"type": "number" "required": ["blocks"]
}
} }
},
"required": ["result"]
} }
def __get__(self, **kwargs): def __get__(self, **kwargs):
...@@ -355,6 +372,7 @@ class Joiners(Blockchain): ...@@ -355,6 +372,7 @@ class Joiners(Blockchain):
"""GET, return block numbers containing joiners.""" """GET, return block numbers containing joiners."""
schema = Newcomers.schema schema = Newcomers.schema
def __get__(self, **kwargs): def __get__(self, **kwargs):
r = yield from self.requests_get('/with/joiners', **kwargs) r = yield from self.requests_get('/with/joiners', **kwargs)
return (yield from self.parse(r)) return (yield from self.parse(r))
...@@ -397,7 +415,7 @@ class UD(Blockchain): ...@@ -397,7 +415,7 @@ class UD(Blockchain):
def __get__(self, **kwargs): def __get__(self, **kwargs):
r = yield from self.requests_get('/with/ud', **kwargs) r = yield from self.requests_get('/with/ud', **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
class TX(Blockchain): class TX(Blockchain):
...@@ -407,4 +425,4 @@ class TX(Blockchain): ...@@ -407,4 +425,4 @@ class TX(Blockchain):
def __get__(self, **kwargs): def __get__(self, **kwargs):
r = yield from self.requests_get('/with/tx', **kwargs) r = yield from self.requests_get('/with/tx', **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
...@@ -106,7 +106,8 @@ class History(Tx): ...@@ -106,7 +106,8 @@ class History(Tx):
"comment", "signatures", "hash", "block_number", "time"] "comment", "signatures", "hash", "block_number", "time"]
} }
} }
} },
"required": ["currency", "pubkey", "history"]
} }
def __init__(self, conn_handler, pubkey, module='tx'): def __init__(self, conn_handler, pubkey, module='tx'):
...@@ -175,7 +176,7 @@ class Sources(Tx): ...@@ -175,7 +176,7 @@ class Sources(Tx):
def __get__(self, **kwargs): def __get__(self, **kwargs):
assert self.pubkey is not None assert self.pubkey is not None
r = yield from self.requests_get('/sources/%s' % self.pubkey, **kwargs) r = yield from self.requests_get('/sources/%s' % self.pubkey, **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
from . import history from . import history
...@@ -148,7 +148,7 @@ class Lookup(WOT): ...@@ -148,7 +148,7 @@ class Lookup(WOT):
assert self.search is not None assert self.search is not None
r = yield from self.requests_get('/lookup/%s' % self.search, **kwargs) r = yield from self.requests_get('/lookup/%s' % self.search, **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
class CertifiersOf(WOT): class CertifiersOf(WOT):
...@@ -224,7 +224,7 @@ class CertifiersOf(WOT): ...@@ -224,7 +224,7 @@ class CertifiersOf(WOT):
assert self.search is not None assert self.search is not None
r = yield from self.requests_get('/certifiers-of/%s' % self.search, **kwargs) r = yield from self.requests_get('/certifiers-of/%s' % self.search, **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
class CertifiedBy(WOT): class CertifiedBy(WOT):
...@@ -241,7 +241,7 @@ class CertifiedBy(WOT): ...@@ -241,7 +241,7 @@ class CertifiedBy(WOT):
assert self.search is not None assert self.search is not None
r = yield from self.requests_get('/certified-by/%s' % self.search, **kwargs) r = yield from self.requests_get('/certified-by/%s' % self.search, **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
class Members(WOT): class Members(WOT):
...@@ -257,10 +257,12 @@ class Members(WOT): ...@@ -257,10 +257,12 @@ class Members(WOT):
"pubkey": { "pubkey": {
"type": "string" "type": "string"
} }
},
"required": ["pubkey"]
} }
} }
} },
} "required": ["results"]
} }
def __init__(self, connection_handler, module='wot'): def __init__(self, connection_handler, module='wot'):
...@@ -268,4 +270,4 @@ class Members(WOT): ...@@ -268,4 +270,4 @@ class Members(WOT):
def __get__(self, **kwargs): def __get__(self, **kwargs):
r = yield from self.requests_get('/members', **kwargs) r = yield from self.requests_get('/members', **kwargs)
return (yield from r.json()) return (yield from self.parse(r))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment