Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statement-distribution: refactor setup/connection logic for tests #2382

Open
mrcnski opened this issue Nov 17, 2023 · 0 comments
Open

statement-distribution: refactor setup/connection logic for tests #2382

mrcnski opened this issue Nov 17, 2023 · 0 comments
Assignees

Comments

@mrcnski
Copy link
Contributor

mrcnski commented Nov 17, 2023

Many of the tests start with basically the same code with minor variations:

let local_validator = state.local.clone().unwrap();
let local_group_index = local_validator.group_index.unwrap();

let other_group = next_group_index(local_group_index, validator_count, group_size);
let other_para = ParaId::from(other_group.0);

let test_leaf = state.make_dummy_leaf(relay_parent);

let (candidate, pvd) = make_candidate(
    relay_parent,
    1,
    other_para,
    test_leaf.para_data(other_para).head_data.clone(),
    vec![4, 5, 6].into(),
    Hash::repeat_byte(42).into(),
);
let candidate_hash = candidate.hash();

let other_group_validators = state.group_validators(local_group_index, true);
let target_group_validators = state.group_validators(other_group, true);
let v_a = other_group_validators[0];
let v_b = other_group_validators[1];
let v_c = target_group_validators[0];
let v_d = target_group_validators[1];

// peer A is in group, has relay parent in view.
// peer B is in group, has no relay parent in view.
// peer C is not in group, has relay parent in view.
// peer D is not in group, has relay parent in view.
{
    connect_peer(
        &mut overseer,
        peer_a.clone(),
        Some(vec![state.discovery_id(v_a)].into_iter().collect()),
    )
    .await;

    connect_peer(
        &mut overseer,
        peer_b.clone(),
        Some(vec![state.discovery_id(v_b)].into_iter().collect()),
    )
    .await;

    connect_peer(
        &mut overseer,
        peer_c.clone(),
        Some(vec![state.discovery_id(v_c)].into_iter().collect()),
    )
    .await;

    connect_peer(
        &mut overseer,
        peer_d.clone(),
        Some(vec![state.discovery_id(v_d)].into_iter().collect()),
    )
    .await;

    send_peer_view_change(&mut overseer, peer_a.clone(), view![relay_parent]).await;
    send_peer_view_change(&mut overseer, peer_c.clone(), view![relay_parent]).await;
    send_peer_view_change(&mut overseer, peer_d.clone(), view![relay_parent]).await;
}

activate_leaf(&mut overseer, &test_leaf, &state, true).await;

answer_expected_hypothetical_depth_request(
    &mut overseer,
    vec![],
    Some(relay_parent),
    false,
)
.await;

// Send gossip topology.
send_new_topology(&mut overseer, state.make_dummy_topology()).await;

It would cut down a lot of verbosity to reduce this to something like:

let peers_in_view = [peer_a, peer_c, peer_d];
setup_and_connect_peers(group_size, &peers_in_view, ...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant