Skip to content
Snippets Groups Projects
Commit e3cdebfb authored by Jakub Ziebinski's avatar Jakub Ziebinski
Browse files

Add the possibility to create a transaction from an already created...

Add the possibility to create a transaction from an already created proto-transaction and json-transaction
parent ed9997bb
No related branches found
No related tags found
1 merge request!230Implementation of the python wax interface
......@@ -3,10 +3,13 @@ from __future__ import annotations
import json
from typing import Final
from utils.refs import PROTO_REF_TRANSACTION
from beekeepy import Beekeeper
from wax import create_wax_foundation
from wax.proto.comment_pb2 import comment
from wax.proto.operation_pb2 import operation
from wax.proto.transaction_pb2 import transaction as proto_transaction
from wax.proto.transfer_pb2 import transfer
from wax.proto.vote_pb2 import vote
......@@ -15,6 +18,7 @@ WALLET_PASSWORD: Final[str] = "password"
TAPOS: Final[str] = "00000449f7860b82b4fbe2f317c670e9f01d6d9a"
EXPECTED_OPERATIONS_COUNT: Final[int] = 2
EXPECTED_SIGNATURES_COUNT: Final[int] = 1
EXPECTED_IMPACTED_ACCOUNT: Final[str] = "alice"
EXPECTED_IMPACTED_ACCOUNT_2: Final[str] = "bob"
EXPECTED_REQUIRED_AUTHORITIES: Final[set[str]] = {EXPECTED_IMPACTED_ACCOUNT}
......@@ -50,6 +54,29 @@ def test_create_transaction() -> None:
assert len(transaction.transaction.operations) == EXPECTED_OPERATIONS_COUNT
def test_create_transaction_with_already_created_transaction() -> None:
# ARRANGE
wax = create_wax_foundation()
# ACT
transaction = wax.create_transaction_from_proto(proto_transaction(**PROTO_REF_TRANSACTION)) # type: ignore[arg-type]
transaction.push_operation(
comment(
parent_permlink="/",
parent_author="",
author="alice",
permlink="/",
title="Best comment",
body="<span>comment</span>",
json_metadata="{}",
)
)
# ASSERT
assert len(transaction.transaction.operations) == EXPECTED_OPERATIONS_COUNT
assert len(transaction.transaction.signatures) == EXPECTED_SIGNATURES_COUNT
def test_create_and_sign_transaction() -> None:
# ARRANGE
wax = create_wax_foundation()
......
......@@ -52,7 +52,7 @@ from wax.cpp_python_bridge import ( # type: ignore[attr-defined]
suggest_brain_key,
validate_operation,
)
from wax.interfaces import ChainConfig, IWaxBaseInterface, TTimestamp
from wax.interfaces import ChainConfig, IWaxBaseInterface, JsonTransaction, ProtoTransaction, TTimestamp
if TYPE_CHECKING:
from decimal import Decimal
......@@ -281,3 +281,9 @@ class WaxBaseApi(IWaxBaseInterface):
expiration = expiration.replace(microsecond=0) - datetime.now(timezone.utc).replace(microsecond=0)
assert isinstance(expiration, timedelta), "Expiration has to be timedelta type"
return Transaction(api=self, tapos_block_id=tapos_block_id, expiration_time=expiration)
def create_transaction_from_proto(self, transaction: ProtoTransaction) -> ITransaction:
return Transaction(api=self, tapos_block_id=transaction)
def create_transaction_from_json(self, transaction: JsonTransaction) -> ITransaction:
return Transaction.from_api(api=self, transaction=transaction)
......@@ -589,3 +589,30 @@ class IWaxBaseInterface(ABC):
Returns:
Transaction object
"""
@abstractmethod
def create_transaction_from_proto(self, transaction: ProtoTransaction) -> ITransaction:
"""
Creates transaction object from proto transaction.
Args:
transaction: Proto transaction object.
Returns:
Transaction object
"""
@abstractmethod
def create_transaction_from_json(self, transaction: JsonTransaction) -> ITransaction:
"""
Creates transaction object from JSON transaction.
Args:
transaction: JSON transaction object.
Returns:
Transaction object
Raises:
WaxValidationFailedError: When the transaction is incorrect.
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment