Skip to content

Commit

Permalink
Refactor service registration in a test
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Aug 15, 2019
1 parent afdc800 commit b62ac28
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions raiden_contracts/tests/test_print_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,28 +316,18 @@ def print_gas_monitoring_service(
def print_gas_one_to_n(
one_to_n_contract: Contract,
deposit_to_udc: Callable,
get_accounts: Callable,
print_gas: Callable,
make_iou: Callable,
service_registry: Contract,
custom_token: Contract,
web3: Web3,
get_private_key: Callable,
create_service_account: Callable,
create_account: Callable,
) -> None:
""" Abusing pytest to print gas cost of OneToN functions """
(A, B) = get_accounts(2)
A = create_account()
B = create_service_account()
deposit_to_udc(A, 30)

# 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()

# happy case
chain_id = int(web3.version.network)
amount = 10
Expand Down Expand Up @@ -421,16 +411,17 @@ def print_gas_user_deposit(

@pytest.fixture
def print_gas_service_registry(
get_accounts: Callable, custom_token: Contract, service_registry: Contract, print_gas: Callable
custom_token: Contract,
service_registry: Contract,
print_gas: Callable,
create_account: Callable,
) -> None:
(A,) = get_accounts(1)
A = create_account()
deposit = service_registry.functions.currentPrice().call()
custom_token.functions.mint(deposit).call_and_transact({"from": A})
custom_token.functions.ming(deposit).call_and_transact({"from": A})
custom_token.functions.approve(service_registry.address, deposit).call_and_transact(
{"from": A}
)

# happy path
deposit_tx = service_registry.functions.deposit(deposit).call_and_transact({"from": A})
print_gas(deposit_tx, CONTRACT_SERVICE_REGISTRY + ".deposit")
url = "http://example.com"
Expand Down

0 comments on commit b62ac28

Please sign in to comment.