Skip to content

Commit

Permalink
Use method to temporarily change timeout for long calls
Browse files Browse the repository at this point in the history
  • Loading branch information
raidgar98 authored and vogel76 committed Sep 27, 2024
1 parent 72174b0 commit 1570622
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import test_tools as tt
from hive_local_tools.functional.python.operation import (
generate_large_amount_of_blocks,
publish_feeds,
)

Expand All @@ -20,7 +21,9 @@


@pytest.mark.testnet()
def test_convert_hbd_to_hive(create_node_and_wallet_for_convert_tests: tuple, alice: ConvertAccount) -> None:
def test_convert_hbd_to_hive(
create_node_and_wallet_for_convert_tests: tuple[tt.InitNode, tt.Wallet], alice: ConvertAccount
) -> None:
# test case 1 from: https://gitlab.syncad.com/hive/hive/-/issues/478
node, wallet = create_node_and_wallet_for_convert_tests
publish_feeds(node, wallet, base=1000, quote=400)
Expand All @@ -35,9 +38,7 @@ def test_convert_hbd_to_hive(create_node_and_wallet_for_convert_tests: tuple, al
alice.check_if_current_rc_mana_was_reduced(transaction)
alice.check_if_funds_to_convert_were_subtracted(transaction)
# generate enough block to jump HIVE_COLLATERALIZED_CONVERSION_DELAY interval
node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key, count=1680, skip=0, miss_blocks=0, edit_if_needed=True
)
generate_large_amount_of_blocks(node=node, block_signer=tt.Account("initminer"), count=1680)
alice.check_if_right_amount_was_converted_and_added_to_balance(transaction)
alice.assert_fill_convert_request_operation(expected_amount=1)

Expand Down Expand Up @@ -93,17 +94,13 @@ def test_convert_hbd_to_hive_during_few_days(
alice.assert_fill_convert_request_operation(expected_amount=vops_counter)
convert_transactions_it += 1

node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key,
count=blocks_to_generate,
skip=0,
miss_blocks=0,
edit_if_needed=True,
)
generate_large_amount_of_blocks(node, tt.Account("initminer"), count=blocks_to_generate)


