Skip to content

Commit

Permalink
Add a unit test for mediator.secret_learned
Browse files Browse the repository at this point in the history
Test the case where the channel is already closed
  • Loading branch information
jomuel authored and rakanalh committed May 14, 2019
1 parent 9a1d078 commit 26519a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_next_route():
)

# HOP3 should be ignored because it doesn't have enough balance
assert iteration.new_state.cancelled_channels == [channel1.identifier]
assert iteration.new_state.cancelled_channels == [channels[0].identifier]


def test_init_with_usable_routes():
Expand Down
28 changes: 25 additions & 3 deletions raiden/tests/unit/transfer/mediated_transfer/test_mediatorstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,9 @@ def test_events_for_onchain_secretreveal_once():
assert pair.payer_state == "payer_waiting_secret_reveal"


def test_secret_learned():
def secret_learned_setup():
pseudo_random_generator = random.Random()

channels = mediator_make_channel_pair()

from_transfer = factories.make_signed_transfer_for(channels[0])

nodeaddresses_to_networkstates = factories.make_node_availability_map([UNIT_TRANSFER_TARGET])
Expand All @@ -722,6 +720,12 @@ def test_secret_learned():
block_hash=factories.make_block_hash(),
)

return pseudo_random_generator, channels, from_transfer, iteration


def test_secret_learned():
pseudo_random_generator, channels, from_transfer, iteration = secret_learned_setup()

iteration = mediator.secret_learned(
state=iteration.new_state,
channelidentifiers_to_channels=channels.channel_map,
Expand Down Expand Up @@ -794,6 +798,24 @@ def test_secret_learned_with_refund():
assert channel.is_secret_known(setup.channels[2].our_state, UNIT_SECRETHASH)


def test_secret_learned_for_closed_channel():
pseudo_random_generator, channels, _, iteration = secret_learned_setup()
close_transaction = factories.create(factories.TransactionExecutionStatusProperties())
channels[0].close_transaction = close_transaction

iteration = mediator.secret_learned(
state=iteration.new_state,
channelidentifiers_to_channels=channels.channel_map,
pseudo_random_generator=pseudo_random_generator,
block_number=1,
block_hash=factories.make_block_hash(),
secret=UNIT_SECRET,
secrethash=UNIT_SECRETHASH,
payee_address=channels[1].partner_state.address,
)
assert search_for_item(iteration.events, ContractSendSecretReveal, {"secret": UNIT_SECRET})


def test_mediate_transfer():
block_number = 5
pseudo_random_generator = random.Random()
Expand Down
5 changes: 3 additions & 2 deletions raiden/tests/utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
PaymentID,
PaymentNetworkID,
Secret,
SecretHash,
Signature,
TargetAddress,
TokenAddress,
Expand Down Expand Up @@ -267,7 +268,7 @@ def make_merkletree_leaves(width: int) -> List[Keccak256]:
return [make_secret() for _ in range(width)]


def make_merkletree(leaves: List[typing.SecretHash]) -> MerkleTreeState:
def make_merkletree(leaves: List[SecretHash]) -> MerkleTreeState:
return MerkleTreeState(compute_layers(leaves))


Expand Down Expand Up @@ -839,7 +840,7 @@ def make_channel_set(
return ChannelSet(channels, our_pkeys, partner_pkeys)


def make_channel_set_from_amounts(amounts: List[typing.TokenAmount]) -> ChannelSet:
def make_channel_set_from_amounts(amounts: List[TokenAmount]) -> ChannelSet:
properties = [
NettingChannelStateProperties(our_state=NettingChannelEndStateProperties(balance=amount))
for amount in amounts
Expand Down

0 comments on commit 26519a2

Please sign in to comment.