コード例 #1
0
ファイル: datastructures.py プロジェクト: sjyi/py-evm
 def _find_oldest_unpruned_task_id(self, finished_task_id: TTaskID) -> TTaskID:
     get_dependency_of_id = compose(
         curry(do)(self._validate_has_task),
         self._dependency_of,
         attrgetter('task'),
         self._tasks.get,
     )
     ancestors = iterate(get_dependency_of_id, finished_task_id)
     return nth(self._max_depth, ancestors)
コード例 #2
0
ファイル: datastructures.py プロジェクト: vardan10/py-evm
    def _prune_forward(self, root_id: TTaskID, depth: int) -> Tuple[TTaskID]:
        """
        Prune all forks forward from the root
        """
        def prune_parent(prune_task_id: TTaskID) -> Set[TTaskID]:
            children = self._dependencies.pop(prune_task_id, set())
            del self._tasks[prune_task_id]
            if prune_task_id in self._declared_finished:
                self._declared_finished.remove(prune_task_id)
            return children

        prune_parent_list = compose(tuple, curry(mapcat)(prune_parent))
        prune_trunk = repeat(prune_parent_list, depth)
        return pipe((root_id, ), *prune_trunk)
コード例 #3
0
    to_canonical_address,
    to_checksum_address,
    to_dict,
    to_hex,
    to_int,
    to_list,
    to_normalized_address,
    to_ordered_dict,
    to_set,
    to_text,
    to_tuple,
    to_wei,
    ValidationError,
)

apply_formatter_at_index = curry(apply_formatter_at_index)
apply_formatter_if = curry(apply_formatter_if)
apply_formatter_to_array = curry(apply_formatter_to_array)
apply_formatters_to_dict = curry(apply_formatters_to_dict)
apply_formatters_to_sequence = curry(apply_formatters_to_sequence)
apply_key_map = curry(apply_key_map)
apply_one_of_formatters = curry(apply_one_of_formatters)
from_wei = curry(from_wei)
hexstr_if_str = curry(hexstr_if_str)
is_same_address = curry(is_same_address)
text_if_str = curry(text_if_str)
to_wei = curry(to_wei)
clamp = curry(clamp)

del curry
コード例 #4
0
ファイル: test_task_queue.py プロジェクト: wangroot/trinity
    q = TaskQueue(order_fn=order_fn)

    # this just needs to not crash, when testing sortability
    await wait(q.add((1, )))


@pytest.mark.asyncio
@pytest.mark.parametrize(
    'order_fn',
    (
        # a basic object is not sortable
        lambda x: object(),
        # If comparison rules create an invalid result (like an element not equal to itself), crash.
        # The following are subclasses of SortableInt that have an intentionally broken comparitor:
        type('invalid_eq', (SortableInt, ),
             dict(__eq__=curry(complement(SortableInt.__eq__)))),
        type('invalid_lt', (SortableInt, ),
             dict(__lt__=curry(complement(SortableInt.__lt__)))),
        type('invalid_gt', (SortableInt, ),
             dict(__gt__=curry(complement(SortableInt.__gt__)))),
    ),
)
async def test_invalid_priority_order(order_fn):
    q = TaskQueue(order_fn=order_fn)

    with pytest.raises(ValidationError):
        await wait(q.add((1, )))


@pytest.mark.asyncio
async def test_cannot_add_single_non_tuple_task():
コード例 #5
0

@pytest.fixture()
def string_contract(w3, StringContract, address_conversion_func):
    deploy_txn = StringContract.constructor("Caqalai").transact()
    deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
    assert deploy_receipt is not None
    contract_address = address_conversion_func(
        deploy_receipt['contractAddress'])
    contract = StringContract(address=contract_address)
    assert contract.address == contract_address
    assert len(w3.eth.get_code(contract.address)) > 0
    return contract


map_repr = compose(list, curry(map, repr))


@pytest.mark.parametrize(
    'method,args,repr_func,expected',
    (
        ('all_functions', (), map_repr, [
            '<Function blockHashAmphithyronVersify(uint256)>',
            '<Function identity(uint256,bool)>',
            '<Function identity(int256,bool)>'
        ]),
        ('get_function_by_signature', ('identity(uint256,bool)', ), repr,
         '<Function identity(uint256,bool)>'),
        ('find_functions_by_name', ('identity', ), map_repr, [
            '<Function identity(uint256,bool)>',
            '<Function identity(int256,bool)>'
コード例 #6
0
async def test_valid_priority_order(order_fn):
    q = TaskQueue(order_fn=order_fn)

    # this just needs to not crash, when testing sortability
    await wait(q.add((1, )))


@pytest.mark.asyncio
@pytest.mark.parametrize(
    'order_fn',
    (
        # a basic object is not sortable
        lambda x: object(),
        # If comparison rules create an invalid result (like an element not equal to itself), crash.
        # The following are subclasses of SortableInt that have an intentionally broken comparitor:
        type('invalid_eq', (SortableInt, ), dict(__eq__=curry(complement(SortableInt.__eq__)))),
        type('invalid_lt', (SortableInt, ), dict(__lt__=curry(complement(SortableInt.__lt__)))),
        type('invalid_gt', (SortableInt, ), dict(__gt__=curry(complement(SortableInt.__gt__)))),
    ),
)
async def test_invalid_priority_order(order_fn):
    q = TaskQueue(order_fn=order_fn)

    with pytest.raises(ValidationError):
        await wait(q.add((1, )))


@pytest.mark.asyncio
async def test_cannot_add_single_non_tuple_task():
    q = TaskQueue()
    with pytest.raises(ValidationError):
コード例 #7
0
    to_canonical_address,
    to_checksum_address,
    to_dict,
    to_hex,
    to_int,
    to_list,
    to_normalized_address,
    to_ordered_dict,
    to_set,
    to_text,
    to_tuple,
    to_wei,
)
from eth_utils.toolz import curry

apply_formatter_at_index = curry(apply_formatter_at_index)
apply_formatter_if = curry(apply_formatter_if)
apply_formatter_to_array = curry(apply_formatter_to_array)
apply_formatters_to_dict = curry(apply_formatters_to_dict)
apply_formatters_to_sequence = curry(apply_formatters_to_sequence)
apply_key_map = curry(apply_key_map)
apply_one_of_formatters = curry(apply_one_of_formatters)
from_wei = curry(from_wei)
get_logger = curry(get_logger)
hexstr_if_str = curry(hexstr_if_str)
is_same_address = curry(is_same_address)
text_if_str = curry(text_if_str)
to_wei = curry(to_wei)
clamp = curry(clamp)
is_checksum_address = curry(is_checksum_address)
remove_0x_prefix = curry(remove_0x_prefix)