Skip to content

Commit 23a08a2

Browse files
committed
Fix schemas in websockets
1 parent c123d9b commit 23a08a2

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

_ucoinpy_test/api/bma/test_ws.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import unittest
2+
from _ucoinpy_test.api.webserver import WebFunctionalSetupMixin
3+
from ucoinpy.api.bma.ws import Block, Peer
4+
5+
6+
class Test_BMA_Websocket(WebFunctionalSetupMixin, unittest.TestCase):
7+
8+
def test_block_014(self):
9+
json_sample = """
10+
{
11+
"documentType":"block",
12+
"version":1,
13+
"currency":"meta_brouzouf",
14+
"nonce":567093,
15+
"number":49191,
16+
"parameters":"",
17+
"previousHash":"0000084665ABA60118B6D302C9A9BA4BCCA94852",
18+
"previousIssuer":"HBSSmqZjT4UQKsCntTSmZbu7iRP14HYtifLE6mW1PsBD",
19+
"issuer":"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
20+
"identities":[],"joiners":[],"actives":[],"leavers":[],"excluded":[],
21+
"membersCount":18,
22+
"certifications":[],
23+
"transactions":[],
24+
"powMin":5,
25+
"medianTime":1454058545,
26+
"time":1454072945,
27+
"signature":"Bk2lo/MAVgEwCr7pEopMs9DdN3TylwPH45MZg80h/V5IsuYwcVmPOstty6Z8XXqFCSfiCuYPUS7NhxGHOcnxDw==",
28+
"hash":"0000011D7A92E746F9B2D5B7035B98867F4A95A2",
29+
"fork":false,
30+
"monetaryMass":15431388469457603000,
31+
"dividend":0,
32+
"UDTime":1453979780,
33+
"wrong":false
34+
}
35+
"""
36+
block = Block(None)
37+
block.parse_text(json_sample)
38+
39+
def test_peer(self):
40+
json_sample = """{
41+
"version": "1",
42+
"currency": "beta_brouzouf",
43+
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
44+
"endpoints": [
45+
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9001",
46+
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9002",
47+
"OTHER_PROTOCOL 88.77.66.55 9001"
48+
],
49+
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
50+
}
51+
"""
52+
peer = Peer(None)
53+
data = peer.parse_text(json_sample)
54+
self.assertEqual(data["version"], "1")
55+
self.assertEqual(data["currency"], "beta_brouzouf")
56+
self.assertEqual(data["pubkey"], "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
57+
self.assertEqual(len(data["endpoints"]), 3)
58+
self.assertEqual(data["signature"], "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r")

ucoinpy/api/bma/ws/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,37 @@ class Block(Websocket):
3333
schema = _Block.schema
3434

3535
def connect(self):
36-
3736
r = self.connect_ws('/block')
3837
return r
3938

4039

4140
class Peer(Websocket):
4241
"""Connect to block websocket."""
43-
schema = _Peers.schema
42+
schema = {
43+
"type": "object",
44+
"properties": {
45+
"version": {
46+
"type": "string"
47+
},
48+
"currency": {
49+
"type": "string"
50+
},
51+
"pubkey": {
52+
"type": "string"
53+
},
54+
"endpoints": {
55+
"type": "array",
56+
"items": {
57+
"type": "string"
58+
}
59+
},
60+
"signature": {
61+
"type": "string"
62+
}
63+
},
64+
"required": ["version", "currency", "pubkey", "endpoints", "signature"]
65+
}
4466

4567
def connect(self):
46-
4768
r = self.connect_ws('/peer')
4869
return r
49-

0 commit comments

Comments
 (0)