Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
beca40de
Commit
beca40de
authored
8 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fix blockUID
parent
28621a15
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/documents/block.py
+10
-2
10 additions, 2 deletions
duniterpy/documents/block.py
tests/documents/test_block.py
+31
-0
31 additions, 0 deletions
tests/documents/test_block.py
with
41 additions
and
2 deletions
duniterpy/documents/block.py
+
10
−
2
View file @
beca40de
...
@@ -5,6 +5,7 @@ from .transaction import Transaction
...
@@ -5,6 +5,7 @@ from .transaction import Transaction
from
.constants
import
pubkey_regex
,
block_id_regex
,
block_hash_regex
from
.constants
import
pubkey_regex
,
block_id_regex
,
block_hash_regex
import
re
import
re
import
hashlib
def
block_uid
(
value
):
def
block_uid
(
value
):
...
@@ -255,7 +256,7 @@ The class Block handles Block documents.
...
@@ -255,7 +256,7 @@ The class Block handles Block documents.
@property
@property
def
blockUID
(
self
):
def
blockUID
(
self
):
return
BlockUID
(
self
.
number
,
self
.
sha_hash
)
return
BlockUID
(
self
.
number
,
self
.
proof_of_work
()
)
@classmethod
@classmethod
def
from_signed_raw
(
cls
,
signed_raw
):
def
from_signed_raw
(
cls
,
signed_raw
):
...
@@ -502,3 +503,10 @@ PreviousIssuer: {1}\n".format(self.prev_hash, self.prev_issuer)
...
@@ -502,3 +503,10 @@ PreviousIssuer: {1}\n".format(self.prev_hash, self.prev_issuer)
doc
+=
"
Nonce: {0}
\n
"
.
format
(
self
.
noonce
)
doc
+=
"
Nonce: {0}
\n
"
.
format
(
self
.
noonce
)
return
doc
return
doc
def
proof_of_work
(
self
):
doc_str
=
"""
InnerHash: {inner_hash}
Nonce: {nonce}
{signature}
"""
.
format
(
inner_hash
=
self
.
inner_hash
,
nonce
=
self
.
noonce
,
signature
=
self
.
signatures
[
0
])
return
hashlib
.
sha256
(
doc_str
.
encode
(
'
ascii
'
)).
hexdigest
().
upper
()
This diff is collapsed.
Click to expand it.
tests/documents/test_block.py
+
31
−
0
View file @
beca40de
...
@@ -539,6 +539,37 @@ class Test_Block(unittest.TestCase):
...
@@ -539,6 +539,37 @@ class Test_Block(unittest.TestCase):
elif
BlockUID
.
empty
():
elif
BlockUID
.
empty
():
self
.
fail
(
"
Empty blockuid __nonzero__ comparison failed
"
)
self
.
fail
(
"
Empty blockuid __nonzero__ comparison failed
"
)
def
test_proof_of_work
(
self
):
block
=
"""
Version: 5
Type: Block
Currency: test_net
Number: 60803
PoWMin: 80
Time: 1480979125
MedianTime: 1480975879
UnitBase: 7
Issuer: 9bZEATXBGPUSsk8oAYi4KAChg3rHKwNt67hVdErbNGCW
IssuersFrame: 120
IssuersFrameVar: 0
DifferentIssuersCount: 18
PreviousHash: 0000083FB6E3435ADCDF0F86B0A1BCA108B6B47D4B4BA61D0B4FDC21A262CF4C
PreviousIssuer: BnSRjMjJ7gWy13asCRz9rQ6G5Njytdf3pvR1GMkJgtu6
MembersCount: 187
Identities:
Joiners:
Actives:
Leavers:
Revoked:
Excluded:
Certifications:
Transactions:
InnerHash: 310F57575EA865EF47BFA236108B2B1CAEBFBF8EF70960E32E214E413E9C836B
Nonce: 10200000037440
AywstQpC0S5iaA/YQvbz2alpP6zTYG3tjkWpxy1jgeCo028Te2V327bBZbfDGDzsjxOrF4UVmEBiGsgbqhL9CA==
"""
block_doc
=
Block
.
from_signed_raw
(
block
)
self
.
assertEqual
(
block_doc
.
proof_of_work
(),
"
00000A84839226046082E2B1AD49664E382D98C845644945D133D4A90408813A
"
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
unittest
.
main
()
unittest
.
main
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment