-
Notifications
You must be signed in to change notification settings - Fork 262
/
Copy pathclient.rs
124 lines (114 loc) · 3.53 KB
/
client.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// This file is part of subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.
use crate::{
test_node_process,
test_node_process_with,
utils::node_runtime::system,
};
use sp_core::storage::{
well_known_keys,
StorageKey,
};
use sp_keyring::AccountKeyring;
#[async_std::test]
async fn insert_key() {
let test_node_process = test_node_process_with(AccountKeyring::Bob).await;
let client = test_node_process.client();
let public = AccountKeyring::Alice.public().as_array_ref().to_vec();
client
.rpc()
.insert_key(
"aura".to_string(),
"//Alice".to_string(),
public.clone().into(),
)
.await
.unwrap();
assert!(client
.rpc()
.has_key(public.clone().into(), "aura".to_string())
.await
.unwrap());
}
#[async_std::test]
async fn fetch_block_hash() {
let node_process = test_node_process().await;
node_process.client().rpc().block_hash(None).await.unwrap();
}
#[async_std::test]
async fn fetch_block() {
let node_process = test_node_process().await;
let client = node_process.client();
let block_hash = client.rpc().block_hash(None).await.unwrap();
client.rpc().block(block_hash).await.unwrap();
}
#[async_std::test]
async fn fetch_read_proof() {
let node_process = test_node_process().await;
let client = node_process.client();
let block_hash = client.rpc().block_hash(None).await.unwrap();
client
.rpc()
.read_proof(
vec![
StorageKey(well_known_keys::HEAP_PAGES.to_vec()),
StorageKey(well_known_keys::EXTRINSIC_INDEX.to_vec()),
],
block_hash,
)
.await
.unwrap();
}
#[async_std::test]
async fn chain_subscribe_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.rpc().subscribe_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}
#[async_std::test]
async fn chain_subscribe_finalized_blocks() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut blocks = client.rpc().subscribe_finalized_blocks().await.unwrap();
blocks.next().await.unwrap().unwrap();
}
#[async_std::test]
async fn fetch_keys() {
let node_process = test_node_process().await;
let client = node_process.client();
let keys = client
.storage()
.fetch_keys::<system::storage::Account>(4, None, None)
.await
.unwrap();
assert_eq!(keys.len(), 4)
}
#[async_std::test]
async fn test_iter() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut iter = client
.storage()
.iter::<system::storage::Account>(None)
.await
.unwrap();
let mut i = 0;
while iter.next().await.unwrap().is_some() {
i += 1;
}
assert_eq!(i, 13);
}