Exemplo n.º 1
0
def test_close_valid_tranfer_different_token(tester_state,
                                             tester_nettingcontracts,
                                             token_amount, tester_events):
    """ Valid messages from a different channel must be rejected. """
    pkey0, pkey1, nettingchannel = tester_nettingcontracts[0]

    from raiden.tests.fixtures.tester import (
        tester_token,
        tester_token_address,
    )

    private_keys = [pkey0, pkey1]
    other_token = tester_token(
        token_amount,
        private_keys,
        tester_state,
        tester_token_address(private_keys, token_amount, tester_state),
        tester_events,
    )

    opened_block = nettingchannel.opened(sender=pkey0)
    nonce = 1 + (opened_block * (2**32))
    direct_transfer_other_token = make_direct_transfer(
        nonce=nonce,
        token=other_token.address,
    )

    address = privatekey_to_address(pkey0)
    sign_key = PrivateKey(pkey0)
    direct_transfer_other_token.sign(sign_key, address)

    direct_transfer_data = direct_transfer_other_token.encode()

    with pytest.raises(TransactionFailed):
        nettingchannel.close(direct_transfer_data, sender=pkey1)
def test_close_valid_tranfer_different_token(
        tester_chain,
        tester_nettingcontracts,
        token_amount,
        tester_events):
    """ Valid messages from a different channel must be rejected. """
    pkey0, pkey1, nettingchannel = tester_nettingcontracts[0]

    from raiden.tests.fixtures.tester import (
        tester_token,
        tester_token_address,
    )

    private_keys = [pkey0, pkey1]
    other_token = tester_token(
        token_amount,
        private_keys,
        tester_chain,
        tester_token_address(private_keys, token_amount, tester_chain),
        tester_events,
    )

    opened_block = nettingchannel.opened(sender=pkey0)
    nonce = 1 + (opened_block * (2 ** 32))
    direct_transfer_other_token = make_direct_transfer(
        nonce=nonce,
        token=other_token.address,
    )

    address = privatekey_to_address(pkey0)
    sign_key = PrivateKey(pkey0)
    direct_transfer_other_token.sign(sign_key, address)

    direct_transfer_other_token_hash = sha3(direct_transfer_other_token.encode()[:-65])
    with pytest.raises(TransactionFailed):
        nettingchannel.close(
            direct_transfer_other_token.nonce,
            direct_transfer_other_token.transferred_amount,
            direct_transfer_other_token.locksroot,
            direct_transfer_other_token_hash,
            direct_transfer_other_token.signature,
            sender=pkey1,
        )