use sp_core::{sr25519, Encode, Pair};
use sp_statement_store::{statement_allowance_key, Channel, StatementAllowance, Topic};
pub fn get_keypair(idx: u32) -> sr25519::Pair {
sr25519::Pair::from_string(&format!("//StatementClient//{idx}"), None)
.expect("Derivation path is always valid; qed")
}
pub fn create_uniform_allowance_items(
count: u32,
allowance: StatementAllowance,
) -> Vec<(Vec<u8>, Vec<u8>)> {
let allowance_encoded = allowance.encode();
let mut items = Vec::with_capacity(count as usize);
for idx in 0..count {
let keypair = get_keypair(idx);
let account_id = keypair.public();
let storage_key = statement_allowance_key(account_id.0);
items.push((storage_key.to_vec(), allowance_encoded.clone()));
}
items
}
pub fn create_allowance_items(allowances: &[(u32, StatementAllowance)]) -> Vec<(Vec<u8>, Vec<u8>)> {
let mut items = Vec::with_capacity(allowances.len());
for (idx, allowance) in allowances {
let keypair = get_keypair(*idx);
let account_id = keypair.public();
let storage_key = statement_allowance_key(account_id.0);
items.push((storage_key.to_vec(), allowance.encode()));
}
items
}
pub fn create_test_statement(
keypair: &sr25519::Pair,
topics: &[Topic],
channel: Option<Channel>,
data: Vec<u8>,
expiry_ts: u32,
seq: u32,
) -> sp_statement_store::Statement {
let mut statement = sp_statement_store::Statement::new();
for (i, topic) in topics.iter().enumerate() {
statement.set_topic(i, *topic);
}
if let Some(ch) = channel {
statement.set_channel(ch);
}
statement.set_plain_data(data);
statement.set_expiry_from_parts(expiry_ts, seq);
statement.sign_sr25519_private(keypair);
statement
}