本文整理汇总了Python中munch.Munch.cost方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.cost方法的具体用法?Python Munch.cost怎么用?Python Munch.cost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类munch.Munch
的用法示例。
在下文中一共展示了Munch.cost方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_headers
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import cost [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'
示例2: test_full_cycle_error_500
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import cost [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
示例3: test_requests
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import cost [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'
示例4: test_full_cycle_adapt_balance
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import cost [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'