From 9953700faf36e8f7cea4064d290eafb8c63c1997 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai <yoichi@brainbot.com> Date: Tue, 30 Jul 2019 19:16:13 +0200 Subject: [PATCH] Remvoe the repetition of ServiceRegistry registers --- raiden_contracts/tests/fixtures/base/utils.py | 20 +++++++++++ raiden_contracts/tests/test_one_to_n.py | 34 +++++-------------- raiden_contracts/tests/test_print_gas.py | 4 ++- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/raiden_contracts/tests/fixtures/base/utils.py b/raiden_contracts/tests/fixtures/base/utils.py index a9e291347..0b8c5d105 100644 --- a/raiden_contracts/tests/fixtures/base/utils.py +++ b/raiden_contracts/tests/fixtures/base/utils.py @@ -50,6 +50,26 @@ def get(number: int, privkeys: Iterable = ()) -> List: return get +@pytest.fixture(scope="session") +def create_service_account( + create_account: Callable, service_registry: Contract, custom_token: Contract +) -> Callable: + """Returns an address registered to ServiceRegistry""" + + def get() -> HexAddress: + account = create_account() + deposit = service_registry.functions.currentPrice().call() + custom_token.functions.mint(deposit).call_and_transact({"from": account}) + custom_token.functions.approve(service_registry.address, deposit).call_and_transact( + {"from": account} + ) + service_registry.functions.deposit(deposit).call_and_transact({"from": account}) + assert service_registry.functions.hasValidRegistration(account).call() + return account + + return get + + @pytest.fixture(scope="session") def get_private_key(ethereum_tester: EthereumTester) -> Callable: def get(account_address: HexAddress) -> str: diff --git a/raiden_contracts/tests/test_one_to_n.py b/raiden_contracts/tests/test_one_to_n.py index 5f514776f..46aee580e 100644 --- a/raiden_contracts/tests/test_one_to_n.py +++ b/raiden_contracts/tests/test_one_to_n.py @@ -13,15 +13,15 @@ def test_claim( user_deposit_contract: Contract, one_to_n_contract: Contract, deposit_to_udc: Callable, - get_accounts: Callable, get_private_key: Callable, web3: Web3, event_handler: Callable, - service_registry: Contract, - custom_token: Contract, + create_account: Callable, + create_service_account: Callable, ) -> None: ev_handler = event_handler(one_to_n_contract) - (A, B) = get_accounts(2) + A = create_account() + B = create_service_account() deposit_to_udc(A, 30) # happy case @@ -29,15 +29,6 @@ def test_claim( expiration = web3.eth.blockNumber + 2 chain_id = web3.eth.chainId - # B registers itself as a service provider - deposit = service_registry.functions.currentPrice().call() - custom_token.functions.mint(deposit).call_and_transact({"from": B}) - custom_token.functions.approve(service_registry.address, deposit).call_and_transact( - {"from": B} - ) - service_registry.functions.deposit(deposit).call_and_transact({"from": B}) - assert service_registry.functions.hasValidRegistration(B).call() - # IOU expired with pytest.raises(TransactionFailed): bad_expiration = web3.eth.blockNumber - 1 @@ -172,27 +163,18 @@ def test_claim_with_insufficient_deposit( user_deposit_contract: Contract, one_to_n_contract: Contract, deposit_to_udc: Callable, - get_accounts: Callable, get_private_key: Callable, web3: Web3, event_handler: Callable, - service_registry: Contract, - custom_token: Contract, + create_account: Callable, + create_service_account: Callable, ) -> None: ev_handler = event_handler(one_to_n_contract) - (A, B) = get_accounts(2) + A = create_account() + B = create_service_account() deposit_to_udc(A, 6) chain_id = web3.eth.chainId - # B registers itself as a service provider - deposit = service_registry.functions.currentPrice().call() - custom_token.functions.mint(deposit).call_and_transact({"from": B}) - custom_token.functions.approve(service_registry.address, deposit).call_and_transact( - {"from": B} - ) - service_registry.functions.deposit(deposit).call_and_transact({"from": B}) - assert service_registry.functions.hasValidRegistration(B).call() - amount = 10 expiration = web3.eth.blockNumber + 1 signature = sign_one_to_n_iou( diff --git a/raiden_contracts/tests/test_print_gas.py b/raiden_contracts/tests/test_print_gas.py index acfa91d69..06eb5fbe0 100644 --- a/raiden_contracts/tests/test_print_gas.py +++ b/raiden_contracts/tests/test_print_gas.py @@ -246,10 +246,12 @@ def print_gas_monitoring_service( deposit_to_udc: Callable, print_gas: Callable, get_private_key: Callable, + create_service_account: Callable, ) -> None: """ Abusing pytest to print gas cost of MonitoringService functions """ # setup: two parties + MS - (A, B, MS) = get_accounts(3) + (A, MS) = get_accounts(2) + B = create_service_account() reward_amount = 10 deposit_to_udc(B, reward_amount)