コード例 #1
0
    def test_fill(self, rpc_mock):
        # Arrange
        testmap = {
            "branch_offset_sandboxed": [5, None, True, 'head~5'],
            "branch_offset_not_sandboxed": [5, None, False, 'head~5'],
            "ttl_sandboxed": [None, 10, True, 'head~50'],
            "ttl_not_sandboxed": [None, 10, False, 'head~50'],
            "ttl_sandboxed_default": [None, None, True, 'head~0'],
            "ttl_not_sandboxed_default": [None, None, False, 'head~55'],
        }

        client = PyTezosClient()
        client.context.chain_id = 'NetXxkAx4woPLyu'
        client.context.protocol = 'PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i'
        op = client.transaction(destination="")

        for name, (branch_offset, ttl, sandboxed,
                   mock_call) in testmap.items():
            with self.subTest(name):
                # Act
                op.context._sandboxed = sandboxed
                with suppress(Exception):
                    op.fill(branch_offset=branch_offset,
                            ttl=ttl,
                            gas_limit=0,
                            storage_limit=0,
                            counter=0)

                # Assert
                rpc_mock.assert_called_with(mock_call)
コード例 #2
0
 def autobake(time_between_blocks: int, node_url: str, key: str, exit_event: Event):
     logging.info("Baker thread started")
     client = PyTezosClient().using(shell=node_url, key=key)
     ptr = 0
     while not exit_event.is_set():
         if ptr % time_between_blocks == 0:
             client.bake_block().fill().work().sign().inject()
         sleep(1)
         ptr += 1
     logging.info("Baker thread stopped")
コード例 #3
0
ファイル: checker.py プロジェクト: tezos-checker/checker
def deploy_contract(
    tz: PyTezosClient,
    *,
    source_file: Path,
    initial_storage: Any,
    initial_balance: int = 0,
    ttl: int = MAX_OPERATIONS_TTL,
):
    script = pytezos.ContractInterface.from_file(source_file).script(
        initial_storage=initial_storage)

    origination = inject(
        tz,
        tz.origination(script,
                       balance=initial_balance).autofill(ttl=ttl).sign())

    # opg = tz.shell.blocks[origination["branch"] :].find_operation(origination["hash"])
    res = pytezos.operation.result.OperationResult.from_operation_group(
        origination)

    addr = res[0].originated_contracts[0]
    return tz.contract(addr)
コード例 #4
0
    def test_fill(self, rpc_mock):
        # Arrange
        testmap = {
            "branch_offset_sandboxed": [5, None, True, 'head-5'],
            "branch_offset_not_sandboxed": [5, None, False, 'head-5'],
            "ttl_sandboxed": [None, 10, True, 'head-50'],
            "ttl_not_sandboxed": [None, 10, False, 'head-50'],
            "ttl_sandboxed_default": [None, None, True, 'head-0'],
            "ttl_not_sandboxed_default": [None, None, False, 'head-55'],
        }

        client = PyTezosClient()
        op = client.transaction(destination="")

        for name, (branch_offset, ttl, sandboxed,
                   mock_call) in testmap.items():
            with self.subTest(name):
                # Act
                op.context._sandboxed = sandboxed
                with suppress(Exception):
                    op.fill(branch_offset=branch_offset, ttl=ttl)

                # Assert
                rpc_mock.assert_called_with(mock_call)
コード例 #5
0
ファイル: node.py プロジェクト: yourlabsopensource/pytezos
 def create_client(cls):
     global node_container_client
     node_container_client = PyTezosClient()
     return cls.get_client()
コード例 #6
0
ファイル: node.py プロジェクト: yourlabsopensource/pytezos
import atexit
import unittest
from time import sleep
from typing import Optional

import requests.exceptions
from testcontainers.core.generic import DockerContainer  # type: ignore

from pytezos.client import PyTezosClient
from pytezos.sandbox.parameters import EDO

# NOTE: Container object is a singleton which will be used in all tests inherited from class _SandboxedNodeTestCase
# and stopped after all tests are completed.
node_container: Optional[DockerContainer] = None
node_container_client: PyTezosClient = PyTezosClient()
node_fitness: int = 1


class SandboxedNodeTestCase(unittest.TestCase):
    IMAGE = 'bakingbad/sandboxed-node:v9.0-rc1-1'
    PROTOCOL = EDO

    @classmethod
    def setUpClass(cls) -> None:
        global node_container
        if not node_container:
            node_container = cls._create_node_container()
            node_container.start()
            cls._wait_for_connection()
            atexit.register(node_container.stop)
コード例 #7
0
ファイル: __init__.py プロジェクト: kengkiat/pytezos
"""
Welcome to PyTezos!

To start playing with the Tezos blockchain you need to get a PyTezosClient instance.
Just type:

>>> from pytezos import pytezos
>>> pytezos

And follow the interactive documentation.
"""

from pytezos.client import PyTezosClient
from pytezos.crypto.key import Key
from pytezos.operation.group import OperationGroup
from pytezos.operation.result import OperationResult
from pytezos.contract.interface import ContractInterface, Contract
from pytezos.michelson.format import micheline_to_michelson
from pytezos.michelson.parse import michelson_to_micheline
from pytezos.michelson.forge import forge_micheline, unforge_micheline
from pytezos.michelson.types.core import Unit
from pytezos.michelson.types.base import Undefined, MichelsonType
from pytezos.michelson.micheline import MichelsonRuntimeError

pytezos = PyTezosClient()