Пример #1
0
def create_bootstrap_node(docker_client,
                          network,
                          bonds_file,
                          key_pair,
                          rnode_timeout,
                          allowed_peers=None,
                          image=default_image,
                          memory="1024m",
                          cpuset_cpus="0"):
    """
    Create bootstrap node.
    """

    key_file = resources.file_path("bootstrap_certificate/node.key.pem")
    cert_file = resources.file_path(
        "bootstrap_certificate/node.certificate.pem")

    logging.info(f"Using key_file={key_file} and cert_file={cert_file}")

    name = f"bootstrap.{network}"
    command = f"run --port 40400 --standalone --validator-private-key {key_pair.private_key} --validator-public-key {key_pair.public_key} --host {name}"

    volumes = [f"{cert_file}:{rnode_certificate}", f"{key_file}:{rnode_key}"]

    logging.info(f"Starting bootstrap node {name}\ncommand:`{command}`")

    return __create_node_container(docker_client, image, name, network,
                                   bonds_file, command, rnode_timeout, volumes,
                                   allowed_peers, memory, cpuset_cpus)
Пример #2
0
def create_bootstrap_node(docker_client,
                          network,
                          image="test-image:latest",
                          memory="1024m",
                          cpuset_cpus="0"):
    """
    Create bootstrap node.
    """

    validator_private_key, validator_public_key = validator_keys[0]

    key_file = resources.file_path("bootstrap_certificate/node.key.pem")
    cert_file = resources.file_path(
        "bootstrap_certificate/node.certificate.pem")

    logging.info(f"Using key_file={key_file} and cert_file={cert_file}")

    name = f"bootstrap.{network}"
    command = f"run --port 40400 --standalone --validator-private-key {validator_private_key} --validator-public-key {validator_public_key} --host {name}"

    volumes = [
        f"{cert_file}:{rnode_directory}/node.certificate.pem",
        f"{key_file}:{rnode_directory}/node.key.pem"
    ]

    logging.info(f"Starting bootstrap node {name}\ncommand:`{command}`")

    return __create_node_container(docker_client, image, name, network,
                                   command, volumes, memory, cpuset_cpus)
Пример #3
0
def __read_validator_keys():
    # Using pre-generated validator key pairs by rnode. We do this because warning below  with python generated keys
    # WARN  coop.rchain.casper.Validate$ - CASPER: Ignoring block 2cb8fcc56e... because block creator 3641880481... has 0 weight
    f = open(
        resources.file_path(
            'pregenerated-validator-private-public-key-pairs.txt'))
    lines = f.readlines()
    random.shuffle(lines)
    return [line.split() for line in lines]
Пример #4
0
def test_casper_propose_and_deploy(config, converged_network):
    """
    This test represents an integration test that deploys a contract and then checks
    if all the nodes have received the block containing the contract.
    """

    token_size = 20

    contract_name = 'contract.rho'

    for node in converged_network.nodes:
        with log_box(logging.info, f"Run test on node '{node.name}'"):
            expected_string = f"<{node.container.name}:{random_string(token_size)}>"

            logging.info(f"Expected string: {expected_string}")

            copyfile(resources.file_path(contract_name, __name__),
                     f"{node.local_deploy_dir}/{contract_name}")

            exit_code, output = node.exec_run(
                f"sed -i -e 's/@placeholder@/{expected_string}/g' {node.remote_deploy_dir}/{contract_name}"
            )
            logging.debug(f"Sed result: {exit_code}, output: {output}")

            exit_code, output = node.deploy(contract_name)
            logging.debug(f"Deploy result: {exit_code}, output: {output}")

            logging.info(
                "Propose to blockchain previously deployed smart contracts.")

            exit_code, output = node.propose()
            logging.debug(f"Propose result: {exit_code}, output: {output}")

            logging.info(
                f"Check all peer logs for blocks containing {expected_string}")

            other_nodes = [
                n for n in converged_network.nodes
                if n.container.name != node.container.name
            ]

            for node in other_nodes:
                wait_for(
                    string_contains(show_blocks(node),
                                    expected_string), config.receive_timeout,
                    f"Container: {node.container.name}: String {expected_string} NOT found in blocks added."
                )

                logging.info(f"Container: {node.container.name}: SUCCESS!")
Пример #5
0
def validators_data(config):
    # Using pre-generated validator key pairs by rnode. We do this because warning below  with python generated keys
    # WARN  coop.rchain.casper.Validate$ - CASPER: Ignoring block 2cb8fcc56e... because block creator 3641880481... has 0 weight
    f = open(
        resources.file_path(
            'pregenerated-validator-private-public-key-pairs.txt'))
    lines = f.readlines()
    random.shuffle(lines)
    validator_keys = [
        KeyPair(*line.split()) for line in lines[0:config.peer_count + 1]
    ]

    logging.info(f"Using validator keys: {validator_keys}")

    with create_bonds_file(validator_keys) as bonds_file:
        yield (bonds_file, validator_keys[0], validator_keys[1:])
Пример #6
0
def __create_node_container(docker_client, image, name, network, command,
                            extra_volumes, memory, cpuset_cpus):
    bonds_file = resources.file_path("test-bonds.txt")

    container_bonds_file = f'{rnode_directory}/genesis/bonds.txt'

    volume = docker_client.volumes.create()
    return docker_client.containers.run(
        image,
        name=name,
        user='******',
        detach=True,
        cpuset_cpus=cpuset_cpus,
        mem_limit=memory,
        network=network,
        volumes=[
            f"{volume.name}:{rnode_directory}",
            f"{bonds_file}:{container_bonds_file}"
        ] + extra_volumes,
        command=command,
        hostname=name)