Skip to content

Commit

Permalink
replace Function Mapping by singledispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cezar Bernardelli committed Aug 2, 2021
1 parent 32c55c7 commit 4d45b86
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 232 deletions.
70 changes: 35 additions & 35 deletions raiden/tests/unit/test_channelstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ def test_channelstate_unlock_without_locks():
block_number=77,
block_hash=make_block_hash(),
)
iteration = channel.handle_channel_closed(channel_state, state_change)
iteration = channel._handle_channel_closed(state_change, channel_state)
assert not iteration.events


Expand Down Expand Up @@ -1313,7 +1313,7 @@ def test_channelstate_unlock_unlocked_onchain():
block_number=closed_block_number,
block_hash=closed_block_hash,
)
iteration = channel.handle_channel_closed(channel_state, close_state_change)
iteration = channel._handle_channel_closed(close_state_change, channel_state)
assert search_for_item(iteration.events, ContractSendChannelBatchUnlock, {}) is None

settle_block_number = lock_expiration + channel_state.reveal_timeout + 1
Expand All @@ -1329,7 +1329,7 @@ def test_channelstate_unlock_unlocked_onchain():
our_onchain_locksroot=LOCKSROOT_OF_NO_LOCKS,
)

iteration = channel.handle_channel_settled(channel_state, settle_state_change)
iteration = channel._handle_channel_settled(settle_state_change, channel_state)
assert search_for_item(iteration.events, ContractSendChannelBatchUnlock, {}) is not None


Expand Down Expand Up @@ -1424,7 +1424,7 @@ def test_update_must_be_called_if_close_lost_race():
block_number=77,
block_hash=make_block_hash(),
)
iteration = channel.handle_channel_closed(channel_state, state_change)
iteration = channel._handle_channel_closed(state_change, channel_state)
assert search_for_item(iteration.events, ContractSendChannelUpdateTransfer, {}) is not None


Expand Down Expand Up @@ -1461,7 +1461,7 @@ def test_update_transfer():
block_number=closed_block_number,
block_hash=closed_block_hash,
)
iteration2 = channel.handle_channel_closed(channel_state, channel_close_state_change)
iteration2 = channel._handle_channel_closed(channel_close_state_change, channel_state)

# update_transaction in channel state should not be set because there was no transfer
channel_state = iteration2.new_state
Expand All @@ -1476,8 +1476,8 @@ def test_update_transfer():
)

update_block_number = 20
iteration3 = channel.handle_channel_updated_transfer(
channel_state, update_transfer_state_change, update_block_number
iteration3 = channel._handle_channel_updated_transfer(
update_transfer_state_change, channel_state, update_block_number
)

# now update_transaction in channel state should be set
Expand Down Expand Up @@ -1591,9 +1591,9 @@ def test_action_withdraw():
canonical_identifier=channel_state.canonical_identifier, total_withdraw=100
)

iteration = channel.handle_action_withdraw(
iteration = channel._handle_action_withdraw(
channel_state=channel_state,
action_withdraw=action_withdraw,
action=action_withdraw,
pseudo_random_generator=pseudo_random_generator,
block_number=2,
)
Expand All @@ -1608,9 +1608,9 @@ def test_action_withdraw():
canonical_identifier=channel_state.canonical_identifier, total_withdraw=our_balance
)

iteration = channel.handle_action_withdraw(
iteration = channel._handle_action_withdraw(
channel_state=channel_state,
action_withdraw=action_withdraw,
action=action_withdraw,
pseudo_random_generator=pseudo_random_generator,
block_number=3,
)
Expand All @@ -1626,9 +1626,9 @@ def test_action_withdraw():
canonical_identifier=channel_state.canonical_identifier, total_withdraw=our_balance
)

iteration = channel.handle_action_withdraw(
iteration = channel._handle_action_withdraw(
channel_state=iteration.new_state,
action_withdraw=action_withdraw,
action=action_withdraw,
pseudo_random_generator=pseudo_random_generator,
block_number=4,
)
Expand Down Expand Up @@ -1664,8 +1664,8 @@ def test_receive_withdraw_request():
expiration=expiration,
)

