本文整理汇总了Python中eth_utils.ValidationError方法的典型用法代码示例。如果您正苦于以下问题:Python eth_utils.ValidationError方法的具体用法?Python eth_utils.ValidationError怎么用?Python eth_utils.ValidationError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eth_utils
的用法示例。
在下文中一共展示了eth_utils.ValidationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_child_service
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def run_child_service(self, child_service: "BaseService") -> None:
"""
Run a child service and keep a reference to it to be considered during the cleanup.
"""
if child_service.is_running:
raise ValidationError(
"Can't start service {}, child of {}: it's already running".format(
repr(child_service), repr(self)
)
)
elif child_service.is_cancelled:
raise ValidationError(
"Can't restart {}, child of {}: it's already completed".format(
repr(child_service), repr(self)
)
)
self._child_services.add(child_service)
self.run_task(child_service.run())
示例2: test_chain_builder_disable_pow_check
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def test_chain_builder_disable_pow_check():
chain = build(
MiningChain,
frontier_at(0),
disable_pow_check(),
genesis(),
)
block = chain.mine_block()
with pytest.raises(ValidationError, match='mix hash mismatch'):
check_pow(
block.number,
block.header.mining_hash,
block.header.mix_hash,
block.header.nonce,
block.header.difficulty,
)
示例3: test_enr_response_handler_does_not_crash_on_invalid_responses
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def test_enr_response_handler_does_not_crash_on_invalid_responses():
discovery = MockDiscoveryService([])
token = b''
invalid_enr = b'garbage'
payload = [token, invalid_enr]
await discovery.recv_enr_response(discovery.this_node, payload, b'')
enr = ENRFactory()
enr._kv_pairs.pop(b'secp256k1')
with pytest.raises(ValidationError):
ENR.deserialize(ENR.serialize(enr))
payload = [token, ENR.serialize(enr)]
await discovery.recv_enr_response(discovery.this_node, payload, b'')
enr = ENRFactory()
enr._signature = b'garbage'
with pytest.raises(eth_keys.exceptions.ValidationError):
enr.validate_signature()
payload = [token, ENR.serialize(enr)]
await discovery.recv_enr_response(discovery.this_node, payload, b'')
示例4: wait_tip_info
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def wait_tip_info(self) -> AsyncIterator[BaseChainPeer]:
"""
This iterator waits until there is potentially new tip information.
New tip information means a new peer connected or a new block arrived.
Then it yields the peer with the highest total difficulty.
It continues indefinitely, until this service is cancelled.
"""
if self.manager.is_cancelled:
raise ValidationError("%s is cancelled, new tip info is impossible", self)
elif not self.manager.is_running:
await self.manager.wait_started()
with self._subscriber() as new_tip_event:
while self.manager.is_running:
try:
highest_td_peer = self._peer_pool.highest_td_peer
except NoConnectedPeers:
# no peers are available right now, skip the new tip info yield
pass
else:
yield highest_td_peer
await new_tip_event.wait()
new_tip_event.clear()
示例5: _get_tip_header
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def _get_tip_header(self) -> BlockHeader:
try:
headers = await self.peer.chain_api.get_block_headers(
self.peer.head_info.head_hash,
max_headers=1,
timeout=CHAIN_SPLIT_CHECK_TIMEOUT,
)
except (asyncio.TimeoutError, PeerConnectionLost) as err:
raise DAOForkCheckFailure(
f"Timed out waiting for tip header from {self.peer}: {err}"
) from err
except ValidationError as err:
raise DAOForkCheckFailure(
f"Invalid header response for tip header during DAO fork check: {err}"
) from err
else:
if len(headers) != 1:
raise DAOForkCheckFailure(
f"{self.peer} returned {headers!r} when asked for tip"
)
else:
return headers[0]
示例6: send_get_block_headers
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def send_get_block_headers(
self,
block_number_or_hash: Union[BlockNumber, Hash32],
max_headers: int,
skip: int,
reverse: bool) -> int:
if max_headers > MAX_HEADERS_FETCH:
raise ValidationError(
f"Cannot ask for more than {MAX_HEADERS_FETCH} headers in a single request"
)
query = BlockHeadersQuery(
block_number_or_hash=block_number_or_hash,
max_headers=max_headers,
skip=skip,
reverse=reverse,
)
payload = GetBlockHeadersPayload(
request_id=gen_request_id(),
query=query,
)
self.protocol.send(GetBlockHeaders(payload))
return payload.request_id
示例7: _get_new_root
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def _get_new_root(self, node_id: TNodeID, parent_id: TNodeID) -> Tuple[TreeRoot[TNodeID], int]:
if self._tree.has_parent(node_id):
try:
parent_root = self._roots[parent_id]
except KeyError as e:
tree_parent = self._tree.parent_of(node_id)
raise ValidationError(
f"When adding node {node_id} with parent {parent_id}, The tree says that "
f"parent {tree_parent} is present, but the parent is missing from roots."
) from e
if len(self._tree.children_of(parent_id)) > 1:
node_root = TreeRoot(node_id)
node_root.extend(parent_root, 0)
else:
node_root = parent_root
original_depth = self._original_depth_to_root[parent_id] + 1
else:
node_root = TreeRoot(node_id)
original_depth = 0
return node_root, original_depth
示例8: _link_children
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def _link_children(
self,
parent_root: TreeRoot[TNodeID],
parent_original_depth: int,
children: Tuple[TNodeID, ...]) -> None:
for child in children:
child_root = self._roots[child]
if child_root.depth_offset + self._original_depth_to_root[child] != 0:
raise ValidationError(
"children without parents must have net depth 0: "
f"but offset was {child_root.depth_offset} and original depth "
f"was {self._original_depth_to_root[child]}."
)
else:
# original depth was 0, needs to be adjusted based on parent's original depth
ideal_original_depth = parent_original_depth + 1
actual_original_depth = self._original_depth_to_root[child]
# extension length = ideal - actual = ideal - 0
child_root.extend(parent_root, ideal_original_depth - actual_original_depth)
示例9: run_import
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def run_import(cls, args: Namespace, trinity_config: TrinityConfig) -> None:
with open(args.file_path, 'rb') as import_file:
# This won't handle large files.
# TODO: Make this stream based: https://github.com/ethereum/trinity/issues/1282
file_bytes = import_file.read()
blocks = decode_all(file_bytes, sedes=FrontierBlock)
cls.logger.info("Importing %s blocks", len(blocks))
chain = get_chain(trinity_config)
for block in blocks:
try:
chain.import_block(block)
except (EVMMissingData, ValidationError) as exc:
cls.logger.error(exc)
cls.logger.error("Import failed")
else:
cls.logger.info("Successfully imported %s", block)
示例10: handle_slot_tick
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def handle_slot_tick(self) -> None:
"""
The callback for `SlotTicker` and it's expected to be called twice for one slot.
"""
async for event in self.event_bus.stream(SlotTickEvent):
try:
self._check_and_update_data_per_slot(event.slot)
if event.tick_type.is_start:
await self.handle_first_tick(event.slot)
elif event.tick_type.is_one_third:
await self.handle_second_tick(event.slot)
elif event.tick_type.is_two_third:
await self.handle_third_tick(event.slot)
except ValidationError as e:
self.logger.warn("%s", e)
self.logger.warn(
"SHOULD NOT GET A VALIDATION ERROR"
" HERE AS IT IS INTERNAL TO OUR OWN CODE"
)
示例11: handle_slot_tick
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def handle_slot_tick(self) -> None:
"""
The callback for `SlotTicker` and it's expected to be called twice for one slot.
"""
async for event in self.event_bus.stream(SlotTickEvent):
try:
self._check_and_update_data_per_slot(event.slot)
if event.tick_type.is_start:
pass
elif event.tick_type.is_one_third:
await self.handle_second_tick(event.slot)
elif event.tick_type.is_two_third:
pass
except ValidationError as e:
self.logger.warn("%s", e)
self.logger.warn(
"SHOULD NOT GET A VALIDATION ERROR"
" HERE AS IT IS INTERNAL TO OUR OWN CODE"
)
示例12: apply
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def apply(self, connection: ConnectionAPI) -> AsyncIterator[asyncio.Future[None]]:
if self._applied_to is not None:
raise ValidationError(
f"Reentrance: Behavior has already been applied to a "
f"connection: {self._applied_to}"
)
else:
# this acts as re-entrance protection for for the `Behavior` instance.
self._applied_to = connection
if hasattr(self.logic, '_behavior'):
raise ValidationError(
f"Reentrance: Logic already bound to a behavior: "
f"{self.logic._behavior}"
)
else:
# this acts as re-entrance protection on the actual `LogicAPI` instance
self.logic._behavior = self
# once the logic is bound to the connection we enter it's context.
async with self.logic.apply(connection) as task:
yield task
示例13: test_validate_attestation_slot
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def test_validate_attestation_slot(
attestation_slot,
state_slot,
slots_per_epoch,
min_attestation_inclusion_delay,
is_valid,
):
if is_valid:
validate_attestation_slot(
attestation_slot,
state_slot,
slots_per_epoch,
min_attestation_inclusion_delay,
)
else:
with pytest.raises(ValidationError):
validate_attestation_slot(
attestation_slot,
state_slot,
slots_per_epoch,
min_attestation_inclusion_delay,
)
示例14: test_validate_validator_has_not_exited
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def test_validate_validator_has_not_exited(
genesis_state, validator_exit_epoch, success
):
state = genesis_state
validator_index = 0
validator = state.validators[validator_index].set(
"exit_epoch", validator_exit_epoch
)
if success:
_validate_validator_has_not_exited(validator)
else:
with pytest.raises(ValidationError):
_validate_validator_has_not_exited(validator)
示例15: test_validate_voluntary_exit_signature
# 需要导入模块: import eth_utils [as 别名]
# 或者: from eth_utils import ValidationError [as 别名]
def test_validate_voluntary_exit_signature(genesis_state, keymap, config, success):
slots_per_epoch = config.SLOTS_PER_EPOCH
state = genesis_state
validator_index = 0
voluntary_exit = create_mock_voluntary_exit(state, config, keymap, validator_index)
validator = state.validators[validator_index]
if success:
_validate_voluntary_exit_signature(
state, voluntary_exit, validator, slots_per_epoch
)
else:
# Use wrong signature
voluntary_exit = voluntary_exit.set(
"signature", b"\x12" * 96
) # wrong signature
with pytest.raises(ValidationError):
_validate_voluntary_exit_signature(
state, voluntary_exit, validator, slots_per_epoch
)