コード例 #1
0
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
コード例 #2
0
    def get_monitor_requests(
        self,
        channel_identifier: ChannelIdentifier = None,
        non_closing_signer: Address = None,
    ) -> Dict[tuple, MonitorRequest]:
        """ Return MRs keyed by (channel_id, non_closing_signer), optionally filtered """
        mr_rows = self.get_monitor_request_rows(channel_identifier,
                                                non_closing_signer)

        return {
            (x['channel_identifier'], x['non_closing_signer']): MonitorRequest(
                balance_proof=BalanceProof(
                    channel_identifier=x['channel_identifier'],
                    token_network_address=x['token_network_address'],
                    balance_hash=x['balance_hash'],
                    nonce=x['nonce'],
                    additional_hash=x['additional_hash'],
                    chain_id=self.chain_id(),
                    signature=x['closing_signature'],
                ),
                non_closing_signature=x['non_closing_signature'],
                reward_proof_signature=x['reward_proof_signature'],
                reward_amount=x['reward_amount'],
                # Monitor address is not used, but required for now, see
                # https://github.com/raiden-network/raiden-monitoring-service/issues/42
                monitor_address='0x' + '0' * 40,
            )
            for x in mr_rows
        }
コード例 #3
0
 def get_monitor_request(self, partner_address: Address,
                         balance_proof: BalanceProof, reward_amount: int,
                         monitor_address: Address) -> MonitorRequest:
     """Get monitor request message for a given balance proof."""
     monitor_request = MonitorRequest(balance_proof,
                                      reward_proof_signature=None,
                                      reward_amount=reward_amount,
                                      monitor_address=monitor_address)
     monitor_request.reward_proof_signature = encode_hex(
         sign_data(self.privkey, monitor_request.serialize_reward_proof()))
     non_closing_data = balance_proof.serialize_bin() + decode_hex(
         balance_proof.signature)
     monitor_request.non_closing_signature = encode_hex(
         sign_data(self.privkey, non_closing_data))
     return monitor_request
コード例 #4
0
    def f():
        balance_proof = get_random_bp()
        privkey = get_random_privkey()
        privkey_non_closing = get_random_privkey()
        balance_proof.signature = encode_hex(
            sign_data(privkey, balance_proof.serialize_bin()))
        non_closing_signature = encode_hex(
            sign_data(privkey_non_closing, balance_proof.serialize_bin()))

        monitor_request = MonitorRequest(balance_proof,
                                         non_closing_signature,
                                         reward_amount=random.randint(
                                             0, UINT192_MAX),
                                         monitor_address=get_random_address())
        monitor_request.reward_proof_signature = encode_hex(
            sign_data(privkey, monitor_request.serialize_reward_proof()))
        return monitor_request
コード例 #5
0
 def f():
     bp = get_random_bp()
     privkey = get_random_privkey()
     bp.signature = encode_hex(sign_data(privkey, bp.serialize_bin()))
     mr = MonitorRequest(
         bp.channel_id,
         bp.nonce,
         bp.transferred_amount,
         bp.locksroot,
         bp.extra_hash,
         bp.signature,
         reward_sender_address=get_random_address(),
         reward_amount=random.randint(0, UINT192_MAX),
         token_network_address=get_random_address(),
         chain_id=random.randint(0, UINT256_MAX),
         monitor_address=get_random_address()
     )
     mr.reward_proof_signature = encode_hex(sign_data(privkey, mr.serialize_reward_proof()))
     return mr
コード例 #6
0
    def f(
        user=None,
        reward_amount=0,
        bad_key_for_bp=False,
        bad_key_for_non_closing=False,
    ):
        if user == 0:
            privkey = keys[0]
            privkey_non_closing = keys[1]
        else:
            privkey = keys[1]
            privkey_non_closing = keys[0]
        balance_proof = BalanceProof(
            channel_id,
            token_network_address,
            balance_hash=encode_hex(sha3(balance_hash_data.encode())),
        )
        balance_proof.signature = encode_hex(
            eth_sign(
                privkey if not bad_key_for_bp else keys[2],
                balance_proof.serialize_bin(),
            ))
        non_closing_signature = encode_hex(
            eth_sign(
                privkey_non_closing
                if not bad_key_for_non_closing else keys[2],
                balance_proof.serialize_bin(
                    msg_type=MessageTypeId.BALANCE_PROOF_UPDATE) +
                decode_hex(balance_proof.signature),
            ))

        monitor_request = MonitorRequest(
            balance_proof,
            non_closing_signature,
            reward_amount=reward_amount,
            monitor_address=get_random_address(),
        )
        monitor_request.reward_proof_signature = encode_hex(
            eth_sign(privkey, monitor_request.serialize_reward_proof()), )
        return monitor_request