Skip to content

Commit

Permalink
Remvoe the repetition of ServiceRegistry registers
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Aug 13, 2019
1 parent dcd0c33 commit 9953700
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
20 changes: 20 additions & 0 deletions raiden_contracts/tests/fixtures/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 8 additions & 26 deletions raiden_contracts/tests/test_one_to_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,22 @@ 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
amount = 10
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
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion raiden_contracts/tests/test_print_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 9953700

Please sign in to comment.