diff --git a/crates/iroha/tests/integration/extra_functional/restart_peer.rs b/crates/iroha/tests/integration/extra_functional/restart_peer.rs index 97a2c4bd149..e91dddb60c3 100644 --- a/crates/iroha/tests/integration/extra_functional/restart_peer.rs +++ b/crates/iroha/tests/integration/extra_functional/restart_peer.rs @@ -8,72 +8,61 @@ use iroha_test_samples::ALICE_ID; use tokio::{task::spawn_blocking, time::timeout}; #[tokio::test] -async fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> { +async fn restarted_peer_should_restore_its_state() -> Result<()> { let asset_definition_id = "xor#wonderland".parse::()?; let quantity = numeric!(200); let network = NetworkBuilder::new().with_peers(4).start().await?; + let peers = network.peers(); - let random_client = network.peer().client(); + // create state on the first peer + let peer_a = &peers[0]; + let client = peer_a.client(); let asset_definition_clone = asset_definition_id.clone(); spawn_blocking(move || { - random_client - .submit_blocking(Register::asset_definition(AssetDefinition::numeric( - asset_definition_clone.clone(), - ))) - .unwrap(); - random_client - .submit_blocking(Mint::asset_numeric( - quantity, - AssetId::new(asset_definition_clone, ALICE_ID.clone()), - )) - .unwrap(); + let tx = client.build_transaction( + [ + InstructionBox::from(Register::asset_definition(AssetDefinition::numeric( + asset_definition_clone.clone(), + ))), + Mint::asset_numeric( + quantity, + AssetId::new(asset_definition_clone, ALICE_ID.clone()), + ) + .into(), + ], + <_>::default(), + ); + client.submit_transaction_blocking(&tx).unwrap(); }) .await?; - // Wait for observing peer to get the block network.ensure_blocks(2).await?; - - let random_client = network.peer().client(); - let assets = spawn_blocking(move || { - random_client - .query(client::asset::all()) - .filter_with(|asset| asset.id.account.eq(ALICE_ID.clone())) - .execute_all() - }) - .await??; - let asset = assets - .into_iter() - .find(|asset| *asset.id().definition() == asset_definition_id) - .expect("Asset not found"); - assert_eq!(AssetValue::Numeric(quantity), *asset.value()); - - // shutdown all - network.ensure_blocks(3).await?; network.shutdown().await; - // restart one - let peer = network.peer(); - peer.start(network.config().clone(), Some(network.genesis())) - .await; - // FIXME: despite that all peers surely have 3 blocks before being shut down, - // on restart a peer might have only 2 blocks in its status. - // So queer! - timeout(network.peer_startup_timeout(), peer.once_block(3)).await?; + // restart another one, **without a genesis** even + let peer_b = &peers[1]; + let config = network.config(); + assert_ne!(peer_a, peer_b); + timeout(network.peer_startup_timeout(), async move { + peer_b.start(config, None).await; + peer_b.once_block(2).await; + }) + .await?; - let client = peer.client(); - let assets = spawn_blocking(move || { + // ensure it has the state + let client = peer_b.client(); + let asset = spawn_blocking(move || { client .query(client::asset::all()) .filter_with(|asset| asset.id.account.eq(ALICE_ID.clone())) .execute_all() }) - .await??; - let account_asset = assets - .into_iter() - .find(|asset| *asset.id().definition() == asset_definition_id) - .expect("Asset not found"); - assert_eq!(AssetValue::Numeric(quantity), *account_asset.value()); + .await?? + .into_iter() + .find(|asset| *asset.id().definition() == asset_definition_id) + .expect("Asset not found"); + assert_eq!(AssetValue::Numeric(quantity), *asset.value()); Ok(()) }