From d272fe1023ab08085df1a96cc23dcb0a7456aaec Mon Sep 17 00:00:00 2001 From: badrogger Date: Wed, 18 Oct 2023 21:01:34 +0000 Subject: [PATCH] Fix tests --- skale/utils/contracts_provision/main.py | 2 +- tests/manager/delegation/delegation_controller_test.py | 8 +++----- tests/manager/delegation/validator_service_test.py | 3 ++- tests/manager/node_rotation_test.py | 2 -- tests/manager/sync_manager_test.py | 6 ++++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/skale/utils/contracts_provision/main.py b/skale/utils/contracts_provision/main.py index b03ff79c..38542390 100644 --- a/skale/utils/contracts_provision/main.py +++ b/skale/utils/contracts_provision/main.py @@ -48,7 +48,7 @@ def _skip_evm_time(web3: Web3, seconds: int, mine: bool = True) -> int: """For test purposes only, works only with hardhat node""" - res = web3.provider.make_request('evm_increaseTime', [seconds * 1000]) + res = web3.provider.make_request('evm_increaseTime', [seconds]) web3.provider.make_request("evm_mine", []) return int(res['result']) diff --git a/tests/manager/delegation/delegation_controller_test.py b/tests/manager/delegation/delegation_controller_test.py index 801f9859..a006db7b 100644 --- a/tests/manager/delegation/delegation_controller_test.py +++ b/tests/manager/delegation/delegation_controller_test.py @@ -1,7 +1,5 @@ """ Tests for contracts/delegation/delegation_controller.py """ -from datetime import date - import pytest from skale.contracts.manager.delegation.delegation_controller import FIELDS @@ -36,7 +34,7 @@ def _delegate_and_activate(skale, validator_id=D_VALIDATOR_ID): delegations[-1]['id'], wait_for=True ) - _skip_evm_time(skale.web3, MONTH_IN_SECONDS) + _skip_evm_time(skale.web3, MONTH_IN_SECONDS, mine=False) def _get_number_of_delegations(skale, validator_id=D_VALIDATOR_ID): @@ -98,10 +96,10 @@ def test_delegate(skale, validator): assert delegated_now_after == delegated_now_before + D_DELEGATION_AMOUNT assert delegated_amount_after == delegated_amount_before + D_DELEGATION_AMOUNT - month = date.fromtimestamp(skale.web3.eth.get_block('latest')['timestamp']).month + month = skale.time_helpers_with_debug.get_current_month() res = skale.delegation_controller.get_delegated_to_validator( validator_id, - month * 100 + month ) assert isinstance(res, int) diff --git a/tests/manager/delegation/validator_service_test.py b/tests/manager/delegation/validator_service_test.py index e2033025..f38a10d4 100644 --- a/tests/manager/delegation/validator_service_test.py +++ b/tests/manager/delegation/validator_service_test.py @@ -393,6 +393,7 @@ def test_set_validator_description(skale): def test_revert_reason(skale): + no_validator_revert = "VM Exception while processing transaction: reverted with reason string 'Validator with such address already exists'" # noqa try: skale.validator_service.register_validator( name=D_VALIDATOR_NAME, @@ -402,7 +403,7 @@ def test_revert_reason(skale): wait_for=True ) except RevertError as e: - assert e.message == "{'code': -32603, 'message': \"Error: VM Exception while processing transaction: reverted with reason string 'Validator with such address already exists'\"}" # noqa + assert no_validator_revert in e.message def test_get_use_whitelist(skale): diff --git a/tests/manager/node_rotation_test.py b/tests/manager/node_rotation_test.py index f1257ab3..4c9e5561 100644 --- a/tests/manager/node_rotation_test.py +++ b/tests/manager/node_rotation_test.py @@ -73,9 +73,7 @@ def four_node_schain(skale, validator): def test_is_rotation_active(skale, four_node_schain): - # cleanup_nodes_schains(skale) nodes, skale_instances, name = four_node_schain - # add_test4_schain_type(skale) group_index = skale.web3.keccak(text=name) run_dkg(nodes, skale_instances, group_index) diff --git a/tests/manager/sync_manager_test.py b/tests/manager/sync_manager_test.py index 2da553ee..ae48b48b 100644 --- a/tests/manager/sync_manager_test.py +++ b/tests/manager/sync_manager_test.py @@ -1,3 +1,5 @@ +from web3.exceptions import ContractLogicError + from skale.transactions.exceptions import RevertError import pytest @@ -50,9 +52,9 @@ def test_remove_range_bad_params(skale, sync_manager_permissions, block_in_secon def test_get_range_bad_params(skale, sync_manager_permissions, block_in_second): num = skale.sync_manager.get_ip_ranges_number() # TODO: Make dry run handle revert that has empty reason properly - with pytest.raises(ValueError): + with pytest.raises(ContractLogicError): r = skale.sync_manager.get_ip_range_by_index(num) - with pytest.raises(ValueError): + with pytest.raises(ContractLogicError): r = skale.sync_manager.get_ip_range_by_index(0) r = skale.sync_manager.get_ip_range_by_name('phantom') assert r.start_ip == '0.0.0.0' and r.end_ip == '0.0.0.0'