sc_statement_store/
test_utils.rs1use sp_core::{sr25519, Encode, Pair};
22use sp_statement_store::{statement_allowance_key, Channel, StatementAllowance, Topic};
23
24pub fn get_keypair(idx: u32) -> sr25519::Pair {
26 sr25519::Pair::from_string(&format!("//StatementClient//{idx}"), None)
27 .expect("Derivation path is always valid; qed")
28}
29
30pub fn create_uniform_allowance_items(
32 count: u32,
33 allowance: StatementAllowance,
34) -> Vec<(Vec<u8>, Vec<u8>)> {
35 let allowance_encoded = allowance.encode();
36 let mut items = Vec::with_capacity(count as usize);
37 for idx in 0..count {
38 let keypair = get_keypair(idx);
39 let account_id = keypair.public();
40 let storage_key = statement_allowance_key(account_id.0);
41 items.push((storage_key.to_vec(), allowance_encoded.clone()));
42 }
43 items
44}
45
46pub fn create_allowance_items(allowances: &[(u32, StatementAllowance)]) -> Vec<(Vec<u8>, Vec<u8>)> {
48 let mut items = Vec::with_capacity(allowances.len());
49 for (idx, allowance) in allowances {
50 let keypair = get_keypair(*idx);
51 let account_id = keypair.public();
52 let storage_key = statement_allowance_key(account_id.0);
53 items.push((storage_key.to_vec(), allowance.encode()));
54 }
55 items
56}
57
58pub fn create_test_statement(
60 keypair: &sr25519::Pair,
61 topics: &[Topic],
62 channel: Option<Channel>,
63 data: Vec<u8>,
64 expiry_ts: u32,
65 seq: u32,
66) -> sp_statement_store::Statement {
67 let mut statement = sp_statement_store::Statement::new();
68 for (i, topic) in topics.iter().enumerate() {
69 statement.set_topic(i, *topic);
70 }
71 if let Some(ch) = channel {
72 statement.set_channel(ch);
73 }
74 statement.set_plain_data(data);
75 statement.set_expiry_from_parts(expiry_ts, seq);
76 statement.sign_sr25519_private(keypair);
77 statement
78}