Esempio n. 1
0
def test_sign_deploy(key: PrivateKey, terms: str, phlo_price: int, phlo_limit: int, valid_after_block_no: int,
                     timestamp_millis: int):
    runner = CliRunner()
    result = runner.invoke(cli, ['sign-deploy', '--private-key', key.to_hex(),
                                 '--term', terms,
                                 "--phlo-price", phlo_price,
                                 "--phlo-limit", phlo_limit,
                                 "--valid-after-block-number", valid_after_block_no,
                                 "--timestamp", timestamp_millis,
                                 "--sig-algorithm", "secp256k1"
                                 ])
    assert result.exit_code == 0
    sig = result.output.strip()

    data = DeployDataProto(
        deployer=key.get_public_key().to_bytes(),
        term=terms,
        phloPrice=phlo_price,
        phloLimit=phlo_limit,
        validAfterBlockNumber=valid_after_block_no,
        timestamp=timestamp_millis,
        sigAlgorithm='secp256k1',
    )
    assert verify_deploy_data(key.get_public_key(), bytes.fromhex(sig), data)
Esempio n. 2
0
def make_peer(
    *,
    docker_client: DockerClient,
    network: str,
    name: str,
    bonds_file: str,
    command_timeout: int,
    bootstrap: Node,
    private_key: PrivateKey,
    allowed_peers: Optional[List[str]] = None,
    mem_limit: Optional[str] = None,
    wallets_file: Optional[str] = None,
    cli_flags: Optional[AbstractSet] = None,
    cli_options: Optional[Dict] = None,
    extra_volumes: Optional[List[str]] = None,
    synchrony_constraint_threshold: float = 0.0,
    max_peer_queue_size: int = 10,
    give_up_after_skipped: int = 0,
    drop_peer_after_retries: int = 0,
    number_of_active_validators: int = 10,
    epoch_length: int = 10000,
    quarantine_length: int = 50000
) -> Node:
    assert isinstance(name, str)
    assert '_' not in name, 'Underscore is not allowed in host name'
    name = make_peer_name(network, name)

    bootstrap_address = bootstrap.get_rnode_address()

    container_command_flags = set([
        "--prometheus",
        "--no-upnp",
        "--allow-private-addresses"
    ])

    if cli_flags is not None:
        container_command_flags.update(cli_flags)

    container_command_options = {
        "--bootstrap":                      bootstrap_address,
        "--validator-private-key":          private_key.to_hex(),
        "--validator-public-key":           private_key.get_public_key().to_hex(),
        "--host":                           name,
        "--synchrony-constraint-threshold": synchrony_constraint_threshold,
        "--frrd-max-peer-queue-size":            max_peer_queue_size,
        "--frrd-give-up-after-skipped":          give_up_after_skipped,
        "--frrd-drop-peer-after-retries":        drop_peer_after_retries,
        "--number-of-active-validators":    number_of_active_validators,
        "--epoch-length":                   epoch_length,
        "--quarantine-length":              quarantine_length
    }

    if cli_options is not None:
        container_command_options.update(cli_options)

    container = make_node(
        docker_client=docker_client,
        name=name,
        network=network,
        bonds_file=bonds_file,
        container_command='run',
        container_command_flags=container_command_flags,
        container_command_options=container_command_options,
        command_timeout=command_timeout,
        extra_volumes=extra_volumes,
        allowed_peers=allowed_peers,
        mem_limit=mem_limit if not None else '4G',
        wallets_file=wallets_file,
    )
    return container