def test_monitor_request(get_random_bp, get_random_privkey, get_random_address):
    balance_proof = get_random_bp()
    client_privkey = get_random_privkey()
    client_address = private_key_to_address(client_privkey)
    balance_proof.signature = encode_hex(sign_data(client_privkey, balance_proof.serialize_bin()))
    monitor_request = MonitorRequest(
        balance_proof,
        non_closing_signature=balance_proof.signature,
        reward_sender_address=client_address,
        reward_proof_signature='',
        reward_amount=1,
        monitor_address=get_random_address()
    )

    serialized = monitor_request.serialize_data()
    monitor_request_verify = MonitorRequest.deserialize(serialized)
    balance_proof_verify = monitor_request_verify.balance_proof
    assert is_same_address(monitor_request_verify.monitor_address, monitor_request.monitor_address)
    assert is_same_address(
        monitor_request_verify.reward_sender_address,
        monitor_request.reward_sender_address
    )
    assert monitor_request_verify.non_closing_signature == monitor_request.non_closing_signature
    assert monitor_request_verify.reward_amount == monitor_request.reward_amount
    assert is_same_address(
        balance_proof_verify.token_network_address,
        balance_proof.token_network_address
    )
    assert balance_proof_verify.chain_id == balance_proof.chain_id
    assert balance_proof_verify.channel_identifier == balance_proof.channel_identifier
    assert balance_proof_verify.nonce == balance_proof.nonce
Example #2
0
def test_serialize_deserialize(get_random_bp, get_random_privkey):
    bp = get_random_bp()
    privkey = get_random_privkey()
    bp.signature = encode_hex(sign_data(privkey, bp.serialize_bin()))
    serialized_message = bp.serialize_full()

    deserialized_message = Message.deserialize(serialized_message)
    assert isinstance(deserialized_message, BalanceProof)