Commit 2d4839e2 authored by inso's avatar inso

Implement BMA data validation

parent bb11e85b
import unittest
import jsonschema
from ucoinpy.api.bma.blockchain import Parameters, Block, Current, Hardship, Membership, Newcomers, \
Certifications, Joiners, Actives, Leavers, UD, TX
class Test_BMA_Blockchain(unittest.TestCase):
def test_parameters(self):
json_sample = {
"currency": "meta_brouzouf",
"c": 0.1,
"dt": 86400,
"ud0": 100,
"sigDelay": 604800,
"sigValidity": 2629800,
"sigQty": 3,
"sigWoT": 3,
"msValidity": 2629800,
"stepMax": 3,
"medianTimeBlocks": 11,
"avgGenTime": 600,
"dtDiffEval": 20,
"blocksRot": 144,
"percentRot": 0.67
}
jsonschema.validate(json_sample, Parameters.schema)
def test_schema_block(self):
json_sample = {
"version": 1,
"nonce": 162294,
"number": 34435,
"powMin": 5,
"time": 1443895887,
"medianTime": 1443881487,
"membersCount": 19,
"monetaryMass": 154381656062153,
"currency": "meta_brouzouf",
"issuer": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
"signature": "VVr2MHcIAxIwjc2skkHqNAOgXVYEVhw4YczZ/NL5fsNZLnu9qvs04q8OUA4dfrDnsYB9I+BhVOAYNYDwNa6KDw==",
"hash": "000002B06C990DEBD5C1D947289C2CF4F4396FB2",
"parameters": "",
"previousHash": "00000D21F80687248A8C02F16BB19A975B4F983D",
"previousIssuer": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
"dividend": None,
"membersChanges": [],
"identities": [
"APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:Lld5KezKGDUgrvnNjKuEGZmWJZNYDYtsPJajuOdrEr7MKXIwJYBRTouWPlCoPP9OQBF7qi7dpX+qKeYcjVPPDA==:1443950660:Alcide"
],
"joiners": [
"APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:XpdVaX1TKnvjRfJRpFnpVDQOmxfDKKUp3YuSG/Ic8DHAT2SJKFSr+th3mK14JHiBtKMsNpVwFyV7TlKNHgnjAw==:34428:0000074D458E92EF09C2305BF0D191DD7CF1D452:1443950660:Alcide"
],
"actives": [],
"leavers": [],
"excluded": [],
"certifications": [
"ATkjQPa4sn4LBF69jqEPzFtRdHYJs6MJQjvP8JdN7MtN:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34434:oGGiYVBAfhreOzWS1M7HQ0OHHUWAA3NdU29XAca3/3mbfD581QBxeADVR+Bj7kTBqrAxwpwyODtaHyZZNYI3AA==",
"2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34432:KFKYioosI3FAvyfTKiWyQqRGUros03S/NITNxShB/3L1LI4P7XSLp2+hFbCK375ODm1g/fnwfzOoorOKPGIOAw==",
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34431:nKDTapgYR/nMEEkLaT4ygLCHlxmiACzi4Zv+gzRJN8hGdirQAMN1FNpJ2RVli4V4z+7y3lklPidOX2Aln8ZNBA=="
],
"transactions": [],
"raw": "Version: 1\nType: Block\nCurrency: meta_brouzouf\nNonce: 162294\nNumber: 34435\nPoWMin: 5\nTime: 1443895887\nMedianTime: 1443881487\nIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nPreviousHash: 00000D21F80687248A8C02F16BB19A975B4F983D\nPreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nMembersCount: 19\nIdentities:\nAPGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:Lld5KezKGDUgrvnNjKuEGZmWJZNYDYtsPJajuOdrEr7MKXIwJYBRTouWPlCoPP9OQBF7qi7dpX+qKeYcjVPPDA==:1443950660:Alcide\nJoiners:\nAPGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:XpdVaX1TKnvjRfJRpFnpVDQOmxfDKKUp3YuSG/Ic8DHAT2SJKFSr+th3mK14JHiBtKMsNpVwFyV7TlKNHgnjAw==:34428:0000074D458E92EF09C2305BF0D191DD7CF1D452:1443950660:Alcide\nActives:\nLeavers:\nExcluded:\nCertifications:\nATkjQPa4sn4LBF69jqEPzFtRdHYJs6MJQjvP8JdN7MtN:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34434:oGGiYVBAfhreOzWS1M7HQ0OHHUWAA3NdU29XAca3/3mbfD581QBxeADVR+Bj7kTBqrAxwpwyODtaHyZZNYI3AA==\n2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34432:KFKYioosI3FAvyfTKiWyQqRGUros03S/NITNxShB/3L1LI4P7XSLp2+hFbCK375ODm1g/fnwfzOoorOKPGIOAw==\n8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:APGtJqMq91jKxgGX9KEoCKqqD6UTsnPmALGNyaLbTknA:34431:nKDTapgYR/nMEEkLaT4ygLCHlxmiACzi4Zv+gzRJN8hGdirQAMN1FNpJ2RVli4V4z+7y3lklPidOX2Aln8ZNBA==\nTransactions:\n"
}
jsonschema.validate(json_sample, Block.schema)
jsonschema.validate(json_sample, Current.schema)
def test_schema_hardship(self):
json_sample = {
"block": 40432,
"level": 4
}
jsonschema.validate(json_sample, Hardship.schema)
def test_schema_membership(self):
json_sample = {
"pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU",
"uid": "inso",
"sigDate": 1421787800,
"memberships": [
{
"version": "1",
"currency": "meta_brouzouf",
"membership": "IN",
"blockNumber": 0,
"blockHash": "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"
},
{
"version": "1",
"currency": "meta_brouzouf",
"membership": "IN",
"blockNumber": 31658,
"blockHash": "0000C5336F0B64BFB87FF4BC858AE25726B88175"
},
]
}
jsonschema.validate(json_sample, Membership.schema)
def test_schema_newcomers(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, Newcomers.schema)
def test_schema_certifications(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, Certifications.schema)
def test_schema_joiners(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, Joiners.schema)
def test_schema_actives(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, Actives.schema)
def test_schema_leavers(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, Leavers.schema)
def test_schema_ud(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, UD.schema)
def test_schema_tx(self):
json_sample = {
"result": {
"blocks": [223, 813]
}
}
jsonschema.validate(json_sample, TX.schema)
import unittest
import jsonschema
from ucoinpy.api.bma.network import Peering
from ucoinpy.api.bma.network.peering import Peers, Status
class Test_BMA_Network(unittest.TestCase):
def test_peering(self):
json_sample = {
"version": "1",
"currency": "beta_brouzouf",
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"endpoints": [
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9001",
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9002",
"OTHER_PROTOCOL 88.77.66.55 9001",
],
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
}
jsonschema.validate(json_sample, Peering.schema)
def test_peers_root(self):
json_sample = {
"depth": 3,
"nodesCount": 6,
"leavesCount": 5,
"root": "114B6E61CB5BB93D862CA3C1DFA8B99E313E66E9"
}
jsonschema.validate(json_sample, Peers.schema)
def test_peers_leaf(self):
json_sample = {
"hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C",
"value": {
"version": "1",
"currency": "beta_brouzouf",
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"endpoints": [
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9001",
"BASIC_MERKLED_API some.dns.name 88.77.66.55 2001:0db8:0000:85a3:0000:0000:ac1f 9002",
"OTHER_PROTOCOL 88.77.66.55 9001",
],
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
}
}
jsonschema.validate(json_sample, Peers.schema)
\ No newline at end of file
import unittest
import jsonschema
from ucoinpy.api.bma.tx import History, Sources
from ucoinpy.api.bma.tx.history import Blocks
class Test_BMA_TX(unittest.TestCase):
def test_bma_tx_history(self):
json_sample = {
"currency": "meta_brouzouf",
"pubkey": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
"history": {
"sent": [
{
"version": 1,
"issuers": [
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
],
"inputs": [
"0:D:125:000A8362AE0C1B8045569CE07735DE4C18E81586:100"
],
"outputs": [
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:5",
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:95"
],
"comment": "Essai",
"signatures": [
"8zzWSU+GNSNURnH1NKPT/TBoxngEc/0wcpPSbs7FqknGxud+94knvT+dpe99k6NwyB5RXvOVnKAr4p9/KEluCw=="
],
"hash": "FC7BAC2D94AC9C16AFC5C0150C2C9E7FBB2E2A09",
"block_number": 173,
"time": 1421932545
}
],
"received": [
{
"version": 1,
"issuers": [
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU"
],
"inputs": [
"0:D:125:000A8362AE0C1B8045569CE07735DE4C18E81586:100"
],
"outputs": [
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:7",
"8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU:93"
],
"comment": "",
"signatures": [
"1Mn8q3K7N+R4GZEpAUm+XSyty1Uu+BuOy5t7BIRqgZcKqiaxfhAUfDBOcuk2i4TJy1oA5Rntby8hDN+cUCpvDg=="
],
"hash": "5FB3CB80A982E2BDFBB3EA94673A74763F58CB2A",
"block_number": 207,
"time": 1421955525
},
{
"version": 1,
"issuers": [
"J78bPUvLjxmjaEkdjxWLeENQtcfXm7iobqB49uT1Bgp3"
],
"inputs": [
"0:T:15128:6A50FF82410387B239489CE38B34E0FDDE1697FE:10000"
],
"outputs": [
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:42",
"J78bPUvLjxmjaEkdjxWLeENQtcfXm7iobqB49uT1Bgp3:9958"
],
"comment": "",
"signatures": [
"XhBcCPizPiWdKeXWg1DX/FTQst6DppEjsYEtoAZNA0P11reXtgc9IduiIxNWzNjt/KvTw8APkSI8/Uf31QQVDA=="
],
"hash": "ADE7D1C4002D6BC10013C34CE22733A55173BAD4",
"block_number": 15778,
"time": 1432314584
}
],
"sending": [
{
"version": 1,
"issuers": [
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
],
"inputs": [
"0:D:8196:000022AD426FE727C707D847EC2168A64C577706:5872"
],
"outputs": [
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:5871"
"2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX:1",
],
"comment": "some comment",
"signatures": [
"kLOAAy7/UldQk7zz4I7Jhv9ICuGYRx7upl8wH8RYL43MMF6+7MbPh3QRN1qNFGpAfa3XMWIQmbUWtjZKP6OfDA=="
],
"hash": "BA41013F2CD38EDFFA9D38A275F8532DD906A2DE"
}
],
"receiving": [
{
"version": 1,
"issuers": [
"2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX"
],
"inputs": [
"0:D:8196:000022AD426FE727C707D847EC2168A64C577706:4334"
],
"outputs": [
"2sq8bBDQGK74f1eD3mAPQVgHCmFdijZr9nbv16FwbokX:1",
"HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:4333"
],
"comment": "some comment",
"signatures": [
"DRiZinUEKrrLiJNogtydzwEbmETrvWiLNYXCiJsRekxTLyU5g4LjnwiLp/XlvmIekjJK5n/gullLWrHUBvFSAw=="
],
"hash": "A0A511131CD0E837204A9441B3354918AC4CE671"
}
]
}
}
jsonschema.validate(json_sample, History.schema)
jsonschema.validate(json_sample, Blocks.schema)
def test_bma_tx_sources(self):
json_sample = {
"currency": "meta_brouzouf",
"pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU",
"sources": [
{
"pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU",
"type": "T",
"number": 34444,
"fingerprint": "6ACECB199D1B054B2633D0E42C066939B7F8EF1D",
"amount": 1000000
},
{
"pubkey": "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU",
"type": "D",
"number": 34989,
"fingerprint": "0007CCC9755067008C28E791E6F2B0D4CBE9B894",
"amount": 1730543585843
}
]
}
jsonschema.validate(json_sample, Sources.schema)
\ No newline at end of file
import unittest
import jsonschema
from ucoinpy.api.bma.wot import Lookup, Members, CertifiedBy, CertifiersOf
class Test_BMA_Wot(unittest.TestCase):
def test_bma_wot_lookup(self):
json_sample = {
"partial": False,
"results": [
{
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"uids": [
{
"uid": "udid2;c;TOCQUEVILLE;FRANCOIS-XAVIER-ROBE;1989-07-14;e+48.84+002.30;0;",
"meta": {
"timestamp": 1409990782
},
"self": "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci",
"others": [
{
"pubkey": "9WYHTavL1pmhunFCzUwiiq4pXwvgGG5ysjZnjz9H8yB",
"meta": {
"timestamp": 1509991044
},
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
}
]
}
],
"signed": [
{
"uid": "snow",
"pubkey": "2P7y2UDiCcvsgSSt8sgHF3BPKS4m9waqKw4yXHCuP6CN",
"meta": {
"timestamp": 1509992000
},
"signature": "Xbr7qhyGNCmLoVuuKnKIbrdmtCvb9VBIEY19izUNwA5nufsjNm8iEsBTwKWOo0lq5O1+AAPMnht8cm2JjMq8AQ=="
},
{
"uid": "snow",
"pubkey": "2P7y2UDiCcvsgSSt8sgHF3BPKS4m9waqKw4yXHCuP6CN",
"meta": {
"timestamp": 1509992006
},
"signature": "HU9VPwC4EqPJwATPuyUJM7HLjfig5Ke1CKonL9Q78n5/uNSL2hkgE9Pxsor8CCJfkwCxh66NjGyqnGYqZnQMAg=="
},
{
"uid": "snow",
"pubkey": "7xapQvvxQ6367bs8DsskEf3nvQAgJv97Yu11aPbkCLQj",
"meta": {
"timestamp": 1609994000
},
"signature": "6S3x3NwiHB2QqYEY79x4wCUYHcDctbazfxIyxejs38V1uRAl4DuC8R3HJUfD6wMSiWKPqbO+td+8ZMuIn0L8AA=="
},
{
"uid": "cat",
"pubkey": "CK2hBp25sYQhdBf9oFMGHyokkmYFfzSCmwio27jYWAN7",
"meta": {
"timestamp": 1422890632
},
"signature": "AhgblSOdxUkLwpUN9Ec46St3JGaw2jPyDn/mLcR4j3EjKxUOwHBYqqkxcQdRz/6K4Qo/xMa941MgUp6NjNbKBA=="
}
]
}
]
}
jsonschema.validate(Lookup.schema, json_sample)
def test_bma_wot_members(self):
json_sample = {
"results": [
{"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY", "uid": "cat"},
{"pubkey": "9kNEiyseUNoPn3pmNUhWpvCCwPRgavsLu7YFKZuzzd1L", "uid": "tac"},
{"pubkey": "9HJ9VXa9wc6EKC6NkCi8b5TKWBot68VhYDg7kDk5T8Cz", "uid": "toc"}
]
}
jsonschema.validate(Members.schema, json_sample)
def test_bma_wot_cert(self):
json_sample = {
"pubkey": "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY",
"uid": "user identifier",
"isMember": True,
"certifications": [
{
"pubkey": "9WYHTavL1pmhunFCzUwiiq4pXwvgGG5ysjZnjz9H8yB",
"uid": "certifier uid",
"cert_time": {
"block": 88,
"medianTime": 1509991044
},
"written": {
"number": 872768,
"hash": "D30978C9D6C5A348A8188603F039423D90E50DC5"
},
"isMember": True,
"signature": "42yQm4hGTJYWkPg39hQAUgP6S6EQ4vTfXdJuxKEHL1ih6YHiDL2hcwrFgBHjXLRgxRhj2VNVqqc6b4JayKqTE14r"
}
]
}
jsonschema.validate(json_sample, CertifiersOf.schema)
jsonschema.validate(json_sample, CertifiedBy.schema)
This diff is collapsed.
......@@ -29,31 +29,31 @@ class Test_SelfCertification(unittest.TestCase):
version = 1
currency = "zeta_brousouf"
selfcert = SelfCertification.from_inline(version, currency, selfcert_inlines[0])
self.assertEquals(selfcert.pubkey, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEquals(selfcert.signatures[0], "h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==")
self.assertEquals(selfcert.timestamp, 1416335620)
self.assertEquals(selfcert.uid, "cgeek")
self.assertEqual(selfcert.pubkey, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(selfcert.signatures[0], "h/H8tDIEbfA4yxMQcvfOXVDQhi1sUa9qYtPKrM59Bulv97ouwbAvAsEkC1Uyit1IOpeAV+CQQs4IaAyjE8F1Cw==")
self.assertEqual(selfcert.timestamp, 1416335620)
self.assertEqual(selfcert.uid, "cgeek")
selfcert = SelfCertification.from_inline(version, currency, selfcert_inlines[1])
self.assertEquals(selfcert.pubkey, "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS")
self.assertEquals(selfcert.signatures[0], "Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==")
self.assertEquals(selfcert.timestamp, 1416428323)
self.assertEquals(selfcert.uid, "vit")
self.assertEqual(selfcert.pubkey, "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS")
self.assertEqual(selfcert.signatures[0], "Ah55O8cvdkGS4at6AGOKUjy+wrFwAq8iKRJ5xLIb6Xdi3M8WfGOUdMjwZA6GlSkdtlMgEhQPm+r2PMebxKrCBg==")
self.assertEqual(selfcert.timestamp, 1416428323)
self.assertEqual(selfcert.uid, "vit")
def test_certifications(self):
version = 1
currency = "zeta_brousouf"
blockhash = "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"
cert = Certification.from_inline(version, currency, blockhash, cert_inlines[0])
self.assertEquals(cert.pubkey_from, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEquals(cert.pubkey_to, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEquals(cert.blocknumber, 0)
self.assertEquals(cert.blockhash, blockhash)
self.assertEquals(cert.signatures[0], "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
self.assertEqual(cert.pubkey_from, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(cert.pubkey_to, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(cert.blocknumber, 0)
self.assertEqual(cert.blockhash, blockhash)
self.assertEqual(cert.signatures[0], "TgmDuMxZdyutroj9jiLJA8tQp/389JIzDKuxW5+h7GIfjDu1ZbwI7HNm5rlUDhR2KreaV/QJjEaItT4Cf75rCQ==")
cert = Certification.from_inline(version, currency, blockhash, cert_inlines[1])
self.assertEquals(cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y")
self.assertEquals(cert.pubkey_to, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEquals(cert.blocknumber, 0)
self.assertEquals(cert.blockhash, blockhash)
self.assertEquals(cert.signatures[0], "qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==")
self.assertEqual(cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y")
self.assertEqual(cert.pubkey_to, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(cert.blocknumber, 0)
self.assertEqual(cert.blockhash, blockhash)
self.assertEqual(cert.signatures[0], "qn/XNJjaGIwfnR+wGrDME6YviCQbG+ywsQWnETlAsL6q7o3k1UhpR5ZTVY9dvejLKuC+1mUEXVTmH+8Ib55DBA==")
......@@ -25,34 +25,34 @@ dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu8
class Test_Membership(unittest.TestCase):
def test_frominline(self):
membership = Membership.from_inline(1, "zeta_brousouf", 'IN', membership_inline)
self.assertEquals(membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEquals(membership.block_number, 0)
self.assertEquals(membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEquals(membership.cert_ts, 1416335620)
self.assertEquals(membership.uid, "cgeek")
self.assertEquals(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEquals(membership.membership_type, 'IN')
self.assertEqual(membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(membership.block_number, 0)
self.assertEqual(membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(membership.cert_ts, 1416335620)
self.assertEqual(membership.uid, "cgeek")
self.assertEqual(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.membership_type, 'IN')
def test_fromraw(self):
membership = Membership.from_signed_raw(membership_raw)
self.assertEquals(membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEquals(membership.block_number, 0)
self.assertEquals(membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEquals(membership.cert_ts, 1416335620)
self.assertEquals(membership.uid, "cgeek")
self.assertEquals(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEquals(membership.membership_type, 'IN')
self.assertEqual(membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(membership.block_number, 0)
self.assertEqual(membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(membership.cert_ts, 1416335620)
self.assertEqual(membership.uid, "cgeek")
self.assertEqual(membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(membership.membership_type, 'IN')
def test_fromraw_toraw(self):
membership = Membership.from_signed_raw(membership_raw)
rendered_membership = membership.signed_raw()
from_rendered_membership = Membership.from_signed_raw(rendered_membership)
self.assertEquals(from_rendered_membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEquals(from_rendered_membership.block_number, 0)
self.assertEquals(from_rendered_membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEquals(from_rendered_membership.cert_ts, 1416335620)
self.assertEquals(from_rendered_membership.uid, "cgeek")
self.assertEquals(from_rendered_membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEquals(from_rendered_membership.membership_type, 'IN')
self.assertEqual(from_rendered_membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
self.assertEqual(from_rendered_membership.block_number, 0)
self.assertEqual(from_rendered_membership.block_hash, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709")
self.assertEqual(from_rendered_membership.cert_ts, 1416335620)
self.assertEqual(from_rendered_membership.uid, "cgeek")
self.assertEqual(from_rendered_membership.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(from_rendered_membership.membership_type, 'IN')
......@@ -23,49 +23,49 @@ dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu8
class TestPeer(unittest.TestCase):
def test_fromraw(self):
peer = Peer.from_signed_raw(rawpeer)
self.assertEquals(peer.currency, "beta_brousouf")
self.assertEquals(peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEquals(peer.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEquals(len(peer.endpoints), 3)
self.assertEqual(peer.currency, "beta_brousouf")
self.assertEqual(peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEqual(peer.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEqual(len(peer.endpoints), 3)
self.assertTrue(type(peer.endpoints[0]) is BMAEndpoint)
self.assertTrue(type(peer.endpoints[1]) is BMAEndpoint)
self.assertTrue(type(peer.endpoints[2]) is UnknownEndpoint)
self.assertEquals(peer.endpoints[0].server, "some.dns.name")
self.assertEquals(peer.endpoints[0].ipv4, "88.77.66.55")
self.assertEquals(peer.endpoints[0].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEquals(peer.endpoints[0].port, 9001)
self.assertEqual(peer.endpoints[0].server, "some.dns.name")
self.assertEqual(peer.endpoints[0].ipv4, "88.77.66.55")
self.assertEqual(peer.endpoints[0].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEqual(peer.endpoints[0].port, 9001)
self.assertEquals(peer.endpoints[1].server, "some.dns.name")
self.assertEquals(peer.endpoints[1].ipv4, "88.77.66.55")
self.assertEquals(peer.endpoints[1].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEquals(peer.endpoints[1].port, 9002)
self.assertEqual(peer.endpoints[1].server, "some.dns.name")
self.assertEqual(peer.endpoints[1].ipv4, "88.77.66.55")
self.assertEqual(peer.endpoints[1].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEqual(peer.endpoints[1].port, 9002)
self.assertEquals(peer.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(peer.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
def test_fromraw_toraw(self):
peer = Peer.from_signed_raw(rawpeer)
rendered_peer = peer.signed_raw()
from_rendered_peer = Peer.from_signed_raw(rendered_peer)
self.assertEquals(from_rendered_peer.currency, "beta_brousouf")
self.assertEquals(from_rendered_peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEquals(from_rendered_peer.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEquals(len(from_rendered_peer.endpoints), 3)
self.assertEqual(from_rendered_peer.currency, "beta_brousouf")
self.assertEqual(from_rendered_peer.pubkey, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEqual(from_rendered_peer.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEqual(len(from_rendered_peer.endpoints), 3)
self.assertTrue(type(from_rendered_peer.endpoints[0]) is BMAEndpoint)
self.assertTrue(type(from_rendered_peer.endpoints[1]) is BMAEndpoint)
self.assertTrue(type(from_rendered_peer.endpoints[2]) is UnknownEndpoint)
self.assertEquals(from_rendered_peer.endpoints[0].server, "some.dns.name")
self.assertEquals(from_rendered_peer.endpoints[0].ipv4, "88.77.66.55")
self.assertEquals(from_rendered_peer.endpoints[0].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEquals(from_rendered_peer.endpoints[0].port, 9001)
self.assertEqual(from_rendered_peer.endpoints[0].server, "some.dns.name")
self.assertEqual(from_rendered_peer.endpoints[0].ipv4, "88.77.66.55")
self.assertEqual(from_rendered_peer.endpoints[0].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEqual(from_rendered_peer.endpoints[0].port, 9001)
self.assertEquals(from_rendered_peer.endpoints[1].server, "some.dns.name")
self.assertEquals(from_rendered_peer.endpoints[1].ipv4, "88.77.66.55")
self.assertEquals(from_rendered_peer.endpoints[1].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEquals(from_rendered_peer.endpoints[1].port, 9002)
self.assertEqual(from_rendered_peer.endpoints[1].server, "some.dns.name")
self.assertEqual(from_rendered_peer.endpoints[1].ipv4, "88.77.66.55")
self.assertEqual(from_rendered_peer.endpoints[1].ipv6, "2001:0db8:0000:85a3:0000:0000:ac1f")
self.assertEqual(from_rendered_peer.endpoints[1].port, 9002)
self.assertEquals(from_rendered_peer.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(from_rendered_peer.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
......@@ -20,19 +20,19 @@ dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu8
class Test_Status(unittest.TestCase):
def test_fromraw(self):
status = Status.from_signed_raw(raw_status)
self.assertEquals(status.status, 'UP')
self.assertEquals(status.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEquals(status.sender, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEquals(status.recipient, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEquals(status.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(status.status, 'UP')
self.assertEqual(status.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEqual(status.sender, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEqual(status.recipient, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(status.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
def test_fromraw_toraw(self):
status = Status.from_signed_raw(raw_status)
rendered_status = status.signed_raw()
from_rendered_status = Status.from_signed_raw(rendered_status)
self.assertEquals(from_rendered_status.status, 'UP')
self.assertEquals(from_rendered_status.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEquals(from_rendered_status.sender, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEquals(from_rendered_status.recipient, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEquals(from_rendered_status.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
self.assertEqual(from_rendered_status.status, 'UP')
self.assertEqual(from_rendered_status.blockid, "8-1922C324ABC4AF7EF7656734A31F5197888DDD52")
self.assertEqual(from_rendered_status.sender, "HsLShAtzXTVxeUtQd7yi5Z5Zh4zNvbu8sTEZ53nfKcqY")
self.assertEqual(from_rendered_status.recipient, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.assertEqual(from_rendered_status.signatures[0], "dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu84rraDg==")
This diff is collapsed.
......@@ -2,4 +2,5 @@ asyncio
aiohttp
pylibscrypt
libnacl
base58
\ No newline at end of file
base58
jsonschema
\ No newline at end of file
......@@ -21,7 +21,7 @@ __all__ = ['api']
PROTOCOL_VERSION = "1"
import aiohttp, asyncio, logging, json
import aiohttp, asyncio, logging, jsonschema
logger = logging.getLogger("ucoin")
......@@ -96,6 +96,21 @@ class API(object):
"""interface purpose for POST request"""