iteration = channel.handle_receive_withdraw_request(
channel_state=channel_state, withdraw_request=withdraw_request
iteration = channel._handle_receive_withdraw_request(
channel_state=channel_state, action=withdraw_request
)

assert (
Expand Down Expand Up @@ -1698,8 +1698,8 @@ def test_receive_withdraw_request():
expiration=expiration,
)

iteration = channel.handle_receive_withdraw_request(
channel_state=channel_state, withdraw_request=withdraw_request
iteration = channel._handle_receive_withdraw_request(
channel_state=channel_state, action=withdraw_request
)

# pylint: disable=no-member
Expand All @@ -1724,8 +1724,8 @@ def test_receive_withdraw_request():
expiration=10,
)

iteration = channel.handle_receive_withdraw_request(
channel_state=iteration.new_state, withdraw_request=withdraw_request
iteration = channel._handle_receive_withdraw_request(
channel_state=iteration.new_state, action=withdraw_request
)

assert (
Expand All @@ -1749,8 +1749,8 @@ def test_receive_withdraw_request():
expiration=10,
)

iteration = channel.handle_receive_withdraw_request(
channel_state=iteration.new_state, withdraw_request=withdraw_request
iteration = channel._handle_receive_withdraw_request(
channel_state=iteration.new_state, action=withdraw_request
)

assert (
Expand Down Expand Up @@ -1803,9 +1803,9 @@ def test_receive_withdraw_confirmation():
expiration=expiration_block,
)

iteration = channel.handle_receive_withdraw_confirmation(
iteration = channel._handle_receive_withdraw_confirmation(
channel_state=channel_state,
withdraw=receive_withdraw,
action=receive_withdraw,
block_number=10,
block_hash=block_hash,
)
Expand All @@ -1830,9 +1830,9 @@ def test_receive_withdraw_confirmation():
expiration=expiration_block,
)

iteration = channel.handle_receive_withdraw_confirmation(
iteration = channel._handle_receive_withdraw_confirmation(
channel_state=iteration.new_state,
withdraw=receive_withdraw,
action=receive_withdraw,
block_number=10,
block_hash=block_hash,
)
Expand All @@ -1855,9 +1855,9 @@ def test_receive_withdraw_confirmation():
expiration=expiration_block,
)

iteration = channel.handle_receive_withdraw_confirmation(
iteration = channel._handle_receive_withdraw_confirmation(
channel_state=iteration.new_state,
withdraw=receive_withdraw,
action=receive_withdraw,
block_number=10,
block_hash=block_hash,
)
Expand Down Expand Up @@ -1891,9 +1891,9 @@ def test_node_sends_withdraw_expiry():
block_hash = make_transaction_hash()
block = Block(block_number=expiration_threshold - 1, gas_limit=1, block_hash=block_hash)

iteration = channel.handle_block(
iteration = channel._handle_block(
channel_state=channel_state,
state_change=block,
action=block,
block_number=expiration_threshold - 1,
pseudo_random_generator=pseudo_random_generator,
)
Expand All @@ -1903,9 +1903,9 @@ def test_node_sends_withdraw_expiry():
block_hash = make_transaction_hash()
block = Block(block_number=expiration_threshold, gas_limit=1, block_hash=block_hash)

iteration = channel.handle_block(
iteration = channel._handle_block(
channel_state=channel_state,
state_change=block,
action=block,
block_number=expiration_threshold,
pseudo_random_generator=pseudo_random_generator,
)
Expand Down Expand Up @@ -2210,8 +2210,8 @@ def test_receive_contract_withdraw():
fee_config=MediationFeeConfig(),
)

iteration = channel.handle_channel_withdraw(
channel_state=channel_state, state_change=contract_receive_withdraw
iteration = channel._handle_channel_withdraw(
channel_state=channel_state, action=contract_receive_withdraw
)

assert iteration.new_state.our_state.offchain_total_withdraw == 0
Expand All @@ -2232,8 +2232,8 @@ def test_receive_contract_withdraw():
fee_config=MediationFeeConfig(),
)

iteration = channel.handle_channel_withdraw(
channel_state=iteration.new_state, state_change=contract_receive_withdraw
iteration = channel._handle_channel_withdraw(
channel_state=iteration.new_state, action=contract_receive_withdraw
)

assert iteration.new_state.partner_state.offchain_total_withdraw == 0
Expand Down
12 changes: 7 additions & 5 deletions raiden/tests/unit/transfer/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
compute_locksroot,
get_secret,
get_status,
handle_block,
handle_receive_lockedtransfer,
handle_state_transitions,
is_balance_proof_usable_onchain,
is_valid_balanceproof_signature,
set_settled,
Expand Down Expand Up @@ -357,20 +357,22 @@ def test_handle_block_closed_channel():
)
pseudo_random_generator = random.Random()
block = Block(block_number=90, gas_limit=100000, block_hash=factories.make_block_hash())
before_settle = handle_block(
before_settle = handle_state_transitions(
block,
channel_state=channel_state,
state_change=block,
block_number=block.block_number,
block_hash=None,
pseudo_random_generator=pseudo_random_generator,
)
assert get_status(before_settle.new_state) == ChannelState.STATE_CLOSED
assert not before_settle.events

block = Block(block_number=102, gas_limit=100000, block_hash=factories.make_block_hash())
after_settle = handle_block(
after_settle = handle_state_transitions(
block,
channel_state=before_settle.new_state,
state_change=block,
block_number=block.block_number,
block_hash=None,
pseudo_random_generator=pseudo_random_generator,
)
assert get_status(after_settle.new_state) == ChannelState.STATE_SETTLING
Expand Down
Loading

0 comments on commit 4d45b86

Please sign in to comment.