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

First unit test + fixes in block.py

parent ec986adb
No related branches found
No related tags found
No related merge requests found
'''
Created on 12 déc. 2014
@author: inso
'''
import pytest
from ucoinpy.documents.block import Block
from mock import Mock
raw_block = "Version: 1\nType: \
Block\nCurrency: zeta_brouzouf\n\
Nonce: 45079\nNumber: 15\nPoWMin: 4\n\
Time: 1418083330\nMedianTime: 1418080208\n\
Issuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\n\
PreviousHash: 0000E73C340601ACA1AD5AAA5B5E56B03E178EF8\n\
PreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\n\
MembersCount: 4\nIdentities:\nJoiners:\nActives:\nLeavers:\n\
Excluded:\nCertifications:\nTransactions:\n"
class Test_Block:
def test_fromraw(self):
block = Block.from_raw(raw_block)
assert block.version == 1
assert block.currency == "zeta_brouzouf"
assert block.noonce == 45079
assert block.number == 15
assert block.powmin == 4
assert block.time == 1418083330
assert block.mediantime == 1418080208
assert block.issuer == "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
assert block.previoushash == "0000E73C340601ACA1AD5AAA5B5E56B03E178EF8"
assert block.previousissuer == "0000E73C340601ACA1AD5AAA5B5E56B03E178EF8"
assert block.memberscount == 4
assert block.identities == []
assert block.joiners == []
assert block.actives == []
assert block.leavers == []
assert block.excluded == []
assert block.certifications == []
assert block.transactions == []
'''
Created on 6 déc. 2014
@author: inso
'''
import pytest
from ucoinpy.documents.certification import SelfCertification
from ucoinpy.key import Base58Encoder
from mock import Mock
from nacl.signing import SigningKey
uid = "lolcat"
timestamp = 1409990782.24
correct_certification = """UID:lolcat
META:TS:1409990782
J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci
"""
key = SigningKey()
class Test_SelfCertification:
'''
classdocs
'''
def test_certification(self):
cert = SelfCertification(timestamp, uid)
assert cert.signed(key) == correct_certification
......@@ -53,7 +53,7 @@ COMPACT_TRANSACTION
BOTTOM_SIGNATURE
'''
re_currency = re.compile("Currency: ([0-9a-zA-Z_\-]+)\n")
re_type = re.compile("Type: (Block)\n")
re_noonce = re.compile("Nonce: ([0-9]+)\n")
re_number = re.compile("Number: ([0-9]+)\n")
re_powmin = re.compile("PoWMin: ([0-9]+)\n")
......@@ -111,46 +111,49 @@ BOTTOM_SIGNATURE
n = 0
version = Block.RE_VERSION.match(lines[n])
n = 1
version = Block.re_version.match(lines[n]).group(1)
n = n + 1
currency = Block.re_currency.match(lines[n])
n = 2
type = Block.re_type.match(lines[n]).group(1)
n = n + 1
noonce = int(Block.re_noonce.match(lines[n]))
n = 3
currency = Block.re_currency.match(lines[n]).group(1)
n = n + 1
number = int(Block.re_number.match(lines[n]))
n = 4
noonce = int(Block.re_noonce.match(lines[n])).group(1)
n = n + 1
powmin = int(Block.re_powmin.match(lines[n]))
n = 5
number = int(Block.re_number.match(lines[n])).group(1)
n = n + 1
time = int(Block.re_time.match(lines[n]))
n = 6
powmin = int(Block.re_powmin.match(lines[n])).group(1)
n = n + 1
time = int(Block.re_time.match(lines[n])).group(1)
n = n + 1
mediantime = int(Block.re_mediantime.match(lines[n]))
n = 7
mediantime = int(Block.re_mediantime.match(lines[n])).group(1)
n = n + 1
ud = Block.re_universaldividend.match(lines[n])
ud = Block.re_universaldividend.match(lines[n]).group(1)
if ud is not None:
ud = int(ud)
n = n + 1
issuer = Block.re_issuer.match(lines[n])
issuer = Block.re_issuer.match(lines[n]).group(1)
n = n + 1
prev_hash = Block.re_previoushash.match(lines[n])
prev_hash = Block.re_previoushash.match(lines[n]).group(1)
n = n + 1()
prev_issuer = Block.re_previousissuer.match(lines[n])
prev_issuer = Block.re_previousissuer.match(lines[n]).group(1)
n = n + 1
if number == 0:
parameters = Block.re_parameters.match(lines[n])
parameters = Block.re_parameters.match(lines[n]).group(1)
n = n + 1
members_count = int(Block.re_memberscount.match(lines[n]))
members_count = int(Block.re_memberscount.match(lines[n])).group(1)
n = n + 1
identities = []
......@@ -169,25 +172,25 @@ BOTTOM_SIGNATURE
if Block.re_joiners.match(lines[n]) is not None:
while Block.re_actives.match(lines[n]) is None:
membership = Membership.from_inline(version, lines[n])
membership = Membership.from_inline(version, currency, "IN", lines[n])
joiners.append(membership)
lines = lines + 1
if Block.re_actives.match(lines[n]) is not None:
while Block.re_leavers.match(lines[n]) is None:
membership = Membership.from_inline(version, lines[n])
membership = Membership.from_inline(version, currency, "IN", lines[n])
actives.append(membership)
lines = lines + 1
if Block.re_leavers.match(lines[n]) is not None:
while Block.re_excluded.match(lines[n]) is None:
membership = Membership.from_inline(version, lines[n])
membership = Membership.from_inline(version, currency, "OUT", lines[n])
leavers.append(membership)
lines = lines + 1
if Block.re_excluded.match(lines[n]) is not None:
while Block.re_certifications.match(lines[n]) is None:
membership = Membership.from_inline(version, lines[n])
membership = Membership.from_inline(version, currency, "OUT", lines[n])
excluded.append(membership)
lines = lines + 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment