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

Integrate existing executor tests with the new testing framework #1342

Merged
merged 9 commits into from
Apr 7, 2023
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 39 additions & 27 deletions crates/subspace-fraud-proof/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use tempfile::TempDir;
const TEST_DOMAIN_ID: DomainId = DomainId::SYSTEM;

#[substrate_test_utils::test(flavor = "multi_thread")]
#[ignore]
async fn execution_proof_creation_and_verification_should_work() {
let directory = TempDir::new().expect("Must be able to create temporary directory");

Expand All @@ -37,23 +36,19 @@ async fn execution_proof_creation_and_verification_should_work() {
let tokio_handle = tokio::runtime::Handle::current();

// Start Ferdie
let (ferdie, ferdie_network_starter) = run_primary_chain_validator_node(
let mut ferdie = MockPrimaryNode::run_mock_primary_node(
tokio_handle.clone(),
Ferdie,
vec![],
BasePath::new(directory.path().join("ferdie")),
)
.await;
ferdie_network_starter.start_network();
);

// Run Alice (a system domain authority node)
let alice = domain_test_service::SystemDomainNodeBuilder::new(
tokio_handle.clone(),
Alice,
BasePath::new(directory.path().join("alice")),
)
.connect_to_primary_chain_node(&ferdie)
.build(Role::Authority, false, false)
.build_with_mock_primary_node(Role::Authority, &mut ferdie)
.await;

// Run Bob (a system domain full node)
Expand All @@ -62,12 +57,17 @@ async fn execution_proof_creation_and_verification_should_work() {
Bob,
BasePath::new(directory.path().join("bob")),
)
.connect_to_primary_chain_node(&ferdie)
.build(Role::Full, false, false)
.build_with_mock_primary_node(Role::Full, &mut ferdie)
.await;

// Bob is able to sync blocks.
futures::future::join(alice.wait_for_blocks(1), bob.wait_for_blocks(1)).await;
futures::join!(
alice.wait_for_blocks(1),
bob.wait_for_blocks(1),
ferdie.produce_blocks(1),
)
.2
.unwrap();

let transfer_to_charlie = domain_test_service::construct_extrinsic(
&alice.client,
Expand Down Expand Up @@ -113,30 +113,36 @@ async fn execution_proof_creation_and_verification_should_work() {
.expect("Failed to send extrinsic");
}

// Ideally we just need to wait one block and the test txs should be all included
// in the next block, but the txs are probably unable to be included if the machine
// is overloaded, hence we manually mock the bundles processing to avoid the occasional
// test failure (https://github.com/subspace/subspace/runs/5663241460?check_suite_focus=true).
//
// alice.wait_for_blocks(1).await;

let primary_info = (
ferdie.client.info().best_hash,
ferdie.client.info().best_number,
);
alice.executor.clone().process_bundles(primary_info).await;
// Produce a domain bundle to include the above test txs and wait for `alice`
// to apply these txs
let (slot, bundle) = ferdie.produce_slot_and_wait_for_bundle_submission().await;
assert!(bundle.is_some());
futures::future::join(
alice.wait_for_blocks(1),
ferdie.produce_block_with_slot(slot),
)
.await
.1
.unwrap();

let best_hash = alice.client.info().best_hash;
let header = alice.client.header(best_hash).unwrap().unwrap();
let parent_header = alice.client.header(*header.parent_hash()).unwrap().unwrap();

let create_block_builder = || {
let primary_hash = ferdie.client.hash(*header.number()).unwrap().unwrap();
let digest = Digest {
logs: vec![DigestItem::primary_block_info((
*header.number(),
primary_hash,
))],
};
BlockBuilder::new(
&*alice.client,
parent_header.hash(),
*parent_header.number(),
RecordProof::No,
Default::default(),
digest,
&*alice.backend,
test_txs.clone().into_iter().map(Into::into).collect(),
)
Expand All @@ -156,12 +162,18 @@ async fn execution_proof_creation_and_verification_should_work() {
);
}

let primary_hash = ferdie.client.hash(*header.number()).unwrap().unwrap();
let new_header = Header::new(
*header.number(),
Default::default(),
Default::default(),
parent_header.hash(),
Default::default(),
Digest {
logs: vec![DigestItem::primary_block_info((
*header.number(),
primary_hash,
))],
},
);
let execution_phase = ExecutionPhase::InitializeBlock {
domain_parent_hash: parent_header.hash(),
Expand Down Expand Up @@ -418,8 +430,8 @@ async fn invalid_execution_proof_should_not_work() {
}

// Produce a domain bundle to include the above test tx
let slot = ferdie.produce_slot_and_wait_for_bundle_submission().await;
assert!(ferdie.is_bundle_present_in_tx_pool(slot.into(), alice.key));
let (slot, bundle) = ferdie.produce_slot_and_wait_for_bundle_submission().await;
assert!(bundle.is_some());

// Wait for `alice` to apply these txs
futures::future::join(
Expand Down
Loading