diff --git a/bindings/python/examples/client/06_simple_block.py b/bindings/python/examples/client/06_simple_block.py index 734444a108..967913787c 100644 --- a/bindings/python/examples/client/06_simple_block.py +++ b/bindings/python/examples/client/06_simple_block.py @@ -26,7 +26,7 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print(f'Empty block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') diff --git a/bindings/python/examples/client/08_data_block.py b/bindings/python/examples/client/08_data_block.py index 900313a537..89cdd4bd34 100644 --- a/bindings/python/examples/client/08_data_block.py +++ b/bindings/python/examples/client/08_data_block.py @@ -3,7 +3,7 @@ import os from dataclasses import asdict from dotenv import load_dotenv -from iota_sdk import BasicBlock, Bip44, CoinType, Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload, MnemonicSecretManager, SecretManager +from iota_sdk import BasicBlockBody, Bip44, CoinType, Client, utf8_to_hex, hex_to_utf8, TaggedDataPayload, MnemonicSecretManager, SecretManager load_dotenv() @@ -27,14 +27,14 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print(f'Data block sent: {os.environ["EXPLORER_URL"]}/block/{block_id}') block = client.get_block(block_id).block -if isinstance(block, BasicBlock): +if isinstance(block, BasicBlockBody): print(f'Block data: {json.dumps(asdict(block), indent=4)}') payload = block.payload diff --git a/bindings/python/examples/client/post_raw_block.py b/bindings/python/examples/client/post_raw_block.py index ea60a51839..8f01ca0a88 100644 --- a/bindings/python/examples/client/post_raw_block.py +++ b/bindings/python/examples/client/post_raw_block.py @@ -24,8 +24,8 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data")))[0] -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) blockBytes = client.get_block_raw(block_id) # Post raw block diff --git a/bindings/python/examples/client/submit_and_read_block.py b/bindings/python/examples/client/submit_and_read_block.py index 00002ff09b..2c3d444207 100644 --- a/bindings/python/examples/client/submit_and_read_block.py +++ b/bindings/python/examples/client/submit_and_read_block.py @@ -11,7 +11,7 @@ # Make sure you have first installed it with `pip install iota_sdk` import os from dotenv import load_dotenv -from iota_sdk import BasicBlock, Bip44, Client, CoinType, hex_to_utf8, utf8_to_hex, TaggedDataPayload, MnemonicSecretManager, SecretManager +from iota_sdk import BasicBlockBody, Bip44, Client, CoinType, hex_to_utf8, utf8_to_hex, TaggedDataPayload, MnemonicSecretManager, SecretManager load_dotenv() @@ -70,14 +70,14 @@ TaggedDataPayload( utf8_to_hex("tag"), utf8_to_hex("data"))) -signed_block = secret_manager.sign_block(unsigned_block, chain) -block_id = client.post_block(signed_block) +block = secret_manager.sign_block(unsigned_block, chain) +block_id = client.post_block(block) print('\nThe block ID for your submitted block is:') print(f' {block_id}') print('\nMetadata for your submitted block is:') -print(f' {signed_block}') +print(f' {block}') ######################################################## # Step 3: Use the block ID to read the payload back @@ -92,7 +92,7 @@ # Get the whole block block = client.get_block(block_id).block -if isinstance(block, BasicBlock): +if isinstance(block, BasicBlockBody): payload_out = block.payload tag_hex_out = block.payload.tag message_hex_out = block.payload.data diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index a08515c175..2d8174022b 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -12,11 +12,11 @@ from .prefix_hex import * from .types.address import * from .types.balance import * -from .types.block.basic import * from .types.block.block import * +from .types.block.body.basic import * +from .types.block.body.type import * +from .types.block.body.validation import * from .types.block.metadata import * -from .types.block.signed_block import * -from .types.block.validation import * from .types.block_builder_options import * from .types.block_issuer_key import * from .types.burn import * diff --git a/bindings/python/iota_sdk/client/_high_level_api.py b/bindings/python/iota_sdk/client/_high_level_api.py index 080a1e3041..928d165804 100644 --- a/bindings/python/iota_sdk/client/_high_level_api.py +++ b/bindings/python/iota_sdk/client/_high_level_api.py @@ -4,7 +4,7 @@ from typing import List, Optional from dataclasses import dataclass from abc import ABCMeta, abstractmethod -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.block import Block from iota_sdk.types.common import CoinType, HexStr, json from iota_sdk.types.output_metadata import OutputWithMetadata from iota_sdk.types.output_id import OutputId @@ -111,7 +111,7 @@ def get_outputs_ignore_errors( }) return [OutputWithMetadata.from_dict(o) for o in outputs] - def find_blocks(self, block_ids: List[HexStr]) -> List[SignedBlock]: + def find_blocks(self, block_ids: List[HexStr]) -> List[Block]: """Find all blocks by provided block IDs. Args: @@ -123,7 +123,7 @@ def find_blocks(self, block_ids: List[HexStr]) -> List[SignedBlock]: blocks = self._call_method('findBlocks', { 'blockIds': block_ids }) - return [SignedBlock.from_dict(block) for block in blocks] + return [Block.from_dict(block) for block in blocks] def find_inputs(self, addresses: List[str], amount: int): """Function to find inputs from addresses for a provided amount(useful for offline signing). diff --git a/bindings/python/iota_sdk/client/_node_core_api.py b/bindings/python/iota_sdk/client/_node_core_api.py index b48a59798f..23ed49bec5 100644 --- a/bindings/python/iota_sdk/client/_node_core_api.py +++ b/bindings/python/iota_sdk/client/_node_core_api.py @@ -5,7 +5,7 @@ from abc import ABCMeta, abstractmethod from dacite import from_dict -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.block import Block from iota_sdk.types.block.metadata import BlockMetadata, BlockWithMetadata from iota_sdk.types.common import HexStr from iota_sdk.types.node_info import NodeInfo, NodeInfoWrapper @@ -75,7 +75,7 @@ def get_tips(self) -> List[HexStr]: """ return self._call_method('getTips') - def post_block(self, block: SignedBlock) -> HexStr: + def post_block(self, block: Block) -> HexStr: """Post a block. Args: @@ -88,10 +88,10 @@ def post_block(self, block: SignedBlock) -> HexStr: 'block': block.__dict__ }) - def get_block(self, block_id: HexStr) -> SignedBlock: + def get_block(self, block_id: HexStr) -> Block: """Get the block corresponding to the given block id. """ - return SignedBlock.from_dict(self._call_method('getBlock', { + return Block.from_dict(self._call_method('getBlock', { 'blockId': block_id })) @@ -152,13 +152,13 @@ def get_output_metadata( 'outputId': output_id_str })) - def get_included_block(self, transaction_id: HexStr) -> SignedBlock: + def get_included_block(self, transaction_id: HexStr) -> Block: """Returns the included block of the given transaction. Returns: The included block. """ - return SignedBlock.from_dict(self._call_method('getIncludedBlock', { + return Block.from_dict(self._call_method('getIncludedBlock', { 'transactionId': transaction_id })) diff --git a/bindings/python/iota_sdk/client/_utils.py b/bindings/python/iota_sdk/client/_utils.py index a1b0859062..3855d4d8a3 100644 --- a/bindings/python/iota_sdk/client/_utils.py +++ b/bindings/python/iota_sdk/client/_utils.py @@ -34,7 +34,7 @@ def _call_method(self, name, data=None): """ # pylint: disable=redefined-builtin - def hex_to_bech32(self, hex: HexStr, bech32_hrp: str) -> str: + def hex_to_bech32(self, hex_str: HexStr, bech32_hrp: str) -> str: """Transforms a hex encoded address to a bech32 encoded address. """ return self._call_method('hexToBech32', { diff --git a/bindings/python/iota_sdk/client/client.py b/bindings/python/iota_sdk/client/client.py index 06e38a42cc..97f44c3ec8 100644 --- a/bindings/python/iota_sdk/client/client.py +++ b/bindings/python/iota_sdk/client/client.py @@ -11,7 +11,7 @@ from iota_sdk.client._node_indexer_api import NodeIndexerAPI from iota_sdk.client._high_level_api import HighLevelAPI from iota_sdk.client._utils import ClientUtils -from iota_sdk.types.block.signed_block import UnsignedBlock +from iota_sdk.types.block.block import UnsignedBlock from iota_sdk.types.common import HexStr, Node from iota_sdk.types.feature import Feature from iota_sdk.types.network_info import NetworkInfo diff --git a/bindings/python/iota_sdk/secret_manager/secret_manager.py b/bindings/python/iota_sdk/secret_manager/secret_manager.py index 4c3e669c96..01fd5aad7c 100644 --- a/bindings/python/iota_sdk/secret_manager/secret_manager.py +++ b/bindings/python/iota_sdk/secret_manager/secret_manager.py @@ -7,7 +7,7 @@ import humps from iota_sdk.external import create_secret_manager, call_secret_manager_method -from iota_sdk.types.block.signed_block import SignedBlock, UnsignedBlock +from iota_sdk.types.block.block import Block, UnsignedBlock from iota_sdk.types.common import HexStr from iota_sdk.types.signature import Ed25519Signature, Bip44 from iota_sdk.types.transaction_data import PreparedTransactionData @@ -280,14 +280,14 @@ def sign_transaction( })) def sign_block( - self, unsigned_block: UnsignedBlock, chain: Bip44) -> SignedBlock: + self, unsigned_block: UnsignedBlock, chain: Bip44) -> Block: """Sign a block. Args: unsigned_block: The unsigned block data. chain: The Bip44 chain to use. """ - return from_dict(SignedBlock, self._call_method('signBlock', { + return from_dict(Block, self._call_method('signBlock', { 'unsignedBlock': unsigned_block.to_dict(), 'chain': chain.to_dict() })) diff --git a/bindings/python/iota_sdk/types/block/block.py b/bindings/python/iota_sdk/types/block/block.py index 9fc0d54747..61c94bebf2 100644 --- a/bindings/python/iota_sdk/types/block/block.py +++ b/bindings/python/iota_sdk/types/block/block.py @@ -2,15 +2,78 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations -from enum import IntEnum +from dataclasses import dataclass, field +from typing import TypeAlias, Union +from dataclasses_json import config +from iota_sdk.utils import Utils +from iota_sdk.types.common import HexStr, json, SlotIndex +from iota_sdk.types.node_info import ProtocolParameters +from iota_sdk.types.signature import Signature +from iota_sdk.types.block.body.basic import BasicBlockBody +from iota_sdk.types.block.body.validation import ValidationBlockBody -class BlockType(IntEnum): - """Block types. +@json +@dataclass +class Block: + """A block that can hold either a `BasicBlockBody` or a `ValidationBlockBody`. + Shared data is stored alongside such a block in the header fields. Attributes: - Basic (0): A Basic Block. - Validation (1): A Validation Block. + protocol_version: Protocol version of the network to which this block belongs. + network_id: The identifier of the network to which this block belongs. + issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. + slot_commitment_id: The identifier of the slot to which this block commits. + latest_finalized_slot: The slot index of the latest finalized slot. + issuer_id: The identifier of the account that issued this block. + body: Holds either a `BasicBlockBody` or a `ValidationBlockBody`. + signature: The Block signature. """ - Basic = 0 - Validation = 1 + protocol_version: int + network_id: int = field(metadata=config( + encoder=str + )) + issuing_time: int = field(metadata=config( + encoder=str + )) + slot_commitment_id: HexStr + latest_finalized_slot: SlotIndex + issuer_id: HexStr + body: BlockBody + signature: Signature + + def id(self, params: ProtocolParameters) -> HexStr: + """Returns the block ID as a hexadecimal string. + """ + return Utils.block_id(self, params) + + +@json +@dataclass +class UnsignedBlock: + """An unsigned block type that can hold either a `BasicBlock` or a `ValidationBlock`. + Shared data is stored alongside such a block in the header fields. + + Attributes: + protocol_version: Protocol version of the network to which this block belongs. + network_id: The identifier of the network to which this block belongs. + issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. + slot_commitment_id: The identifier of the slot to which this block commits. + latest_finalized_slot: The slot index of the latest finalized slot. + issuer_id: The identifier of the account that issued this block. + block: Holds either a `BasicBlock` or a `ValidationBlock`. + """ + protocol_version: int + network_id: int = field(metadata=config( + encoder=str + )) + issuing_time: int = field(metadata=config( + encoder=str + )) + slot_commitment_id: HexStr + latest_finalized_slot: SlotIndex + issuer_id: HexStr + body: BlockBody + + +BlockBody: TypeAlias = Union[BasicBlockBody, ValidationBlockBody] diff --git a/bindings/python/iota_sdk/types/block/basic.py b/bindings/python/iota_sdk/types/block/body/basic.py similarity index 80% rename from bindings/python/iota_sdk/types/block/basic.py rename to bindings/python/iota_sdk/types/block/body/basic.py index 6300ad5399..52a1110189 100644 --- a/bindings/python/iota_sdk/types/block/basic.py +++ b/bindings/python/iota_sdk/types/block/body/basic.py @@ -5,15 +5,15 @@ from dataclasses import dataclass, field from typing import List, Optional from dataclasses_json import config -from iota_sdk.types.block.block import BlockType +from iota_sdk.types.block.body.type import BlockBodyType from iota_sdk.types.common import HexStr, json from iota_sdk.types.payload import Payload @json @dataclass -class BasicBlock: - """A `BasicBlock` is the most common type of block used to issue various kinds of payloads such as transactions +class BasicBlockBody: + """A Basic Block Body is the most common type of block body used to issue various kinds of payloads such as transactions at the cost of burning Mana. Attributes: @@ -31,5 +31,5 @@ class BasicBlock: shallow_like_parents: Optional[List[HexStr]] = None payload: Optional[Payload] = None type: int = field( - default_factory=lambda: int(BlockType.Basic), + default_factory=lambda: int(BlockBodyType.Basic), init=False) diff --git a/bindings/python/iota_sdk/types/block/body/type.py b/bindings/python/iota_sdk/types/block/body/type.py new file mode 100644 index 0000000000..fcd8b3d1d4 --- /dev/null +++ b/bindings/python/iota_sdk/types/block/body/type.py @@ -0,0 +1,16 @@ +# Copyright 2023 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations +from enum import IntEnum + + +class BlockBodyType(IntEnum): + """Block Body types. + + Attributes: + Basic (0): A Basic Block Body. + Validation (1): A Validation Block Body. + """ + Basic = 0 + Validation = 1 diff --git a/bindings/python/iota_sdk/types/block/validation.py b/bindings/python/iota_sdk/types/block/body/validation.py similarity index 81% rename from bindings/python/iota_sdk/types/block/validation.py rename to bindings/python/iota_sdk/types/block/body/validation.py index 3cee5b0cde..b963fcdeb4 100644 --- a/bindings/python/iota_sdk/types/block/validation.py +++ b/bindings/python/iota_sdk/types/block/body/validation.py @@ -4,14 +4,14 @@ from __future__ import annotations from dataclasses import dataclass, field from typing import List, Optional -from iota_sdk.types.block.block import BlockType +from iota_sdk.types.block.body.type import BlockBodyType from iota_sdk.types.common import HexStr, json @json @dataclass -class ValidationBlock: - """A Validation Block is a special type of block used by validators to secure the network. It is recognized by the +class ValidationBlockBody: + """A Validation Block Body is a special type of block body used by validators to secure the network. It is recognized by the Congestion Control of the IOTA 2.0 protocol and can be issued without burning Mana within the constraints of the allowed validator throughput. It is allowed to reference more parent blocks than a normal Basic Block. @@ -28,5 +28,5 @@ class ValidationBlock: weak_parents: Optional[List[HexStr]] = None shallow_like_parents: Optional[List[HexStr]] = None type: int = field( - default_factory=lambda: int(BlockType.Validation), + default_factory=lambda: int(BlockBodyType.Validation), init=False) diff --git a/bindings/python/iota_sdk/types/block/metadata.py b/bindings/python/iota_sdk/types/block/metadata.py index ae313ecd73..19a45386e2 100644 --- a/bindings/python/iota_sdk/types/block/metadata.py +++ b/bindings/python/iota_sdk/types/block/metadata.py @@ -6,8 +6,7 @@ from dataclasses import dataclass from typing import Optional from iota_sdk.types.common import HexStr, json -# TODO rename change to Block -from iota_sdk.types.block.signed_block import SignedBlock +from iota_sdk.types.block.block import Block @json @@ -196,5 +195,5 @@ class BlockWithMetadata: block: The block. metadata: The block metadata. """ - block: SignedBlock + block: Block metadata: BlockMetadata diff --git a/bindings/python/iota_sdk/types/block/signed_block.py b/bindings/python/iota_sdk/types/block/signed_block.py deleted file mode 100644 index 46439c6a77..0000000000 --- a/bindings/python/iota_sdk/types/block/signed_block.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2023 IOTA Stiftung -# SPDX-License-Identifier: Apache-2.0 - -from __future__ import annotations -from dataclasses import dataclass, field -from typing import TypeAlias, Union -from dataclasses_json import config -from iota_sdk.utils import Utils -from iota_sdk.types.common import HexStr, json, SlotIndex -from iota_sdk.types.node_info import ProtocolParameters -from iota_sdk.types.signature import Signature -from iota_sdk.types.block.basic import BasicBlock -from iota_sdk.types.block.validation import ValidationBlock - - -@json -@dataclass -class SignedBlock: - """A signed block type that can hold either a `BasicBlock` or a `ValidationBlock`. - Shared data is stored alongside such a block in the header fields. - - Attributes: - protocol_version: Protocol version of the network to which this block belongs. - network_id: The identifier of the network to which this block belongs. - issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. - slot_commitment_id: The identifier of the slot to which this block commits. - latest_finalized_slot: The slot index of the latest finalized slot. - issuer_id: The identifier of the account that issued this block. - block: Holds either a `BasicBlock` or a `ValidationBlock`. - signature: The Block signature. - """ - protocol_version: int - network_id: int = field(metadata=config( - encoder=str - )) - issuing_time: int = field(metadata=config( - encoder=str - )) - slot_commitment_id: HexStr - latest_finalized_slot: SlotIndex - issuer_id: HexStr - block: Block - signature: Signature - - def id(self, params: ProtocolParameters) -> HexStr: - """Returns the block ID as a hexadecimal string. - """ - return Utils.block_id(self, params) - - -@json -@dataclass -class UnsignedBlock: - """An unsigned block type that can hold either a `BasicBlock` or a `ValidationBlock`. - Shared data is stored alongside such a block in the header fields. - - Attributes: - protocol_version: Protocol version of the network to which this block belongs. - network_id: The identifier of the network to which this block belongs. - issuing_time: The time at which the block was issued. It is a Unix timestamp in nanoseconds. - slot_commitment_id: The identifier of the slot to which this block commits. - latest_finalized_slot: The slot index of the latest finalized slot. - issuer_id: The identifier of the account that issued this block. - block: Holds either a `BasicBlock` or a `ValidationBlock`. - """ - protocol_version: int - network_id: int = field(metadata=config( - encoder=str - )) - issuing_time: int = field(metadata=config( - encoder=str - )) - slot_commitment_id: HexStr - latest_finalized_slot: SlotIndex - issuer_id: HexStr - block: Block - - -Block: TypeAlias = Union[BasicBlock, ValidationBlock] diff --git a/bindings/python/iota_sdk/types/output_params.py b/bindings/python/iota_sdk/types/output_params.py index b5b896b61b..6133a2e704 100644 --- a/bindings/python/iota_sdk/types/output_params.py +++ b/bindings/python/iota_sdk/types/output_params.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass, field from enum import Enum -from typing import List, Optional +from typing import Optional from dataclasses_json import config from iota_sdk.types.common import HexStr, json, opt_int_encoder from iota_sdk.types.native_token import NativeToken diff --git a/bindings/python/iota_sdk/types/send_params.py b/bindings/python/iota_sdk/types/send_params.py index 6bcccd9c2e..4807147df8 100644 --- a/bindings/python/iota_sdk/types/send_params.py +++ b/bindings/python/iota_sdk/types/send_params.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass, field -from typing import Optional, List +from typing import Optional from dataclasses_json import config from iota_sdk.types.common import hex_str_decoder, HexStr, json from iota_sdk.types.native_token import NativeToken diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index f029feb703..17fdfc9395 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -3,7 +3,7 @@ from __future__ import annotations from json import dumps, loads -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, List, Optional from iota_sdk.types.signature import Ed25519Signature from iota_sdk.types.address import Address, deserialize_address @@ -11,14 +11,14 @@ from iota_sdk.types.transaction import Transaction from iota_sdk.types.node_info import ProtocolParameters from iota_sdk.types.output_id import OutputId -from iota_sdk.types.output import Output +from iota_sdk.types.unlock import Unlock from iota_sdk.external import call_utils_method from iota_sdk.types.payload import SignedTransactionPayload from iota_sdk.types.transaction_data import InputSigningData # Required to prevent circular import if TYPE_CHECKING: - from iota_sdk.types.block.signed_block import SignedBlock + from iota_sdk.types.block.block import Block # pylint: disable=too-many-public-methods @@ -163,7 +163,7 @@ def compute_token_id(account_id: HexStr, serial_number: int, }) @staticmethod - def block_id(block: SignedBlock, params: ProtocolParameters) -> HexStr: + def block_id(block: Block, params: ProtocolParameters) -> HexStr: """ Return a block ID (Blake2b256 hash of block bytes) from a block. """ return _call_method('blockId', { @@ -218,7 +218,7 @@ def verify_secp256k1_ecdsa_signature( @staticmethod def verify_transaction_semantic( - inputs: transaction: Transaction, inputs: List[InputSigningData], unlocks: Optional[List[Unlock]] = None) -> str: + transaction: Transaction, inputs: List[InputSigningData], unlocks: Optional[List[Unlock]] = None) -> str: """Verifies the semantic of a transaction. """ return _call_method('verifyTransactionSemantic', { diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 8a76a91b87..b1d10b0af8 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -3,7 +3,7 @@ from typing import get_args import pytest -from iota_sdk import BasicBlock, BlockType, SignedBlock, Payload, PayloadType +from iota_sdk import BasicBlockBody, BlockBodyType, Block, Payload, PayloadType def test_basic_block_with_tagged_data_payload(): @@ -19,7 +19,7 @@ def test_basic_block_with_tagged_data_payload(): "type": 0, "tag": "0x484f524e4554205370616d6d6572", "data": "0x57652061726520616c6c206d616465206f662073746172647573742e0a436f756e743a20353436333730330a54696d657374616d703a20323032332d30372d31395430373a32323a32385a0a54697073656c656374696f6e3a20343732c2b573"}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.TaggedData @@ -30,7 +30,7 @@ def test_basic_block_with_tagged_data_payload(): assert block_to_dict == block_dict -def test_signed_block_with_tagged_data_payload(): +def test_block_with_tagged_data_payload(): block_dict = { "protocolVersion": 3, "networkId": "10549460113735494767", @@ -63,14 +63,14 @@ def test_signed_block_with_tagged_data_payload(): "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" } } - signed_block = SignedBlock.from_dict(block_dict) - assert signed_block.to_dict() == block_dict - assert isinstance(signed_block.block, BasicBlock) - assert signed_block.block.type == BlockType.Basic - assert isinstance(signed_block.block.payload, get_args(Payload)) - assert signed_block.block.payload.type == PayloadType.TaggedData + block = Block.from_dict(block_dict) + assert block.to_dict() == block_dict + assert isinstance(block.body, BasicBlockBody) + assert block.body.type == BlockBodyType.Basic + assert isinstance(block.body.payload, get_args(Payload)) + assert block.body.payload.type == PayloadType.TaggedData # TODO: determine the actual hash of the block - # assert signed_block.id() == "0x7ce5ad074d4162e57f83cfa01cd2303ef5356567027ce0bcee0c9f57bc11656e" + # assert block.id() == "0x7ce5ad074d4162e57f83cfa01cd2303ef5356567027ce0bcee0c9f57bc11656e" @pytest.mark.skip(reason="https://github.com/iotaledger/iota-sdk/issues/1387") @@ -104,7 +104,7 @@ def test_basic_block_with_tx_payload(): "signature": {"type": 0, "publicKey": "0xa7af600976f440ec97d7bddbf17eacf0bfbf710e8cfb4ae3eae475d4ae8e1b16", "signature": "0x6bbe2eed95300a3d707af1bb17e04f83087fe31261256020fd00c24a54543c084079bed29c6d1479ee5acfd1e2fa32316e88c4c1577b4fbea3fe247f71114500"}}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction @@ -245,7 +245,7 @@ def test_basic_block_with_tx_payload_all_output_types(): "type": 1, "reference": 0}, { "type": 2, "reference": 1}, { "type": 1, "reference": 0}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction @@ -291,7 +291,7 @@ def test_basic_block_with_tx_payload_with_tagged_data_payload(): "signature": "0x30cb012af3402be1b4b2ed18e2aba86839da06ba38ff3277c481e17c003f0199ba26f5613199e0d24035628bb2b69a6ea2a7682e41c30244996baf3a2adc1c00"}}, {"type": 1, "reference": 0}]}} - block = BasicBlock.from_dict(block_dict) + block = BasicBlockBody.from_dict(block_dict) assert block.to_dict() == block_dict assert isinstance(block.payload, get_args(Payload)) assert block.payload.type == PayloadType.SignedTransaction