Example #1
0
 def test_check_operations(self, sandbox_multibranch: SandboxMultiBranch):
     min_level = min([
         client.get_level() for client in sandbox_multibranch.all_clients()
     ])
     heads_hash = set()
     # check there is exactly one head
     for client in sandbox_multibranch.all_clients():
         block_hash = utils.get_block_hash(client, min_level)
         heads_hash.add(block_hash)
     assert len(heads_hash) == 1
Example #2
0
def sandbox_multibranch(log_dir, request):
    """Multi-branch sandbox fixture. Parameterized by map of branches.

    This fixture is identical to `sandbox` except that each node_id is
    mapped to a pair (git revision, protocol version). For instance,
    suppose a mapping:

      MAP = { 0: ('zeronet', 'alpha'), 1:('mainnet', '003-PsddFKi3'),
              2: ('alphanet', '003-PsddFKi3' }

    If we annotate the class test as follows.
    @pytest.mark.parametrize('sandbox_multibranch', [MAP], indirect=True)

    The executables (node, baker, endorser)
    - for node_id 0 will be looked up in `TEZOS_BINARY/zeronet`,
    - for node_id 1 will be looked up in `TEZOS_BINARY/mainnet` and so on...

    baker and endorser will use the specified protocol version, according
    to the tezos executables naming conventions.
    """
    if paths.TEZOS_BINARIES is None:
        pytest.skip()
    branch_map = request.param
    assert branch_map is not None
    num_peers = max(branch_map) + 1

    with SandboxMultiBranch(paths.TEZOS_BINARIES,
                            constants.IDENTITIES,
                            num_peers=num_peers,
                            log_dir=log_dir,
                            branch_map=branch_map) as sandbox:
        yield sandbox
        # this assertion checks that daemons (baker, endorser, node...) didn't
        # fail unexpected.
        assert sandbox.are_daemons_alive(), DEAD_DAEMONS_WARN
Example #3
0
 def test_setup_network(self, sandbox_multibranch: SandboxMultiBranch):
     # Set appropriate time to avoid double-baking
     for i in range(NUM_NODES):
         sandbox_multibranch.add_node(i, params=params(i))
     parameters = dict(constants.ALPHA_PARAMETERS)
     parameters["time_between_blocks"] = ["10", "0"]
     sandbox_multibranch.client(0).activate_protocol_json(ALPHA, parameters)
     sandbox_multibranch.add_baker(0, 'bootstrap5', proto=ALPHA_DAEMON)
     sandbox_multibranch.add_baker(1, 'bootstrap4', proto=ALPHA_DAEMON)
     sandbox_multibranch.add_endorser(0,
                                      account='bootstrap1',
                                      endorsement_delay=1,
                                      proto=ALPHA_DAEMON)
     sandbox_multibranch.add_endorser(1,
                                      account='bootstrap2',
                                      endorsement_delay=1,
                                      proto=ALPHA_DAEMON)
Example #4
0
    def test_network_gen_operations_and_add_nodes(
            self, sandbox_multibranch: SandboxMultiBranch, session: dict):
        node_add_period = NUM_CYCLES // NEW_NODES
        for cycle in range(NUM_CYCLES):
            i = random.randrange(NUM_NODES)
            client = sandbox_multibranch.client(i)
            try:
                transfer = random_op(client)
                session[f'op{cycle}'] = transfer.operation_hash
            except subprocess.CalledProcessError:
                # some operations may be invalid, e.g. the client sends
                # several operation with the same counter
                print('# IGNORED INVALID OPERATION')

            if cycle % node_add_period == 0:
                # add node
                running_nodes = list(sandbox_multibranch.nodes.keys())
                new_node = max(running_nodes) + 1
                if REPLACE:
                    running_nodes.remove(0)
                    running_nodes.remove(1)
                    sandbox_multibranch.rm_node(random.choice(running_nodes))
                sandbox_multibranch.add_node(new_node, params=params(new_node))
                proto = ALPHA
                assert utils.check_protocol(
                    sandbox_multibranch.client(new_node), proto)
            time.sleep(TIME_BETWEEN_CYCLE)
Example #5
0
 def test_wait_for_alpha(self, sandbox_multibranch: SandboxMultiBranch):
     clients = sandbox_multibranch.all_clients()
     for client in clients:
         proto = ALPHA
         assert utils.check_protocol(client, proto)
Example #6
0
 def test_synchronize(self, sandbox_multibranch: SandboxMultiBranch):
     utils.synchronize(sandbox_multibranch.all_clients())
Example #7
0
 def test_kill_baker(self, sandbox_multibranch: SandboxMultiBranch):
     sandbox_multibranch.rm_baker(0, proto=ALPHA_DAEMON)
     sandbox_multibranch.rm_baker(1, proto=ALPHA_DAEMON)