forked from hyperledger-iroha/iroha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart_peer.rs
68 lines (61 loc) · 1.98 KB
/
restart_peer.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use eyre::Result;
use iroha::{
client::{self},
data_model::prelude::*,
};
use iroha_test_network::*;
use iroha_test_samples::ALICE_ID;
use tokio::{task::spawn_blocking, time::timeout};
#[tokio::test]
async fn restarted_peer_should_restore_its_state() -> Result<()> {
let asset_definition_id = "xor#wonderland".parse::<AssetDefinitionId>()?;
let quantity = numeric!(200);
let network = NetworkBuilder::new().with_peers(4).start().await?;
let peers = network.peers();
// 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 || {
client
.submit_all_blocking::<InstructionBox>([
Register::asset_definition(AssetDefinition::numeric(
asset_definition_clone.clone(),
))
.into(),
Mint::asset_numeric(
quantity,
AssetId::new(asset_definition_clone, ALICE_ID.clone()),
)
.into(),
])
.unwrap();
})
.await?;
network.ensure_blocks(2).await?;
// shutdown all
network.shutdown().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?;
// ensure it has the state
let client = peer_b.client();
let asset = spawn_blocking(move || {
client
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(ALICE_ID.clone()))
.execute_all()
})
.await??
.into_iter()
.find(|asset| *asset.id().definition() == asset_definition_id)
.expect("Asset not found");
assert_eq!(AssetValue::Numeric(quantity), *asset.value());
Ok(())
}