|
4 | 4 | from raiden.constants import UINT64_MAX |
5 | 5 | from raiden.tests.utils import factories |
6 | 6 | from raiden.transfer import channel, token_network |
7 | | -from raiden.transfer.state_change import ContractReceiveChannelNew |
| 7 | +from raiden.transfer.state_change import ( |
| 8 | + ContractReceiveChannelClosed, |
| 9 | + ContractReceiveChannelNew, |
| 10 | + ContractReceiveChannelSettled, |
| 11 | +) |
8 | 12 | from raiden.transfer.state import TokenNetworkState |
9 | 13 |
|
10 | 14 |
|
@@ -56,3 +60,58 @@ def test_contract_receive_channelnew_must_be_idempotent(): |
56 | 60 |
|
57 | 61 | channelmap_by_address = iteration.new_state.partneraddresses_to_channels |
58 | 62 | assert channelmap_by_address[channel_state1.partner_state.address] == channel_state1, msg |
| 63 | + |
| 64 | + |
| 65 | +def test_channel_settle_must_properly_cleanup(): |
| 66 | + open_block_number = 10 |
| 67 | + pseudo_random_generator = random.Random() |
| 68 | + |
| 69 | + token_network_id = factories.make_address() |
| 70 | + token_id = factories.make_address() |
| 71 | + token_network_state = TokenNetworkState(token_network_id, token_id) |
| 72 | + |
| 73 | + amount = 30 |
| 74 | + our_balance = amount + 50 |
| 75 | + channel_state = factories.make_channel(our_balance=our_balance) |
| 76 | + |
| 77 | + channel_new_state_change = ContractReceiveChannelNew(token_network_id, channel_state) |
| 78 | + |
| 79 | + channel_new_iteration = token_network.state_transition( |
| 80 | + token_network_state, |
| 81 | + channel_new_state_change, |
| 82 | + pseudo_random_generator, |
| 83 | + open_block_number, |
| 84 | + ) |
| 85 | + |
| 86 | + closed_block_number = open_block_number + 10 |
| 87 | + channel_close_state_change = ContractReceiveChannelClosed( |
| 88 | + token_network_id, |
| 89 | + channel_state.identifier, |
| 90 | + channel_state.partner_state.address, |
| 91 | + closed_block_number, |
| 92 | + ) |
| 93 | + |
| 94 | + channel_closed_iteration = token_network.state_transition( |
| 95 | + channel_new_iteration.new_state, |
| 96 | + channel_close_state_change, |
| 97 | + pseudo_random_generator, |
| 98 | + closed_block_number, |
| 99 | + ) |
| 100 | + |
| 101 | + settle_block_number = closed_block_number + channel_state.settle_timeout + 1 |
| 102 | + channel_settled_state_change = ContractReceiveChannelSettled( |
| 103 | + token_network_id, |
| 104 | + channel_state.identifier, |
| 105 | + settle_block_number, |
| 106 | + ) |
| 107 | + |
| 108 | + channel_settled_iteration = token_network.state_transition( |
| 109 | + channel_closed_iteration.new_state, |
| 110 | + channel_settled_state_change, |
| 111 | + pseudo_random_generator, |
| 112 | + closed_block_number, |
| 113 | + ) |
| 114 | + |
| 115 | + token_network_state_after_settle = channel_settled_iteration.new_state |
| 116 | + ids_to_channels = token_network_state_after_settle.channelidentifiers_to_channels |
| 117 | + assert channel_state.identifier not in ids_to_channels |
0 commit comments