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
use super::{ChainInfo, CoreContext, Test};
use crate::{Result, TestReport};
use diem_sdk::{client::BlockingClient, types::LocalAccount};
pub trait AdminTest: Test {
fn run<'t>(&self, ctx: &mut AdminContext<'t>) -> Result<()>;
}
#[derive(Debug)]
pub struct AdminContext<'t> {
core: CoreContext,
chain_info: ChainInfo<'t>,
pub report: &'t mut TestReport,
}
impl<'t> AdminContext<'t> {
pub fn new(core: CoreContext, chain_info: ChainInfo<'t>, report: &'t mut TestReport) -> Self {
Self {
core,
chain_info,
report,
}
}
pub fn core(&self) -> &CoreContext {
&self.core
}
pub fn rng(&mut self) -> &mut ::rand::rngs::StdRng {
self.core.rng()
}
pub fn client(&self) -> BlockingClient {
BlockingClient::new(&self.chain_info.json_rpc_url)
}
pub fn chain_info(&mut self) -> &mut ChainInfo<'t> {
&mut self.chain_info
}
pub fn random_account(&mut self) -> LocalAccount {
LocalAccount::generate(self.core.rng())
}
}