@pytest.mark.testnet()
def test_convert_hive_to_hbd(create_node_and_wallet_for_convert_tests: tuple, alice: ConvertAccount) -> None:
def test_convert_hive_to_hbd(
create_node_and_wallet_for_convert_tests: tuple[tt.InitNode, tt.Wallet], alice: ConvertAccount
) -> None:
# test case 1 from: https://gitlab.syncad.com/hive/hive/-/issues/481
node, wallet = create_node_and_wallet_for_convert_tests
publish_feeds(node, wallet, base=1000, quote=400)
Expand All @@ -123,9 +120,7 @@ def test_convert_hive_to_hbd(create_node_and_wallet_for_convert_tests: tuple, al
alice.assert_collateralized_conversion_requests(trx=transaction, state="create")

# generate enough blocks to jump HIVE_COLLATERALIZED_CONVERSION_DELAY interval
node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key, count=1680, skip=0, miss_blocks=0, edit_if_needed=True
)
generate_large_amount_of_blocks(node=node, block_signer=tt.Account("initminer"), count=1680)
alice.assert_if_right_amount_of_hives_came_back_after_collateral_conversion(transaction)
alice.assert_collateralized_conversion_requests(trx=transaction, state="delete")
alice.assert_fill_collateralized_convert_request_operation(expected_amount=1)
Expand Down Expand Up @@ -185,13 +180,7 @@ def test_convert_hive_to_hbd_during_few_days(
)
alice.assert_fill_collateralized_convert_request_operation(expected_amount=vops_counter)
convert_transactions_it += 1
node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key,
count=blocks_to_generate,
skip=0,
miss_blocks=0,
edit_if_needed=True,
)
generate_large_amount_of_blocks(node, tt.Account("initminer"), count=blocks_to_generate)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -221,7 +210,7 @@ def test_convert_hive_to_hbd_during_few_days(
],
)
def test_convert_hive_into_hbd_with_changing_median_current_price_during_conversion(
create_node_and_wallet_for_convert_tests: tuple,
create_node_and_wallet_for_convert_tests: tuple[tt.InitNode, tt.Wallet],
alice: ConvertAccount,
initial_feed_base_value: int,
further_feed_base_value: int,
Expand All @@ -242,9 +231,7 @@ def test_convert_hive_into_hbd_with_changing_median_current_price_during_convers
publish_feeds(node, wallet, further_feed_base_value, 1000)

# generate enough block to jump HIVE_COLLATERALIZED_CONVERSION_DELAY interval
node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key, count=1680, skip=0, miss_blocks=0, edit_if_needed=True
)
generate_large_amount_of_blocks(node=node, block_signer=tt.Account("initminer"), count=1680)
alice.assert_if_right_amount_of_hives_came_back_after_collateral_conversion(transaction)
alice.assert_collateralized_conversion_requests(trx=transaction, state="delete")
alice.assert_fill_collateralized_convert_request_operation(expected_amount=1)
Expand All @@ -258,7 +245,9 @@ def test_convert_hive_into_hbd_with_changing_median_current_price_during_convers
],
)
def test_minimal_feed_price_greater_than_median_feed_price(
create_node_and_wallet_for_convert_tests: tuple, alice: ConvertAccount, feed_base_values: tuple
create_node_and_wallet_for_convert_tests: tuple[tt.InitNode, tt.Wallet],
alice: ConvertAccount,
feed_base_values: tuple,
) -> None:
# test case from Excel file (sheet TC2 - columns D, F) https://gitlab.syncad.com/hive/hive/-/issues/481#note_154312
node, wallet = create_node_and_wallet_for_convert_tests
Expand Down Expand Up @@ -301,13 +290,7 @@ def test_minimal_feed_price_greater_than_median_feed_price(
trx = publish_feeds(node, wallet, next(feeds_it), 1000, broadcast=False)
node.api.network_broadcast.broadcast_transaction(trx=trx)

node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key,
count=blocks_to_generate,
skip=0,
miss_blocks=0,
edit_if_needed=True,
)
generate_large_amount_of_blocks(node=node, block_signer=tt.Account("initminer"), count=blocks_to_generate)


@pytest.mark.parametrize(
Expand All @@ -318,7 +301,9 @@ def test_minimal_feed_price_greater_than_median_feed_price(
],
)
def test_median_feed_price_greater_than_minimal_feed_price(
create_node_and_wallet_for_convert_tests: tuple, alice: ConvertAccount, feed_base_values: tuple
create_node_and_wallet_for_convert_tests: tuple[tt.InitNode, tt.Wallet],
alice: ConvertAccount,
feed_base_values: tuple,
) -> None:
# test case from Excel file (sheet TC2 - columns C, E) https://gitlab.syncad.com/hive/hive/-/issues/481#note_154312
node, wallet = create_node_and_wallet_for_convert_tests
Expand Down Expand Up @@ -363,10 +348,4 @@ def test_median_feed_price_greater_than_minimal_feed_price(
alice.assert_fill_collateralized_convert_request_operation(expected_amount=vops_counter)
convert_transactions_it += 1

node.api.debug_node.debug_generate_blocks(
debug_key=tt.Account("initminer").private_key,
count=blocks_to_generate,
skip=0,
miss_blocks=0,
edit_if_needed=True,
)
generate_large_amount_of_blocks(node=node, block_signer=tt.Account("initminer"), count=blocks_to_generate)
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,10 @@ def assert_account_was_created(node: tt.AnyNode, account_name: str) -> None:
created_accounts.append(operation.op.value.new_account_name)

assert account_name in created_accounts, f"Account named {account_name} was not created"


def generate_large_amount_of_blocks(node: tt.AnyNode, block_signer: tt.Account, count: int) -> None:
with node.temporarily_change_timeout(seconds=30):
node.api.debug_node.debug_generate_blocks(
debug_key=block_signer.private_key, count=count, skip=0, miss_blocks=0, edit_if_needed=True
)

0 comments on commit 1570622

Please sign in to comment.