From f3d7145dd3ca029c82a9d8dc7f5730a97b4f5d07 Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Fri, 18 Jun 2021 10:31:47 +0200 Subject: [PATCH] [enh] #172 refactor subclass version argument as optional with default=subclass.VERSION Break backward compatibility argument is Optional[Int] with default=subclass.VERSION --- duniterpy/documents/block.py | 34 ++++++++++++++------------- duniterpy/documents/certification.py | 16 ++++++++----- duniterpy/documents/identity.py | 23 +++++++++--------- duniterpy/documents/membership.py | 14 ++++++----- duniterpy/documents/peer.py | 10 ++++---- duniterpy/documents/revocation.py | 15 ++++++------ duniterpy/documents/transaction.py | 15 +++++++----- examples/save_revoke_document.py | 8 ++----- examples/send_certification.py | 7 +----- examples/send_identity.py | 1 - examples/send_membership.py | 1 - examples/send_transaction.py | 5 ---- tests/api/ws2p/test_ws2p.py | 2 +- tests/documents/test_certification.py | 20 ++++++++-------- tests/documents/test_membership.py | 2 +- tests/documents/test_transaction.py | 2 -- 16 files changed, 86 insertions(+), 89 deletions(-) diff --git a/duniterpy/documents/block.py b/duniterpy/documents/block.py index 2efc7cff..7b41e1b3 100644 --- a/duniterpy/documents/block.py +++ b/duniterpy/documents/block.py @@ -32,6 +32,8 @@ from .transaction import Transaction BlockType = TypeVar("BlockType", bound="Block") +VERSION = 12 + class Block(Document): """ @@ -150,7 +152,6 @@ class Block(Document): def __init__( self, - version: int, currency: str, number: int, powmin: int, @@ -177,11 +178,11 @@ class Block(Document): inner_hash: str, nonce: int, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Constructor - :param version: duniter protocol version :param currency: the block currency :param number: the number of the block :param powmin: the powmin value of this block @@ -208,6 +209,7 @@ class Block(Document): :param inner_hash: the block hash :param nonce: the nonce value of the block :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=block.VERSION) """ super().__init__(version, currency) @@ -274,7 +276,6 @@ class Block(Document): version = b["version"] currency = b["currency"] arguments = { # arguments used to create block - "version": b["version"], "currency": b["currency"], "number": b["number"], "powmin": b["powMin"], @@ -300,39 +301,40 @@ class Block(Document): "transactions": b["transactions"], "inner_hash": b["inner_hash"], "nonce": b["nonce"], + "version": b["version"], } # parameters: Optional[Sequence[str]] if arguments["parameters"]: arguments["parameters"] = arguments["parameters"].split(":") # identities: List[Identity] arguments["identities"] = [ - Identity.from_inline(version, currency, i + "\n") + Identity.from_inline(currency, i + "\n", version) for i in arguments["identities"] ] # joiners: List[Membership] arguments["joiners"] = [ - Membership.from_inline(version, currency, "IN", i + "\n") + Membership.from_inline(currency, "IN", i + "\n", version) for i in arguments["joiners"] ] # actives: List[Membership] arguments["actives"] = [ - Membership.from_inline(version, currency, "IN", i + "\n") + Membership.from_inline(currency, "IN", i + "\n", version) for i in arguments["actives"] ] # leavers: List[Membership] arguments["leavers"] = [ - Membership.from_inline(version, currency, "OUT", i + "\n") + Membership.from_inline(currency, "OUT", i + "\n", version) for i in arguments["leavers"] ] # revokations: List[Revocation] arguments["revokations"] = [ - Revocation.from_inline(version, currency, i + "\n") + Revocation.from_inline(currency, i + "\n", version) for i in arguments["revokations"] ] # certifications: List[Certification] arguments["certifications"] = [ Certification.from_inline( - version, currency, arguments["inner_hash"], i + "\n" + currency, arguments["inner_hash"], i + "\n", version ) for i in arguments["certifications"] ] @@ -435,35 +437,35 @@ class Block(Document): if Block.re_identities.match(lines[n]) is not None: n += 1 while Block.re_joiners.match(lines[n]) is None: - selfcert = Identity.from_inline(version, currency, lines[n]) + selfcert = Identity.from_inline(currency, lines[n], version) identities.append(selfcert) n += 1 if Block.re_joiners.match(lines[n]): n += 1 while Block.re_actives.match(lines[n]) is None: - membership = Membership.from_inline(version, currency, "IN", lines[n]) + membership = Membership.from_inline(currency, "IN", lines[n], version) joiners.append(membership) n += 1 if Block.re_actives.match(lines[n]): n += 1 while Block.re_leavers.match(lines[n]) is None: - membership = Membership.from_inline(version, currency, "IN", lines[n]) + membership = Membership.from_inline(currency, "IN", lines[n], version) actives.append(membership) n += 1 if Block.re_leavers.match(lines[n]): n += 1 while Block.re_revoked.match(lines[n]) is None: - membership = Membership.from_inline(version, currency, "OUT", lines[n]) + membership = Membership.from_inline(currency, "OUT", lines[n], version) leavers.append(membership) n += 1 if Block.re_revoked.match(lines[n]): n += 1 while Block.re_excluded.match(lines[n]) is None: - revokation = Revocation.from_inline(version, currency, lines[n]) + revokation = Revocation.from_inline(currency, lines[n], version) revoked.append(revokation) n += 1 @@ -480,7 +482,7 @@ class Block(Document): n += 1 while Block.re_transactions.match(lines[n]) is None: certification = Certification.from_inline( - version, currency, prev_hash, lines[n] + currency, prev_hash, lines[n], version ) certifications.append(certification) n += 1 @@ -524,7 +526,6 @@ class Block(Document): signature = Block.parse_field("Signature", lines[n]) block = cls( - version, currency, number, powmin, @@ -550,6 +551,7 @@ class Block(Document): transactions, inner_hash, nonce, + version=version, ) # return block with signature diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py index 3a027d02..908d73e2 100644 --- a/duniterpy/documents/certification.py +++ b/duniterpy/documents/certification.py @@ -26,6 +26,8 @@ from .identity import Identity CertificationType = TypeVar("CertificationType", bound="Certification") +VERSION = 10 + class Certification(Document): """ @@ -58,22 +60,22 @@ class Certification(Document): def __init__( self, - version: int, currency: str, pubkey_from: str, identity: Union[Identity, str], timestamp: BlockUID, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Constructor - :param version: the UCP version :param currency: the currency of the blockchain :param pubkey_from: Pubkey of the certifier :param identity: Document instance of the certified identity or identity pubkey string :param timestamp: the blockuid :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=certification.VERSION) """ super().__init__(version, currency) self.pubkey_from = pubkey_from @@ -118,7 +120,7 @@ class Certification(Document): identity = Identity.from_certification_raw(signed_raw) - certification = cls(version, currency, pubkey_from, identity, timestamp) + certification = cls(currency, pubkey_from, identity, timestamp, version=version) # return certification with signature certification.signature = signature @@ -127,10 +129,10 @@ class Certification(Document): @classmethod def from_inline( cls: Type[CertificationType], - version: int, currency: str, blockhash: Optional[str], inline: str, + version: int = VERSION, ) -> CertificationType: """ Return Certification instance from inline document @@ -138,10 +140,10 @@ class Certification(Document): Only self.pubkey_to is populated. You must populate self.identity with an Identity instance to use raw/sign/signed_raw methods - :param version: Version of document :param currency: Name of the currency :param blockhash: Hash of the block :param inline: Inline document + :param version: Document version (default=certification.VERSION) :return: """ cert_data = Certification.re_inline.match(inline) @@ -156,7 +158,9 @@ class Certification(Document): timestamp = BlockUID(blockid, blockhash) signature = cert_data.group(4) - certification = cls(version, currency, pubkey_from, pubkey_to, timestamp) + certification = cls( + currency, pubkey_from, pubkey_to, timestamp, version=version + ) # return certification with signature certification.signature = signature diff --git a/duniterpy/documents/identity.py b/duniterpy/documents/identity.py index 7d996f94..1eb7e4d6 100644 --- a/duniterpy/documents/identity.py +++ b/duniterpy/documents/identity.py @@ -25,6 +25,8 @@ from .document import Document, MalformedDocumentError IdentityType = TypeVar("IdentityType", bound="Identity") +VERSION = 10 + class Identity(Document): """ @@ -80,22 +82,22 @@ class Identity(Document): def __init__( self, - version: int, currency: str, pubkey: str, uid: str, timestamp: BlockUID, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Create an identity document - :param version: Version of the document :param currency: Name of the currency :param pubkey: Public key of the account linked to the identity :param uid: Unique identifier :param timestamp: BlockUID instance :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=identity.VERSION) """ super().__init__(version, currency) @@ -108,14 +110,14 @@ class Identity(Document): @classmethod def from_inline( - cls: Type[IdentityType], version: int, currency: str, inline: str + cls: Type[IdentityType], currency: str, inline: str, version: int = VERSION ) -> IdentityType: """ Return Identity instance from inline Identity string - :param version: Document version number :param currency: Name of the currency :param inline: Inline string of the Identity + :param version: Document version (default=certification.VERSION) :return: """ selfcert_data = Identity.re_inline.match(inline) @@ -126,7 +128,7 @@ class Identity(Document): blockstamp = BlockUID.from_str(selfcert_data.group(3)) uid = selfcert_data.group(4) - identity = cls(version, currency, pubkey, uid, blockstamp) + identity = cls(currency, pubkey, uid, blockstamp, version=version) # return identity with signature identity.signature = signature @@ -163,7 +165,7 @@ class Identity(Document): signature = Identity.parse_field("Signature", lines[n]) - identity = cls(version, currency, pubkey, uid, blockstamp) + identity = cls(currency, pubkey, uid, blockstamp, version=version) # return identity with signature identity.signature = signature @@ -231,7 +233,7 @@ Timestamp: {timestamp} n += 1 signature = Identity.parse_field("IdtySignature", lines[n]) - identity = cls(version, currency, issuer, uid, timestamp) + identity = cls(currency, issuer, uid, timestamp, version=version) identity.signature = signature return identity @@ -265,7 +267,7 @@ Timestamp: {timestamp} n += 1 signature = Identity.parse_field("IdtySignature", lines[n]) - identity = cls(version, currency, issuer, uid, timestamp) + identity = cls(currency, issuer, uid, timestamp, version=version) identity.signature = signature return identity @@ -273,19 +275,18 @@ Timestamp: {timestamp} @classmethod def from_bma_lookup_response( cls: Type[IdentityType], - version: int, currency: str, pubkey: str, lookup_response: dict, + version: int = VERSION, ) -> IdentityType: """ Return Identity instance from bma.lookup request response - :param pubkey: - :param version: Document version :param currency: Currency codename :param pubkey: Requested identity pubkey :param lookup_response: Lookup request response + :param version: Document version (default=identity.VERSION) :return: """ identity = None diff --git a/duniterpy/documents/membership.py b/duniterpy/documents/membership.py index 0bfb9071..0f3e940f 100644 --- a/duniterpy/documents/membership.py +++ b/duniterpy/documents/membership.py @@ -25,6 +25,8 @@ from .document import Document, MalformedDocumentError MembershipType = TypeVar("MembershipType", bound="Membership") +VERSION = 10 + class Membership(Document): """ @@ -77,7 +79,6 @@ class Membership(Document): def __init__( self, - version: int, currency: str, issuer: str, membership_ts: BlockUID, @@ -85,11 +86,11 @@ class Membership(Document): uid: str, identity_ts: BlockUID, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Create a membership document - :param version: Version of the document :param currency: Name of the currency :param issuer: Public key of the issuer :param membership_ts: BlockUID of this membership @@ -97,6 +98,7 @@ class Membership(Document): :param uid: Unique identifier of the identity :param identity_ts: BlockUID of the identity :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=membership.VERSION) """ super().__init__(version, currency) @@ -112,18 +114,18 @@ class Membership(Document): @classmethod def from_inline( cls: Type[MembershipType], - version: int, currency: str, membership_type: str, inline: str, + version: int = VERSION, ) -> MembershipType: """ Return Membership instance from inline format - :param version: Version of the document :param currency: Name of the currency :param membership_type: "IN" or "OUT" to enter or exit membership :param inline: Inline string format + :param version: Document version (default=membership.VERSION) :return: """ data = Membership.re_inline.match(inline) @@ -135,13 +137,13 @@ class Membership(Document): identity_blockstamp = BlockUID.from_str(data.group(4)) uid = data.group(5) membership = cls( - version, currency, issuer, membership_blockstamp, membership_type, uid, identity_blockstamp, + version=version, ) # return membership with signature @@ -191,13 +193,13 @@ class Membership(Document): n += 1 membership = cls( - version, currency, issuer, membership_blockstamp, membership_type, uid, identity_blockstamp, + version=version, ) # return membership with signature diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index a7c0ce62..9d81e056 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -27,6 +27,8 @@ from .document import Document, MalformedDocumentError PeerType = TypeVar("PeerType", bound="Peer") +VERSION = 10 + class Peer(Document): """ @@ -66,22 +68,22 @@ class Peer(Document): def __init__( self, - version: int, currency: str, pubkey: str, block_uid: BlockUID, endpoints: List[Endpoint], signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Init Peer instance - :param version: Version of the document :param currency: Name of the currency :param pubkey: Public key of the issuer :param block_uid: BlockUID instance timestamp :param endpoints: List of endpoints string :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=peer.VERSION) """ super().__init__(version, currency) @@ -131,7 +133,7 @@ class Peer(Document): raise MalformedDocumentError("Peer") signature = data.group(1) - peer = cls(version, currency, pubkey, block_uid, endpoints) + peer = cls(currency, pubkey, block_uid, endpoints, version=version) # return peer with signature peer.signature = signature @@ -172,7 +174,7 @@ Endpoints: signature = str(Peer.re_signature.match(data["signature"])) - peer = cls(version, currency, pubkey, block_uid, endpoints) + peer = cls(currency, pubkey, block_uid, endpoints, version=version) # return peer with signature peer.signature = signature diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py index 1e030941..2aa824f0 100644 --- a/duniterpy/documents/revocation.py +++ b/duniterpy/documents/revocation.py @@ -25,6 +25,8 @@ from .identity import Identity RevocationType = TypeVar("RevocationType", bound="Revocation") +VERSION = 10 + class Revocation(Document): """ @@ -62,18 +64,18 @@ class Revocation(Document): def __init__( self, - version: int, currency: str, identity: Union[Identity, str], signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Init Revocation instance - :param version: Version number :param currency: Name of the currency :param identity: Identity instance or identity pubkey :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=revocation.VERSION) """ super().__init__(version, currency) @@ -85,7 +87,7 @@ class Revocation(Document): @classmethod def from_inline( - cls: Type[RevocationType], version: int, currency: str, inline: str + cls: Type[RevocationType], currency: str, inline: str, version: int = VERSION ) -> RevocationType: """ Return Revocation document instance from inline string @@ -93,10 +95,9 @@ class Revocation(Document): Only self.pubkey is populated. You must populate self.identity with an Identity instance to use raw/sign/signed_raw methods - :param version: Version number :param currency: Name of the currency :param inline: Inline document - + :param version: Document version (default=revocation.VERSION) :return: """ cert_data = Revocation.re_inline.match(inline) @@ -104,7 +105,7 @@ class Revocation(Document): raise MalformedDocumentError("Revokation") pubkey = cert_data.group(1) signature = cert_data.group(2) - revocation = cls(version, currency, pubkey) + revocation = cls(currency, pubkey, version=version) # return revocation with signature revocation.signature = signature @@ -134,7 +135,7 @@ class Revocation(Document): identity = Identity.from_revocation_raw(signed_raw) - revocation = cls(version, currency, identity) + revocation = cls(currency, identity, version=version) # return revocation with signature revocation.signature = signature diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index 4fb3429c..557c16e0 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -32,6 +32,8 @@ from ..key import SigningKey, VerifyingKey from .block_uid import BlockUID from .document import Document, MalformedDocumentError +VERSION = 10 + def reduce_base(amount: int, base: int) -> Tuple[int, int]: """ @@ -538,7 +540,6 @@ class Transaction(Document): def __init__( self, - version: int, currency: str, blockstamp: Optional[BlockUID], locktime: int, @@ -549,11 +550,11 @@ class Transaction(Document): comment: str, time: Optional[int] = None, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Init Transaction instance - :param version: Version number of the document :param currency: Name of the currency :param blockstamp: BlockUID timestamp of the block :param locktime: Lock time in seconds @@ -564,6 +565,7 @@ class Transaction(Document): :param comment: Comment field :param time: time when the transaction enters the blockchain :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=transaction.VERSION) """ super().__init__(version, currency) self.blockstamp = blockstamp @@ -730,7 +732,6 @@ Comment: {comment} raise MalformedDocumentError("Compact TX Signatures") transaction = cls( - version, currency, blockstamp, locktime, @@ -739,6 +740,7 @@ Comment: {comment} unlocks, outputs, comment, + version=version, ) # return transaction with signatures @@ -822,7 +824,6 @@ Comment: {comment} n += 1 transaction = cls( - version, currency, blockstamp, locktime, @@ -832,6 +833,7 @@ Comment: {comment} outputs, comment, time, + version=version, ) # return transaction with signatures @@ -995,7 +997,6 @@ class SimpleTransaction(Transaction): def __init__( self, - version: int, currency: str, blockstamp: BlockUID, locktime: int, @@ -1006,6 +1007,7 @@ class SimpleTransaction(Transaction): comment: str, time: int, signing_key: SigningKey = None, + version: int = VERSION, ) -> None: """ Init instance @@ -1021,9 +1023,9 @@ class SimpleTransaction(Transaction): :param comment: Comment field :param time: time when the transaction enters the blockchain :param signing_key: SigningKey instance to sign the document (default=None) + :param version: Document version (default=transaction.VERSION) """ super().__init__( - version, currency, blockstamp, locktime, @@ -1034,6 +1036,7 @@ class SimpleTransaction(Transaction): comment, time, signing_key=signing_key, + version=version, ) @staticmethod diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py index 33b27450..ea98a883 100644 --- a/examples/save_revoke_document.py +++ b/examples/save_revoke_document.py @@ -45,10 +45,6 @@ REVOCATION_DOCUMENT_FILE_PATH = os.path.join( home_path, "duniter_account_revocation_document.txt" ) -# Current protocol version -PROTOCOL_VERSION = 10 - - ################################################ @@ -68,7 +64,7 @@ def get_identity_document( lookup_response = client(bma.wot.lookup, pubkey) return Identity.from_bma_lookup_response( - PROTOCOL_VERSION, current_block["currency"], pubkey, lookup_response + current_block["currency"], pubkey, lookup_response ) @@ -85,7 +81,7 @@ def get_signed_raw_revocation_document( :rtype: str """ key = SigningKey.from_credentials(salt, password) - revocation = Revocation(PROTOCOL_VERSION, identity.currency, identity, key) + revocation = Revocation(identity.currency, identity, key) return revocation.signed_raw() diff --git a/examples/send_certification.py b/examples/send_certification.py index 2d20578e..dc08e99a 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -29,10 +29,6 @@ from duniterpy.key import SigningKey # Here we use the secure BASIC_MERKLED_API (BMAS) BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443" -# Current protocol version -PROTOCOL_VERSION = 10 - - ################################################ @@ -52,7 +48,7 @@ def get_identity_document( lookup_response = client(bma.wot.lookup, pubkey) return Identity.from_bma_lookup_response( - PROTOCOL_VERSION, current_block["currency"], pubkey, lookup_response + current_block["currency"], pubkey, lookup_response ) @@ -70,7 +66,6 @@ def get_certification_document( """ # construct Certification Document return Certification( - version=10, currency=current_block["currency"], pubkey_from=signing_key.pubkey, identity=identity, diff --git a/examples/send_identity.py b/examples/send_identity.py index 4b58bfc8..c87e15f1 100644 --- a/examples/send_identity.py +++ b/examples/send_identity.py @@ -52,7 +52,6 @@ def get_identity_document( # create identity document identity = Identity( - version=10, currency=current_block["currency"], pubkey=key.pubkey, uid=uid, diff --git a/examples/send_membership.py b/examples/send_membership.py index e47526cd..8ff26c63 100644 --- a/examples/send_membership.py +++ b/examples/send_membership.py @@ -58,7 +58,6 @@ def get_membership_document( # create membership document membership = Membership( - version=10, currency=current_block["currency"], issuer=key.pubkey, membership_ts=timestamp, diff --git a/examples/send_transaction.py b/examples/send_transaction.py index 537ba3fa..9e5dd0e9 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -34,10 +34,6 @@ from duniterpy.key import SigningKey # Here we use the secure BASIC_MERKLED_API (BMAS) BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443" -# Version of the transaction document -TRANSACTION_VERSION = 10 - - ################################################ @@ -93,7 +89,6 @@ def get_transaction_document( ] transaction = Transaction( - version=TRANSACTION_VERSION, currency=current_block["currency"], blockstamp=BlockUID(current_block["number"], current_block["hash"]), locktime=0, diff --git a/tests/api/ws2p/test_ws2p.py b/tests/api/ws2p/test_ws2p.py index 9461c78f..63216808 100644 --- a/tests/api/ws2p/test_ws2p.py +++ b/tests/api/ws2p/test_ws2p.py @@ -188,11 +188,11 @@ class TestWs2p(unittest.TestCase): document_message = DocumentMessage() # prepare document identity_document = Identity( - 10, "beta_brousouf", "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd", "lolcat", BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + version=10, ) # get json string message json_document_message = document_message.get_json( diff --git a/tests/documents/test_certification.py b/tests/documents/test_certification.py index e5fcee3b..a9902267 100644 --- a/tests/documents/test_certification.py +++ b/tests/documents/test_certification.py @@ -45,7 +45,7 @@ class TestCertification(unittest.TestCase): def test_self_certification_from_inline(self): version = 2 currency = "beta_brousouf" - selfcert = Identity.from_inline(version, currency, selfcert_inlines[0]) + selfcert = Identity.from_inline(currency, selfcert_inlines[0], version) self.assertEqual( selfcert.pubkey, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ) @@ -58,7 +58,7 @@ class TestCertification(unittest.TestCase): ) self.assertEqual(selfcert.uid, "lolcat") - selfcert = Identity.from_inline(version, currency, selfcert_inlines[1]) + selfcert = Identity.from_inline(currency, selfcert_inlines[1], version) self.assertEqual(selfcert.pubkey, "RdrHvL179Rw62UuyBrqy2M1crx7RPajaViBatS59EGS") self.assertEqual( selfcert.signature, @@ -77,7 +77,7 @@ class TestCertification(unittest.TestCase): timestamp = BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD") signature = "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci" - selfcert = Identity(version, currency, issuer, uid, timestamp) + selfcert = Identity(currency, issuer, uid, timestamp, version=version) selfcert.signature = signature result = """Version: 2 @@ -96,7 +96,7 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf def test_certifications_from_inline(self): version = 2 currency = "zeta_brousouf" - cert = Certification.from_inline(version, currency, None, cert_inlines[0]) + cert = Certification.from_inline(currency, None, cert_inlines[0], version) self.assertEqual( cert.pubkey_from, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ) @@ -109,10 +109,10 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf ) cert = Certification.from_inline( - version, currency, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD", cert_inlines[1], + version, ) self.assertEqual( cert.pubkey_from, "9fx25FmeBDJcikZLWxK5HuzKNbY6MaWYXoK1ajteE42Y" @@ -135,16 +135,16 @@ J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBf timestamp = BlockUID(36, "1076F10A7397715D2BEE82579861999EA1F274AC") signature = "SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneNYSMV3rk" identity = Identity( - version, currency, pubkey_to, "lolcat", BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + version=version, ) identity.signature = "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci" certification = Certification( - version, currency, pubkey_from, identity, timestamp + currency, pubkey_from, identity, timestamp, version=version ) certification.signature = signature @@ -167,7 +167,7 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN def test_revokation_from_inline(self): version = 2 currency = "zeta_brousouf" - revokation = Revocation.from_inline(version, currency, revokation_inline) + revokation = Revocation.from_inline(currency, revokation_inline, version) self.assertEqual( revokation.pubkey, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" ) @@ -182,15 +182,15 @@ SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneN pubkey = "HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd" signature = "SoKwoa8PFfCDJWZ6dNCv7XstezHcc2BbKiJgVDXv82R5zYR83nis9dShLgWJ5w48noVUHimdngzYQneNYSMV3rk" identity = Identity( - version, currency, pubkey, "lolcat", BlockUID(32, "DB30D958EE5CB75186972286ED3F4686B8A1C2CD"), + version=version, ) identity.signature = "J3G9oM5AKYZNLAB5Wx499w61NuUoS57JVccTShUbGpCMjCqj9yXXqNq7dyZpDWA6BxipsiaMZhujMeBfCznzyci" - revokation = Revocation(version, currency, identity) + revokation = Revocation(currency, identity, version=version) revokation.signature = signature result = """Version: 2 diff --git a/tests/documents/test_membership.py b/tests/documents/test_membership.py index 0fd90c9f..0ec660a4 100644 --- a/tests/documents/test_membership.py +++ b/tests/documents/test_membership.py @@ -35,7 +35,7 @@ dkaXIiCYUJtCg8Feh/BKvPYf4uFH9CJ/zY6J4MlA9BsjmcMe4YAblvNt/gJy31b1aGq3ue3h14mLMCu8 class TestMembership(unittest.TestCase): def test_frominline(self): - membership = Membership.from_inline(2, "zeta_brousouf", "IN", membership_inline) + membership = Membership.from_inline("zeta_brousouf", "IN", membership_inline, 2) self.assertEqual( membership.issuer, "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" ) diff --git a/tests/documents/test_transaction.py b/tests/documents/test_transaction.py index 1adbcc41..56994569 100644 --- a/tests/documents/test_transaction.py +++ b/tests/documents/test_transaction.py @@ -433,7 +433,6 @@ class TestTransaction(unittest.TestCase): def test_transaction_document_generation(self): transaction = Transaction( - version=10, currency="gtest", blockstamp=BlockUID( 8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC" @@ -467,7 +466,6 @@ class TestTransaction(unittest.TestCase): ] transaction = Transaction( - version=12, currency="g1-test", blockstamp=BlockUID( 8979, "000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC" -- GitLab