Skip to content

Commit

Permalink
Expand test coverage for message format of find_recurrent_transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Kudela authored and vogel76 committed May 29, 2024
1 parent 7477d53 commit 704e1fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import annotations

import pytest

import test_tools as tt
from hive_local_tools import run_for


@run_for("testnet", "mainnet_5m", "live_mainnet")
def test_find_recurrent_transfers(node: tt.InitNode | tt.RemoteNode, should_prepare: bool) -> None:
@pytest.mark.parametrize("asset", [tt.Asset.Test(10), tt.Asset.Tbd(10)])
def test_find_recurrent_transfers(node: tt.InitNode | tt.RemoteNode, should_prepare: bool, asset: tt.Asset) -> None:
if should_prepare:
wallet = tt.Wallet(attach_to=node)
wallet.api.create_account("initminer", "alice", "{}")
wallet.api.recurrent_transfer("initminer", "alice", tt.Asset.Test(10), "{}", 720, 12)
wallet.api.recurrent_transfer("initminer", "alice", asset, "{}", 720, 12)
node.api.condenser.find_recurrent_transfers("initminer")
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pytest

import test_tools as tt
from hive_local_tools import run_for

Expand All @@ -9,12 +11,13 @@
# too. There is no listing method for recurrent_transfers, and they could run out of executions after some time.
# See the readme.md file in this directory for further explanation.
@run_for("testnet")
def test_find_recurrent_transfers(node: tt.InitNode) -> None:
@pytest.mark.parametrize("asset", [tt.Asset.Test(5), tt.Asset.Tbd(5)])
def test_find_recurrent_transfers(node: tt.InitNode, asset: tt.Asset) -> None:
wallet = tt.Wallet(attach_to=node)
wallet.create_account("alice", hives=tt.Asset.Test(100), vests=tt.Asset.Test(100))
wallet.create_account("alice", hives=tt.Asset.Test(100), hbds=tt.Asset.Tbd(100), vests=tt.Asset.Test(100))
wallet.api.create_account("initminer", "bob", "{}")
# create transfer from alice to bob for amount 5 test hives every 720 hours, repeat 12 times
wallet.api.recurrent_transfer("alice", "bob", tt.Asset.Test(5), "memo", 720, 12)
wallet.api.recurrent_transfer("alice", "bob", asset, "memo", 720, 12)
# "from" is a Python keyword and needs workaround
recurrent_transfers = node.api.database.find_recurrent_transfers(**{"from": "alice"}).recurrent_transfers
assert len(recurrent_transfers) != 0
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"bob",
],
)
@pytest.mark.parametrize("asset", [tt.Asset.Test(20), tt.Asset.Tbd(20)])
@run_for("testnet", "mainnet_5m", "live_mainnet")
def test_find_recurrent_transfers_with_correct_value(
node: tt.InitNode | tt.RemoteNode, should_prepare: bool, reward_fund_name: str
node: tt.InitNode | tt.RemoteNode, should_prepare: bool, reward_fund_name: str, asset: tt.Asset
) -> None:
if should_prepare:
wallet = tt.Wallet(attach_to=node)
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob")
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob", asset=asset)

node.api.wallet_bridge.find_recurrent_transfers(reward_fund_name)

Expand Down Expand Up @@ -49,34 +50,39 @@ def test_find_recurrent_transfers_with_incorrect_value(


@pytest.mark.parametrize("reward_fund_name", [["alice"]])
@pytest.mark.parametrize("asset", [tt.Asset.Test(20), tt.Asset.Tbd(20)])
@run_for("testnet", "mainnet_5m", "live_mainnet")
def test_find_recurrent_transfers_with_incorrect_type_of_argument(
node: tt.InitNode | tt.RemoteNode, should_prepare: bool, reward_fund_name: list
node: tt.InitNode | tt.RemoteNode, should_prepare: bool, reward_fund_name: list, asset: tt.Asset
) -> None:
if should_prepare:
wallet = tt.Wallet(attach_to=node)
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob")
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob", asset=asset)

with pytest.raises(tt.exceptions.CommunicationError):
node.api.wallet_bridge.find_recurrent_transfers(reward_fund_name)


@run_for("testnet", "mainnet_5m", "live_mainnet")
@pytest.mark.parametrize("asset", [tt.Asset.Test(20), tt.Asset.Tbd(20)])
def test_find_recurrent_transfers_with_additional_argument(
node: tt.InitNode | tt.RemoteNode, should_prepare: bool
node: tt.InitNode | tt.RemoteNode, should_prepare: bool, asset: tt.Asset
) -> None:
if should_prepare:
wallet = tt.Wallet(attach_to=node)
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob")
create_accounts_and_make_recurrent_transfer(wallet, from_account="alice", to_account="bob", asset=asset)

node.api.wallet_bridge.find_recurrent_transfers("alice", "additional_argument")


def create_accounts_and_make_recurrent_transfer(wallet: tt.Wallet, from_account: str, to_account: str) -> None:
def create_accounts_and_make_recurrent_transfer(
wallet: tt.Wallet, from_account: str, to_account: str, asset: tt.Asset
) -> None:
with wallet.in_single_transaction():
wallet.api.create_account("initminer", from_account, "{}")
wallet.api.create_account("initminer", to_account, "{}")

wallet.api.transfer_to_vesting("initminer", from_account, tt.Asset.Test(100))
wallet.api.transfer("initminer", from_account, tt.Asset.Test(500), "memo")
wallet.api.recurrent_transfer(from_account, to_account, tt.Asset.Test(20), "memo", 100, 10)
wallet.api.transfer("initminer", from_account, tt.Asset.Tbd(500), "memo")
wallet.api.recurrent_transfer(from_account, to_account, asset, "memo", 100, 10)

0 comments on commit 704e1fe

Please sign in to comment.