当前位置: 首页>>代码示例>>Python>>正文


Python Munch.receiver_address方法代码示例

本文整理汇总了Python中munch.Munch.receiver_address方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.receiver_address方法的具体用法?Python Munch.receiver_address怎么用?Python Munch.receiver_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在munch.Munch的用法示例。


在下文中一共展示了Munch.receiver_address方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_custom_headers

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import receiver_address [as 别名]
def test_custom_headers(
        session: Session,
        api_endpoint_address: str,
        token_address: str,
        channel_manager_address: str,
        receiver_address: str
):
    session.initial_deposit = lambda x: x

    with requests_mock.mock(real_http=True) as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '7'

        headers2 = Munch()
        headers2.cost = '7'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [
            {'status_code': 402, 'headers': headers1},
            {'status_code': 200, 'headers': headers2, 'text': 'success'}
        ])
        response = session.get(url, headers={
            'someheader': 'somevalue',
            # This should override the actual balance but doesn't actually make sense.
            'RDN-Balance': '5'
        })

    # Filter out any requests made to the ethereum node.
    request_history = [request for request in server_mock.request_history if request.port == 5000]

    # First cycle, request price.
    request = request_history[0]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '5'
    assert request.headers['someheader'] == 'somevalue'

    # Second cycle, pay price.
    request = request_history[1]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '5'
    assert request.headers['someheader'] == 'somevalue'

    assert session.channel.balance == 7
    balance_sig_hex = encode_hex(session.channel.balance_sig)
    assert request.headers['RDN-Balance-Signature'] == balance_sig_hex
    assert session.channel.balance_sig
    assert response.text == 'success'
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:59,代码来源:test_session.py

示例2: test_full_cycle_error_500

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import receiver_address [as 别名]
def test_full_cycle_error_500(
        session: Session,
        api_endpoint_address: str,
        token_address: str,
        channel_manager_address: str,
        receiver_address: str
):
    session.initial_deposit = lambda x: x

    with requests_mock.mock(real_http=True) as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '3'

        headers2 = Munch()
        headers2.cost = '3'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [
            {'status_code': 402, 'headers': headers1},
            {'status_code': 500, 'headers': {}}
        ])
        response = session.get(url)

    # Filter out any requests made to the ethereum node.
    request_history = [request for request in server_mock.request_history if request.port == 5000]

    # First cycle, request price.
    request = request_history[0]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address

    # Second cycle, pay price but receive error.
    request = request_history[1]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '3'

    assert session.channel.balance == 3
    balance_sig_hex = encode_hex(session.channel.balance_sig)
    assert request.headers['RDN-Balance-Signature'] == balance_sig_hex
    assert response.status_code == 500
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:51,代码来源:test_session.py

示例3: test_requests

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import receiver_address [as 别名]
def test_requests(
    patched_contract,
    web3: Web3,
    sender_privkey: str,
    api_endpoint_address: str,
    token_address: str,
    channel_manager_address: str,
    receiver_address: str,
    revert_chain
):
    import microraiden.requests

    with requests_mock.mock(real_http=True) as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '7'

        headers2 = Munch()
        headers2.cost = '7'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [
            {'status_code': 402, 'headers': headers1},
            {'status_code': 200, 'headers': headers2, 'text': 'success'}
        ])
        response = microraiden.requests.get(
            url,
            retry_interval=0.1,
            private_key=sender_privkey,
            web3=web3,
            channel_manager_address=channel_manager_address
        )

    assert response.text == 'success'
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:41,代码来源:test_session.py

示例4: _request_resource

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import receiver_address [as 别名]
    def _request_resource(
            self,
            method: str,
            url: str,
            **kwargs
    ) -> Tuple[Union[None, Response], bool]:
        """
        Performs a simple GET request to the HTTP server with headers representing the given
        channel state.
        """
        headers = Munch()
        headers.contract_address = self.client.context.channel_manager.address
        if self.channel is not None:
            headers.balance = str(self.channel.balance)
            headers.balance_signature = encode_hex(self.channel.balance_sig)
            headers.sender_address = self.channel.sender
            headers.receiver_address = self.channel.receiver
            headers.open_block = str(self.channel.block)

        headers = HTTPHeaders.serialize(headers)
        if 'headers' in kwargs:
            headers.update(kwargs['headers'])
            kwargs['headers'] = headers
        else:
            kwargs['headers'] = headers
        response = requests.Session.request(self, method, url, **kwargs)

        if self.on_http_response(method, url, response, **kwargs) is False:
            return response, False  # user requested abort

        if response.status_code == requests.codes.OK:
            return response, self.on_success(method, url, response, **kwargs)

        elif response.status_code == requests.codes.PAYMENT_REQUIRED:
            if HTTPHeaders.NONEXISTING_CHANNEL in response.headers:
                return response, self.on_nonexisting_channel(method, url, response, **kwargs)

            elif HTTPHeaders.INSUF_CONFS in response.headers:
                return response, self.on_insufficient_confirmations(
                    method,
                    url,
                    response,
                    **kwargs
                )

            elif HTTPHeaders.INVALID_PROOF in response.headers:
                return response, self.on_invalid_balance_proof(method, url, response, **kwargs)

            elif HTTPHeaders.CONTRACT_ADDRESS not in response.headers or not is_same_address(
                response.headers.get(HTTPHeaders.CONTRACT_ADDRESS),
                self.client.context.channel_manager.address
            ):
                return response, self.on_invalid_contract_address(method, url, response, **kwargs)

            elif HTTPHeaders.INVALID_AMOUNT in response.headers:
                return response, self.on_invalid_amount(method, url, response, **kwargs)

            else:
                return response, self.on_payment_requested(method, url, response, **kwargs)
        else:
            return response, self.on_http_error(method, url, response, **kwargs)
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:63,代码来源:session.py

示例5: test_full_cycle_adapt_balance

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import receiver_address [as 别名]
def test_full_cycle_adapt_balance(
        session: Session,
        api_endpoint_address: str,
        token_address: str,
        channel_manager_address: str,
        receiver_address: str
):
    # Simulate a lost balance signature.
    client = session.client
    channel = client.get_suitable_channel(receiver_address, 10, initial_deposit=lambda x: 2 * x)
    channel.create_transfer(3)
    lost_balance_sig = channel.balance_sig
    channel.update_balance(0)

    with requests_mock.mock(real_http=True) as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '7'

        headers2 = headers1.copy()
        headers2.invalid_amount = '1'
        headers2.sender_balance = '3'
        headers2.balance_signature = encode_hex(lost_balance_sig)

        headers3 = Munch()
        headers3.cost = '7'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)
        headers3 = HTTPHeaders.serialize(headers3)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [
            {'status_code': 402, 'headers': headers1},
            {'status_code': 402, 'headers': headers2},
            {'status_code': 200, 'headers': headers3, 'text': 'success'}
        ])

        response = session.get(url)

    # Filter out any requests made to the ethereum node.
    request_history = [request for request in server_mock.request_history if request.port == 5000]

    # First cycle, request price.
    request = request_history[0]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address

    # Second cycle, pay price based on outdated balance.
    request = request_history[1]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '7'
    assert request.headers['RDN-Balance-Signature']

    # Third cycle, adapt new balance and pay price again.
    request = request_history[2]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '10'

    assert session.channel.balance == 10
    balance_sig_hex = encode_hex(session.channel.balance_sig)
    assert request.headers['RDN-Balance-Signature'] == balance_sig_hex
    assert session.channel.balance_sig
    assert response.text == 'success'
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:73,代码来源:test_session.py


注:本文中的munch.Munch.receiver_address方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。