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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
1aca28b1
Commit
1aca28b1
authored
3 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#187
: Implement __eq__ and __hash__ Certification’s methods
parent
bcc3cf45
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!167
#187: Implement __eq__ and __hash__ Documents methods
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/documents/certification.py
+26
-1
26 additions, 1 deletion
duniterpy/documents/certification.py
tests/documents/test_certification.py
+33
-4
33 additions, 4 deletions
tests/documents/test_certification.py
with
59 additions
and
5 deletions
duniterpy/documents/certification.py
+
26
−
1
View file @
1aca28b1
...
...
@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
re
from
typing
import
Optional
,
Type
,
TypeVar
,
Union
from
typing
import
Any
,
Optional
,
Type
,
TypeVar
,
Union
from
..constants
import
(
BLOCK_ID_REGEX
,
...
...
@@ -80,6 +80,31 @@ class Certification(Document):
if
signing_key
is
not
None
:
self
.
sign
(
signing_key
)
def
__eq__
(
self
,
other
:
Any
)
->
bool
:
"""
Check Certification instances equality
"""
if
not
isinstance
(
other
,
Certification
):
return
NotImplemented
return
(
super
().
__eq__
(
other
)
and
self
.
pubkey_from
==
other
.
pubkey_from
and
self
.
identity
==
other
.
identity
and
self
.
block_id
==
other
.
block_id
)
def
__hash__
(
self
)
->
int
:
return
hash
(
(
self
.
pubkey_from
,
self
.
identity
,
self
.
block_id
,
self
.
version
,
self
.
currency
,
self
.
signature
,
)
)
@classmethod
def
from_signed_raw
(
cls
:
Type
[
CertificationType
],
signed_raw
:
str
...
...
This diff is collapsed.
Click to expand it.
tests/documents/test_certification.py
+
33
−
4
View file @
1aca28b1
...
...
@@ -15,11 +15,16 @@
import
unittest
from
duniterpy.constants
import
EMPTY_HASH
import
pytest
from
duniterpy.constants
import
EMPTY_HASH
,
G1_TEST_CURRENCY_CODENAME
from
duniterpy.documents
import
Certification
,
Identity
,
Revocation
from
duniterpy.documents.block
import
BlockID
from
duniterpy.documents.certification
import
Certification
from
duniterpy.documents.identity
import
Identity
from
duniterpy.documents.revocation
import
Revocation
PUBKEY
=
"
A
"
UID
=
"
test
"
BLOCK_ID
=
"
0-NRSATU
"
IDENTITY_KWARGS
=
[
PUBKEY
,
UID
,
BLOCK_ID
]
selfcert_inlines
=
[
"
HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk:
\
...
...
@@ -223,3 +228,27 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN
revocation
=
Revocation
.
from_signed_raw
(
signed_raw
)
self
.
assertTrue
(
isinstance
(
Revocation
.
extract_self_cert
(
signed_raw
),
Identity
))
self
.
assertEqual
(
revocation
.
signed_raw
(),
signed_raw
)
def
test_certification_equality
():
cert1
=
Certification
(
PUBKEY
,
Identity
(
*
IDENTITY_KWARGS
),
BLOCK_ID
)
cert2
=
Certification
(
PUBKEY
,
Identity
(
*
IDENTITY_KWARGS
),
BLOCK_ID
)
assert
cert1
==
cert2
@pytest.mark.parametrize
(
"
pubkey, uid, block_id, currency
"
,
[
(
"
pubkey
"
,
UID
,
BLOCK_ID
,
None
),
(
PUBKEY
,
"
uid
"
,
BLOCK_ID
,
None
),
(
PUBKEY
,
UID
,
"
1-TEST
"
,
None
),
IDENTITY_KWARGS
+
[
G1_TEST_CURRENCY_CODENAME
],
],
)
def
test_certification_inequality
(
pubkey
,
uid
,
block_id
,
currency
):
cert1
=
Certification
(
pubkey
,
Identity
(
*
IDENTITY_KWARGS
),
block_id
)
idty2
=
Identity
(
pubkey
,
uid
,
block_id
)
cert2
=
Certification
(
pubkey
,
idty2
,
block_id
)
if
currency
:
cert2
.
currency
=
currency
assert
not
cert1
==
cert2
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