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

Implementation of the wrapper for imports from the proto

parent 1a9a2e25
No related branches found
No related tags found
1 merge request!288Move compiled proto package to the private part
Showing
with 151 additions and 172 deletions
......@@ -3,7 +3,7 @@ import asyncio
from beekeepy import AsyncBeekeeper
from beekeepy.interfaces import HttpUrl
from wax import create_wax_foundation
from wax.proto.transfer_pb2 import transfer
from wax.proto.operations import transfer
PASSWORD = "pass"
......
from google.protobuf.json_format import ParseDict
from wax.proto import (
comment_pb2,
limit_order_cancel_pb2,
recurrent_transfer_pb2,
operation_pb2,
transaction_pb2,
vote_pb2,
)
from wax.proto.operations import comment, limit_order_cancel, recurrent_transfer, vote
from wax.proto.transaction import transaction
from wax.wax_visitor import OperationVisitor
tx_json = {
......@@ -41,19 +35,19 @@ tx_json = {
class MyOperationVisitor(OperationVisitor):
def limit_order_cancel(self, op: limit_order_cancel_pb2.limit_order_cancel):
def limit_order_cancel(self, op: limit_order_cancel):
print(f"Handling limit_order_cancel operation:\n{op}")
assert op.owner == "orderabc"
assert op.orderid == 5
def vote(self, op: vote_pb2.vote) -> None:
def vote(self, op: vote) -> None:
print(f"Handling vote operation:\n{op}")
assert op.voter == "Alice"
assert op.author == "Bob"
assert op.permlink == "/"
assert op.weight == 11
def comment(self, op: comment_pb2.comment) -> None:
def comment(self, op: comment) -> None:
print(f"Handling comment operation:\n{op}")
assert op.parent_permlink == "/"
assert op.parent_author == ""
......@@ -63,7 +57,7 @@ class MyOperationVisitor(OperationVisitor):
assert op.body == "<span>comment</span>"
assert op.json_metadata == "{}"
def recurrent_transfer(self, op: recurrent_transfer_pb2.recurrent_transfer) -> None:
def recurrent_transfer(self, op: recurrent_transfer) -> None:
print(f"Handling recurrent_transfer operation:\n{op}")
assert op.from_account == "alice"
assert op.to_account == "harry"
......@@ -77,7 +71,7 @@ class MyOperationVisitor(OperationVisitor):
if __name__ == "__main__":
tx = ParseDict(tx_json, transaction_pb2.transaction())
tx = ParseDict(tx_json, transaction())
visit = MyOperationVisitor()
for op in tx.operations:
visit.accept(op)
......@@ -77,6 +77,12 @@ strict = true
disallow_untyped_decorators = false
plugins = "pydantic.mypy"
[[tool.mypy.overrides]]
module = "wax._private.proto.*"
ignore_missing_imports = true
follow_imports = "skip"
ignore_errors = true
[[tool.mypy.overrides]]
module = "wax.proto.*"
ignore_missing_imports = true
......
......@@ -6,7 +6,7 @@ import pytest
from wax._private.models.asset import Asset
from wax.models.asset import AssetName
from wax.proto.asset_pb2 import asset
from wax.proto.asset import asset
if TYPE_CHECKING:
from wax.interfaces import IWaxBaseInterface
......
......@@ -5,29 +5,29 @@ from typing import TYPE_CHECKING, Any, Final
import pytest
from wax.proto import authority_pb2, operation_pb2, recover_account_pb2
from wax.proto.vote_pb2 import vote
from wax.proto.authority import authority
from wax.proto.operations import operation, recover_account, vote
if TYPE_CHECKING:
from wax.interfaces import IWaxBaseInterface
from wax.models.operations import Operation
AUTHORITY_1: Final[authority_pb2.authority] = authority_pb2.authority(
AUTHORITY_1: Final[authority] = authority(
weight_threshold=1,
account_auths={"account": 1, "account1": 2},
key_auths={"STM76EQNV2RTA6yF9TnBvGSV71mW7eW36MM7XQp24JxdoArTfKA76": 1},
)
AUTHORITY_2: Final[authority_pb2.authority] = authority_pb2.authority(
AUTHORITY_2: Final[authority] = authority(
weight_threshold=1,
account_auths={"account1": 1, "account2": 2},
key_auths={"STM76EQNV2RTA6yF9TnBvGSV71mW7eW36MM7XQp24JxdoArTfKA76": 1},
)
RECOVER_ACCOUNT: Final[recover_account_pb2.recover_account] = recover_account_pb2.recover_account(
RECOVER_ACCOUNT: Final[recover_account] = recover_account(
account_to_recover="account", new_owner_authority=AUTHORITY_1, recent_owner_authority=AUTHORITY_2, extensions=[]
)
PROTO_OPERATION: Final[operation_pb2.operation] = operation_pb2.operation(recover_account=RECOVER_ACCOUNT)
PROTO_OPERATION: Final[operation] = operation(recover_account=RECOVER_ACCOUNT)
API_OPERATION_DICT: Final[dict[str, Any]] = {
"type": "claim_reward_balance_operation",
"value": {
......@@ -68,7 +68,7 @@ def test_get_operation_impacted_accounts_0(wax: IWaxBaseInterface) -> None:
@pytest.mark.description("Should be able to get impacted accounts from example proto operation")
def test_get_operation_impacted_accounts_1(wax: IWaxBaseInterface) -> None:
result = wax.get_operation_impacted_accounts(
operation=operation_pb2.operation(
operation=operation(
vote=vote(
author="c0ff33a",
permlink="ewxhnjbj",
......
......@@ -5,11 +5,8 @@ from typing import TYPE_CHECKING, Any, Final
import pytest
from wax.proto.recurrent_transfer_pb2 import (
recurrent_transfer,
recurrent_transfer_extension,
recurrent_transfer_pair_id,
)
from wax._private.proto.recurrent_transfer_pb2 import recurrent_transfer_extension, recurrent_transfer_pair_id
from wax.proto.operations import recurrent_transfer
if TYPE_CHECKING:
from wax import ITransaction, IWaxBaseInterface
......
......@@ -11,10 +11,8 @@ if TYPE_CHECKING:
from wax.interfaces import IWaxBaseInterface
from wax._private.models.hive_date_time import HiveDateTime
from wax.proto.operation_pb2 import operation
from wax.proto.recurrent_transfer_pb2 import recurrent_transfer
from wax.proto.transaction_pb2 import transaction
from wax.proto.vote_pb2 import vote
from wax.proto.operations import operation, recurrent_transfer, vote
from wax.proto.transaction import transaction
from .templates import (
RECOVER_ACCOUNT_TRANSACTION,
......
......@@ -7,7 +7,8 @@ import pytest
from google.protobuf.json_format import MessageToDict
from wax._private.exceptions import WaxError
from wax.proto.update_proposal_pb2 import update_proposal, update_proposal_end_date, update_proposal_extension
from wax._private.proto.update_proposal_pb2 import update_proposal_end_date, update_proposal_extension
from wax.proto.operations import update_proposal
if TYPE_CHECKING:
from wax.interfaces import ITransaction, IWaxBaseInterface
......
from __future__ import annotations
from wax.wax_visitor import AbstractOperationVisitor
from wax.proto import vote_pb2
from wax.proto.operations import vote
class MyOperationVisitor(AbstractOperationVisitor):
def vote(self, op: vote_pb2.vote) -> None:
def vote(self, op: vote) -> None:
pass
......
from google.protobuf.json_format import ParseDict
from wax.proto import (
vote_pb2,
limit_order_cancel_pb2,
operation_pb2,
transaction_pb2
)
from wax.proto.operations import vote, operation
from wax.proto.transaction import transaction
from wax.wax_visitor import OperationVisitor
tx_json = {
......@@ -17,18 +12,18 @@ tx_json = {
}
class MyOperationVisitor(OperationVisitor):
vote_obj: vote_pb2.vote = None
vote_obj: vote = None
def vote(self, op: vote_pb2.vote) -> None:
def vote(self, op: vote) -> None:
print("Processing 'vote' operation")
self.vote_obj = op
def test_operation_visitor():
tx = ParseDict(tx_json, transaction_pb2.transaction())
tx = ParseDict(tx_json, transaction())
visitor = MyOperationVisitor()
for op in tx.operations:
visitor.accept(op)
assert visitor.vote_obj == ParseDict(tx_json["operations"][0]["vote"], vote_pb2.vote())
assert visitor.vote_obj == ParseDict(tx_json["operations"][0]["vote"], vote())
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
asset_pb2,
account_create_with_delegation_pb2,
operation_pb2,
transaction_pb2,
future_extensions_pb2,
authority_pb2
)
from wax.proto.operations import account_create_with_delegation, operation
from wax.proto.asset import asset
from wax.proto.transaction import transaction
from wax.proto.authority import authority
from wax._private.proto.future_extensions_pb2 import future_extensions
def test_account_create_with_delegation():
extension: future_extensions_pb2.future_extensions = future_extensions_pb2.future_extensions()
vests: asset_pb2.asset = asset_pb2.asset(
extension: future_extensions = future_extensions()
vests: asset = asset(
nai="@@000000037", precision=6, amount="10"
)
hive: asset_pb2.asset = asset_pb2.asset(
hive: asset = asset(
nai="@@000000021", precision=3, amount="10"
)
authority: authority_pb2.authority = authority_pb2.authority(
proto_authority: authority = authority(
weight_threshold=1,
account_auths={"account": 1, "account1": 2},
key_auths={"STM76EQNV2RTA6yF9TnBvGSV71mW7eW36MM7XQp24JxdoArTfKA76": 1},
)
account_create_with_delegation: account_create_with_delegation_pb2.account_create_with_delegation = account_create_with_delegation_pb2.account_create_with_delegation(
account_create_with_delegation_proto: account_create_with_delegation = account_create_with_delegation(
fee=hive,
delegation=vests,
creator="creator",
new_account_name="account2",
owner=authority,
active=authority,
posting=authority,
owner=proto_authority,
active=proto_authority,
posting=proto_authority,
memo_key="STM6FATHLohxTN8RWWkU9ZZwVywXo6MEDjHHui1jEBYkG2tTdvMYo",
json_metadata="{}",
extensions=[]
)
account_create_with_delegation_operation: operation_pb2.operation = operation_pb2.operation(
account_create_with_delegation=account_create_with_delegation
account_create_with_delegation_operation: operation = operation(
account_create_with_delegation=account_create_with_delegation_proto
)
check_operations(account_create_with_delegation_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[account_create_with_delegation_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
account_update_pb2,
authority_pb2,
operation_pb2,
transaction_pb2
)
from wax.proto.operations import account_update, operation
from wax.proto.authority import authority
from wax.proto.transaction import transaction
def test_account_update():
posting: authority_pb2.authority = authority_pb2.authority(
posting: authority = authority(
weight_threshold=1,
account_auths={"account": 1, "account1": 2},
key_auths={"STM76EQNV2RTA6yF9TnBvGSV71mW7eW36MM7XQp24JxdoArTfKA76": 1},
)
account_update: account_update_pb2.account_update = (
account_update_pb2.account_update(
account_update_proto: account_update = (
account_update(
account="theoretical",
posting=posting,
memo_key="STM6FATHLohxTN8RWWkU9ZZwVywXo6MEDjHHui1jEBYkG2tTdvMYo",
......@@ -23,14 +20,14 @@ def test_account_update():
)
)
account_update_operation: operation_pb2.operation = operation_pb2.operation(
account_update=account_update
account_update_operation: operation = operation(
account_update=account_update_proto
)
check_operations(account_update_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[account_update_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
......@@ -11,17 +11,15 @@
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
account_update2_pb2,
operation_pb2,
transaction_pb2,
future_extensions_pb2
)
from wax.proto.operations import account_update2, operation
from wax.proto.transaction import transaction
from wax._private.proto.future_extensions_pb2 import future_extensions
def test_account_update2():
extension: future_extensions_pb2.future_extensions = future_extensions_pb2.future_extensions()
account_update2: account_update2_pb2.account_update2 = (
account_update2_pb2.account_update2(
extension: future_extensions = future_extensions()
account_update2_proto: account_update2 = (
account_update2(
account="rosylisboa",
json_metadata="",
posting_json_metadata="{}",
......@@ -29,14 +27,14 @@ def test_account_update2():
)
)
account_update2_operation: operation_pb2.operation = operation_pb2.operation(
account_update2=account_update2
account_update2_operation: operation = operation(
account_update2=account_update2_proto
)
check_operations(account_update2_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[account_update2_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
......@@ -8,27 +8,25 @@
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
account_witness_proxy_pb2,
operation_pb2,
transaction_pb2
)
from wax.proto.operations import account_witness_proxy, operation
from wax.proto.transaction import transaction
def test_account_witness_proxy():
account_witness_proxy: account_witness_proxy_pb2.account_witness_proxy = (
account_witness_proxy_pb2.account_witness_proxy(
account_witness_proxy_proto: account_witness_proxy = (
account_witness_proxy(
account="bunkermining", proxy="datasecuritynode"
)
)
account_witness_proxy_operation: operation_pb2.operation = (
operation_pb2.operation(account_witness_proxy=account_witness_proxy)
account_witness_proxy_operation: operation = (
operation(account_witness_proxy=account_witness_proxy_proto)
)
check_operations(account_witness_proxy_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[account_witness_proxy_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
......@@ -9,27 +9,27 @@
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
account_witness_vote_pb2,
operation_pb2,
transaction_pb2
from wax.proto.operations import (
account_witness_vote,
operation,
)
from wax.proto.transaction import transaction
def test_account_witness_vote():
account_witness_vote: account_witness_vote_pb2.account_witness_vote = (
account_witness_vote_pb2.account_witness_vote(
account_witness_vote_proto: account_witness_vote = (
account_witness_vote(
account="donalddrumpf", witness="berniesanders", approve=True
)
)
account_witness_vote_operation: operation_pb2.operation = (
operation_pb2.operation(account_witness_vote=account_witness_vote)
account_witness_vote_operation: operation = (
operation(account_witness_vote=account_witness_vote_proto)
)
check_operations(account_witness_vote_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[account_witness_vote_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
operation_pb2,
transaction_pb2,
cancel_transfer_from_savings_pb2
from wax.proto.operations import (
operation,
cancel_transfer_from_savings,
)
from wax.proto.transaction import transaction
def test_cancel_transfer_from_savings():
cancel_transfer_from_savings: cancel_transfer_from_savings_pb2.cancel_transfer_from_savings = cancel_transfer_from_savings_pb2.cancel_transfer_from_savings(
cancel_transfer_from_savings_proto: cancel_transfer_from_savings = cancel_transfer_from_savings(
from_account="faddy",
request_id=3
)
cancel_transfer_from_savings_operation: operation_pb2.operation = (
operation_pb2.operation(cancel_transfer_from_savings=cancel_transfer_from_savings)
cancel_transfer_from_savings_operation: operation = (
operation(cancel_transfer_from_savings=cancel_transfer_from_savings_proto)
)
check_operations(cancel_transfer_from_savings_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
transaction_proto: transaction = transaction(
operations=[cancel_transfer_from_savings_operation]
)
check_transaction(transaction)
check_transaction(transaction_proto)
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
change_recovery_account_pb2,
operation_pb2,
transaction_pb2,
future_extensions_pb2
from wax.proto.operations import (
change_recovery_account,
operation,
)
from wax.proto.transaction import transaction
from wax._private.proto.future_extensions_pb2 import future_extensions
def test_change_recovery_account():
extension: future_extensions_pb2.future_extensions = future_extensions_pb2.future_extensions()
change_recovery_account: change_recovery_account_pb2.change_recovery_account = change_recovery_account_pb2.change_recovery_account(
extension: future_extensions = future_extensions()
change_recovery_account_proto: change_recovery_account = change_recovery_account(
account_to_recover="account",
new_recovery_account="account1",
extensions=[]
)
change_recovery_account_operation: operation_pb2.operation = operation_pb2.operation(
change_recovery_account=change_recovery_account
change_recovery_account_operation: operation = operation(
change_recovery_account=change_recovery_account_proto
)
check_operations(change_recovery_account_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[change_recovery_account_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
claim_account_pb2,
operation_pb2,
transaction_pb2,
future_extensions_pb2,
asset_pb2
)
from wax.proto.operations import claim_account, operation
from wax.proto.transaction import transaction
from wax.proto.asset import asset
from wax._private.proto.future_extensions_pb2 import future_extensions, void_t
def test_claim_account():
extension: future_extensions_pb2.future_extensions = future_extensions_pb2.future_extensions(void_t=future_extensions_pb2.void_t())
fee: asset_pb2.asset = asset_pb2.asset(
extension: future_extensions = future_extensions(void_t=void_t())
fee: asset = asset(
nai="@@000000021", precision=3, amount="10"
)
claim_account: claim_account_pb2.claim_account = claim_account_pb2.claim_account(
claim_account_proto: claim_account = claim_account(
creator="rosylisboa",
fee=fee,
extensions=[]
)
claim_account_operation: operation_pb2.operation = operation_pb2.operation(
claim_account=claim_account
claim_account_operation: operation = operation(
claim_account=claim_account_proto
)
check_operations(claim_account_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
transaction_proto: transaction = transaction(
operations=[claim_account_operation]
)
check_transaction(transaction)
check_transaction(transaction_proto)
......@@ -22,26 +22,26 @@
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
asset_pb2,
claim_reward_balance_pb2,
operation_pb2,
transaction_pb2
from wax.proto.operations import (
claim_reward_balance,
operation,
)
from wax.proto.transaction import transaction
from wax.proto.asset import asset
def test_claim_reward_balance():
reward_hive: asset_pb2.asset = asset_pb2.asset(
reward_hive: asset = asset(
amount="0", precision=3, nai="@@000000021"
)
reward_hbd: asset_pb2.asset = asset_pb2.asset(
reward_hbd: asset = asset(
amount="104", precision=3, nai="@@000000013"
)
reward_vests: asset_pb2.asset = asset_pb2.asset(
reward_vests: asset = asset(
amount="531747227", precision=6, nai="@@000000037"
)
claim_reward_balance: claim_reward_balance_pb2.claim_reward_balance = (
claim_reward_balance_pb2.claim_reward_balance(
claim_reward_balance_proto: claim_reward_balance = (
claim_reward_balance(
account="bradleyarrow",
reward_hive=reward_hive,
reward_hbd=reward_hbd,
......@@ -49,14 +49,14 @@ def test_claim_reward_balance():
)
)
claim_reward_balance_operation: operation_pb2.operation = (
operation_pb2.operation(claim_reward_balance=claim_reward_balance)
claim_reward_balance_operation: operation = (
operation(claim_reward_balance=claim_reward_balance_proto)
)
check_operations(claim_reward_balance_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
proto_transaction: transaction = transaction(
operations=[claim_reward_balance_operation]
)
check_transaction(transaction)
check_transaction(proto_transaction)
......@@ -13,32 +13,32 @@
from tests.utils.checkers import check_operations, check_transaction
from wax.proto import (
asset_pb2,
collateralized_convert_pb2,
operation_pb2,
transaction_pb2
from wax.proto.operations import (
collateralized_convert,
operation,
)
from wax.proto.transaction import transaction
from wax.proto.asset import asset
def test_collateralized_convert():
amount: asset_pb2.asset = asset_pb2.asset(
amount: asset = asset(
amount="102", precision=3, nai="@@000000021"
)
collateralized_convert: collateralized_convert_pb2.collateralized_convert = (
collateralized_convert_pb2.collateralized_convert(
collateralized_convert_proto: collateralized_convert = (
collateralized_convert(
owner="karbea", requestid=2, amount=amount
)
)
collateralized_convert_operation: operation_pb2.operation = (
operation_pb2.operation(collateralized_convert=collateralized_convert)
collateralized_convert_operation: operation = (
operation(collateralized_convert=collateralized_convert_proto)
)
check_operations(collateralized_convert_operation)
transaction: transaction_pb2.transaction = transaction_pb2.transaction(
transaction_proto: transaction = transaction(
operations=[collateralized_convert_operation]
)
check_transaction(transaction)
check_transaction(transaction_proto)
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