diff --git a/_ucoinpy_test/api/bma/test_blockchain.py b/_ucoinpy_test/api/bma/test_blockchain.py index 1c745e29cb1632983a1ac2face7a1aeb609c4844..72959726106c24e74c8ea1e7931d6323fac10a1b 100644 --- a/_ucoinpy_test/api/bma/test_blockchain.py +++ b/_ucoinpy_test/api/bma/test_blockchain.py @@ -1,10 +1,11 @@ import unittest import jsonschema +from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio from ucoinpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \ Certifications, Joiners, Actives, Leavers, UD, TX -class Test_BMA_Blockchain(unittest.TestCase): +class Test_BMA_Blockchain(WebFunctionalSetupMixin, unittest.TestCase): def test_parameters(self): json_sample = { "currency": "meta_brouzouf", @@ -25,6 +26,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "version": 1, @@ -79,6 +96,38 @@ class Test_BMA_Blockchain(unittest.TestCase): jsonschema.validate(json_sample, Block.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): json_sample = { "version": 1, @@ -125,6 +174,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU", @@ -149,6 +214,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -157,6 +238,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -165,6 +262,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -173,6 +286,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -181,6 +310,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -189,6 +334,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -197,6 +358,22 @@ class Test_BMA_Blockchain(unittest.TestCase): } 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): json_sample = { "result": { @@ -204,3 +381,19 @@ class Test_BMA_Blockchain(unittest.TestCase): } } 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 diff --git a/_ucoinpy_test/api/bma/test_network.py b/_ucoinpy_test/api/bma/test_network.py index bf524e1d596e1b3f64870f347584aa55bacafc5b..58e87c67f0903ae9ff57be66cd59f92a9ec83fe6 100644 --- a/_ucoinpy_test/api/bma/test_network.py +++ b/_ucoinpy_test/api/bma/test_network.py @@ -1,11 +1,12 @@ import unittest import jsonschema 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): json_sample = { "version": "1", @@ -20,6 +21,21 @@ class Test_BMA_Network(unittest.TestCase): } 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): json_sample = { @@ -45,4 +61,20 @@ class Test_BMA_Network(unittest.TestCase): "signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r" } } - jsonschema.validate(json_sample, Peers.schema) \ No newline at end of file + 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 diff --git a/_ucoinpy_test/api/bma/test_tx.py b/_ucoinpy_test/api/bma/test_tx.py index 8c33ea51d943a424ec59a2b6faca6876b984a5ee..0c61231165a383c205e8621ecb0047feffe5986d 100644 --- a/_ucoinpy_test/api/bma/test_tx.py +++ b/_ucoinpy_test/api/bma/test_tx.py @@ -1,10 +1,11 @@ import unittest import jsonschema 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 -class Test_BMA_TX(unittest.TestCase): +class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase): def test_bma_tx_history(self): json_sample = { "currency": "meta_brouzouf", @@ -119,6 +120,38 @@ class Test_BMA_TX(unittest.TestCase): jsonschema.validate(json_sample, History.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): json_sample = { "currency": "meta_brouzouf", @@ -140,4 +173,20 @@ class Test_BMA_TX(unittest.TestCase): } ] } - jsonschema.validate(json_sample, Sources.schema) \ No newline at end of file + 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 diff --git a/_ucoinpy_test/api/bma/test_wot.py b/_ucoinpy_test/api/bma/test_wot.py index 18db10f4df5fb99a7a451fe911a13d66a3aa6cd1..fd53026a05f54633f0ea5c076ab96bc6f7188f2a 100644 --- a/_ucoinpy_test/api/bma/test_wot.py +++ b/_ucoinpy_test/api/bma/test_wot.py @@ -1,9 +1,10 @@ import unittest import jsonschema +from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin, web, asyncio 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): json_sample = { "partial": False, @@ -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): json_sample = { @@ -77,6 +94,22 @@ class Test_BMA_Wot(unittest.TestCase): } 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): json_sample = { "pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY", @@ -101,3 +134,35 @@ class Test_BMA_Wot(unittest.TestCase): } jsonschema.validate(json_sample, CertifiersOf.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()) diff --git a/_ucoinpy_test/api/webserver.py b/_ucoinpy_test/api/webserver.py new file mode 100644 index 0000000000000000000000000000000000000000..3dd863479b89b7d85fd903113daa59c080d27c4d --- /dev/null +++ b/_ucoinpy_test/api/webserver.py @@ -0,0 +1,47 @@ +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 diff --git a/_ucoinpy_test/documents/test_transaction.py b/_ucoinpy_test/documents/test_transaction.py index 63d5e67fabc87e65d4ee9d69a1f772b08b603a8b..134e1c2f8081ab8bc24b12728efa96ecb1de1e6d 100644 --- a/_ucoinpy_test/documents/test_transaction.py +++ b/_ucoinpy_test/documents/test_transaction.py @@ -16,20 +16,19 @@ BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30 42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r """ -tx_raw = """Version: 1 -Type: Transaction -Currency: beta_brousouf -Issuers: -HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY -Inputs: -0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4 -0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15 -0:D:88:F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B:11 -Outputs: -BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30 -Comment: -42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r -""" +tx_raw = ("Version: 1\n" + "Type: Transaction\n" + "Currency: beta_brousouf\n" + "Issuers:\n" + "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY\n" + "Inputs:\n" + "0:T:65:D717FEC1993554F8EAE4CEA88DE5FBB6887CFAE8:4\n" + "0:T:77:F80993776FB55154A60B3E58910C942A347964AD:15\n" + "0:D:88:F4A47E39BC2A20EE69DCD5CAB0A9EB3C92FD8F7B:11\n" + "Outputs:\n" + "BYfWYFrsyjpvpFysgu19rGK3VHBkz4MqmQbNyEuVU64g:30\n" + "Comment: \n" + "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r\n") class Test_Transaction(unittest.TestCase): diff --git a/ucoinpy/__init__.py b/ucoinpy/__init__.py index a03bb353b4c035f628241c20a6f49feb1ed6c331..65b293bf3358f1e1f00e6e1124d9918481855e70 100644 --- a/ucoinpy/__init__.py +++ b/ucoinpy/__init__.py @@ -21,7 +21,7 @@ PROTOCOL_VERSION="1" MANAGED_API=["BASIC_MERKLED_API"] __author__ = 'Caner Candan & inso' -__version__ = '0.12.0' +__version__ = '0.12.1' __nonsense__ = 'uCoin' from . import api, documents, key \ No newline at end of file diff --git a/ucoinpy/api/bma/blockchain/__init__.py b/ucoinpy/api/bma/blockchain/__init__.py index 3fb1d0e444ddb1ba377b3af1e2c28dd0d16fde06..42fe958e8f61801d8570de7d5fa6a7368826423f 100644 --- a/ucoinpy/api/bma/blockchain/__init__.py +++ b/ucoinpy/api/bma/blockchain/__init__.py @@ -32,52 +32,54 @@ class Parameters(Blockchain): "type": "object", "properties": { - "currency": { - "type": "string" - }, - "c": { - "type": "number" - }, - "dt": { - "type": "number" - }, - "ud0": { - "type": "number" - }, - "sigDelay": { - "type": "number" - }, - "sigValidity": { - "type": "number" - }, - "sigQty": { - "type": "number" - }, - "sigWoT": { - "type": "number" - }, - "msValidity": { - "type": "number" - }, - "stepMax": { - "type": "number" - }, - "medianTimeBlocks": { - "type": "number" - }, - "avgGenTime": { - "type": "number" - }, - "dtDiffEval": { - "type": "number" - }, - "blocksRot": { - "type": "number" - }, - "percentRot": { - "type": "number" - }, - } + "currency": { + "type": "string" + }, + "c": { + "type": "number" + }, + "dt": { + "type": "number" + }, + "ud0": { + "type": "number" + }, + "sigDelay": { + "type": "number" + }, + "sigValidity": { + "type": "number" + }, + "sigQty": { + "type": "number" + }, + "sigWoT": { + "type": "number" + }, + "msValidity": { + "type": "number" + }, + "stepMax": { + "type": "number" + }, + "medianTimeBlocks": { + "type": "number" + }, + "avgGenTime": { + "type": "number" + }, + "dtDiffEval": { + "type": "number" + }, + "blocksRot": { + "type": "number" + }, + "percentRot": { + "type": "number" + }, + }, + "required": ["currency", "c", "dt", "ud0","sigDelay","sigValidity","sigQty","sigWoT","msValidity", + "stepMax", "medianTimeBlocks", "avgGenTime", "dtDiffEval", "blocksRot", "percentRot"] } def __get__(self, **kwargs): r = yield from self.requests_get('/parameters', **kwargs) @@ -120,9 +122,11 @@ class Membership(Blockchain): "type": "string" } }, + "required": ["version", "currency", "membership", "blockNumber", "blockHash"] } } - } + }, + "required": ["pubkey", "uid", "sigDate", "memberships"] } def __init__(self, connection_handler, search=None): @@ -159,7 +163,10 @@ class Block(Blockchain): "number": { "type": "number" }, - "timestamp": { + "time": { + "type": "number" + }, + "medianTime": { "type": "number" }, "dividend": { @@ -245,13 +252,17 @@ class Block(Blockchain): "type": "string" } } - } + }, + "required": ["signatures", "version", "currency", "issuers", "inputs", "outputs"] } }, "signature": { "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): @@ -300,7 +311,8 @@ class Hardship(Blockchain): "level": { "type": "number" } - } + }, + "required": ["block", "level"] } def __init__(self, connection_handler, fingerprint): @@ -327,13 +339,18 @@ class Newcomers(Blockchain): schema = { "type": "object", "properties": { - "block": { - "type": "number" - }, - "level": { - "type": "number" + "result":{ + "type": "object", + "properties": { + "blocks": { + "type": "array", + "item": "number" + }, + }, + "required": ["blocks"] } - } + }, + "required": ["result"] } def __get__(self, **kwargs): @@ -355,6 +372,7 @@ class Joiners(Blockchain): """GET, return block numbers containing joiners.""" schema = Newcomers.schema + def __get__(self, **kwargs): r = yield from self.requests_get('/with/joiners', **kwargs) return (yield from self.parse(r)) @@ -397,7 +415,7 @@ class UD(Blockchain): def __get__(self, **kwargs): r = yield from self.requests_get('/with/ud', **kwargs) - return (yield from r.json()) + return (yield from self.parse(r)) class TX(Blockchain): @@ -407,4 +425,4 @@ class TX(Blockchain): def __get__(self, **kwargs): r = yield from self.requests_get('/with/tx', **kwargs) - return (yield from r.json()) + return (yield from self.parse(r)) diff --git a/ucoinpy/api/bma/tx/__init__.py b/ucoinpy/api/bma/tx/__init__.py index eb21c9024fce331e4dce357ea5ef37800ac57959..fd844d0fb0062e96bc543495f37e51a05bf162c1 100644 --- a/ucoinpy/api/bma/tx/__init__.py +++ b/ucoinpy/api/bma/tx/__init__.py @@ -106,7 +106,8 @@ class History(Tx): "comment", "signatures", "hash", "block_number", "time"] } } - } + }, + "required": ["currency", "pubkey", "history"] } def __init__(self, conn_handler, pubkey, module='tx'): @@ -175,7 +176,7 @@ class Sources(Tx): def __get__(self, **kwargs): assert self.pubkey is not None 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 diff --git a/ucoinpy/api/bma/wot/__init__.py b/ucoinpy/api/bma/wot/__init__.py index ab80d0952dc38991f32b4a469dfd399805d746b0..b192825a2a5d8c6f87696941097773d7c0e78aae 100644 --- a/ucoinpy/api/bma/wot/__init__.py +++ b/ucoinpy/api/bma/wot/__init__.py @@ -148,7 +148,7 @@ class Lookup(WOT): assert self.search is not None 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): @@ -224,7 +224,7 @@ class CertifiersOf(WOT): assert self.search is not None 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): @@ -241,7 +241,7 @@ class CertifiedBy(WOT): assert self.search is not None 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): @@ -257,10 +257,12 @@ class Members(WOT): "pubkey": { "type": "string" } - } + }, + "required": ["pubkey"] } } - } + }, + "required": ["results"] } def __init__(self, connection_handler, module='wot'): @@ -268,4 +270,4 @@ class Members(WOT): def __get__(self, **kwargs): r = yield from self.requests_get('/members', **kwargs) - return (yield from r.json()) + return (yield from self.parse(r))