예제 #1
0
    def _spawn_context(
        self,
        shell: Optional[Union[ShellQuery, str]] = None,
        key: Optional[Union[Key, str, dict]] = None,
        address: Optional[str] = None,
        block_id: Optional[Union[str, int]] = None,
        mode: Optional[str] = None,
        script: Optional[dict] = None,
        ipfs_gateway: Optional[str] = None,
    ) -> ExecutionContext:
        if isinstance(shell, str):
            if shell.endswith('.pool'):
                shell = shell.split('.')[0]
                assert shell in nodes, f'unknown network {shell}'
                shell = ShellQuery(RpcMultiNode(nodes[shell]))
            elif shell in nodes:
                shell = ShellQuery(RpcNode(nodes[shell][0]))
            else:
                shell = ShellQuery(RpcNode(shell))
        else:
            assert shell is None or isinstance(
                shell, ShellQuery), f'unexpected shell {shell}'

        if isinstance(key, str):
            if key in keys:
                key = Key.from_encoded_key(keys[key])
            elif is_public_key(key):
                key = Key.from_encoded_key(key)
            elif is_pkh(key):
                key = KeyHash(key)
            elif exists(expanduser(key)):
                key = Key.from_faucet(key)
            else:
                key = Key.from_alias(key)
        elif isinstance(key, dict):
            key = Key.from_faucet(key)
        else:
            assert key is None or isinstance(key, Key), f'unexpected key {key}'

        if isinstance(address, str):
            try:
                script = self.shell.contracts[address].script()
            except RpcError as e:
                raise RpcError(f'Contract {address} not found', *e.args) from e

        return ExecutionContext(
            shell=shell or self.context.shell,
            key=key or self.context.key,
            address=address,
            block_id=block_id,
            script=script or self.context.script,
            mode=mode or self.context.mode,
            ipfs_gateway=ipfs_gateway,
        )
예제 #2
0
    def __init__(self, shell=None, key=None):
        if shell is None:
            shell = default_shell

        if isinstance(shell, str):
            networks = {
                'mainnet': mainnet,
                'babylonnet': babylonnet,
                'zeronet': zeronet,
                'sandboxnet': localhost.sandboxnet
            }
            if shell in networks:
                self.shell = networks[shell]
            else:
                self.shell = ShellQuery(node=RpcNode(uri=shell))
        elif isinstance(shell, ShellQuery):
            self.shell = shell
        else:
            raise NotImplementedError(shell)

        if key is None:
            key = default_key

        if isinstance(key, str):
            if is_key(key):
                self.key = Key.from_encoded_key(key)
            elif exists(expanduser(key)):
                self.key = Key.from_faucet(key)
            else:
                self.key = Key.from_alias(key)
        elif isinstance(key, Key):
            self.key = key
        else:
            raise NotImplementedError(key)
예제 #3
0
 def __init__(self, context: Optional[ExecutionContext] = None):
     super(ContextMixin, self).__init__()
     if context is None:
         context = ExecutionContext(
             shell=ShellQuery(RpcNode(nodes[default_network][0])),
             key=Key.from_encoded_key(default_key) if is_installed() else KeyHash(default_key_hash))
     self.context = context
예제 #4
0
    def test_reset_value(self):
        self.context.shell = ShellQuery(RpcNode('https://rpc.tzkt.io/edonet'))
        self.context.network = 'mainnet'
        self.context.chain_id = 'ch21n1d'
        code = """
            storage unit ;
            parameter unit ;
            code {
                PUSH int 1;
                RESET "edo2net";
            }
        """
        self._execute_code(code)

        self.assertEqual([], self.stack.items)
        self.assertEqual('edo2net', self.context.network)
        self.assertEqual('some_chain_id', self.context.chain_id)
예제 #5
0
    def __init__(self, shell=None, key=None):
        if shell is None:
            shell = default_shell

        if isinstance(shell, str):
            networks = {
                'mainnet': mainnet,
                'babylonnet': babylonnet,
                'carthagenet': carthagenet,
                'zeronet': zeronet,
                'sandboxnet': localhost.sandboxnet,
                'bbbox': localhost.bbbox,
                'labnet': labnet,
                'mainnet-pool': pool.mainnet
            }
            if shell in networks:
                self.shell = networks[shell]
            else:
                self.shell = ShellQuery(node=RpcNode(uri=shell))
        elif isinstance(shell, ShellQuery):
            self.shell = shell
        else:
            raise NotImplementedError(shell)

        if key is None:
            key = default_key if is_installed() else default_key_hash

        if isinstance(key, str):
            keys = {
                'alice': alice_key
            }
            if key in keys:
                self.key = keys[key]
            elif is_key(key):
                self.key = Key.from_encoded_key(key)
            elif is_pkh(key):
                self.key = KeyHash(key)
            elif exists(expanduser(key)):
                self.key = Key.from_faucet(key)
            else:
                self.key = Key.from_alias(key)
        elif isinstance(key, Key):
            self.key = key
        else:
            raise NotImplementedError(key)