use crate::strings::rpc_server::storage;
pub const DEV_BALANCE: u128 = u128::MAX / 2;
pub const ALICE: [u8; 32] = [
0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x04, 0xa9, 0x9f, 0xd6,
0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d,
];
pub const BOB: [u8; 32] = [
0x8e, 0xaf, 0x04, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52,
0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48,
];
pub const CHARLIE: [u8; 32] = [
0x90, 0xb5, 0xab, 0x20, 0x5c, 0x69, 0x74, 0xc9, 0xea, 0x84, 0x1b, 0xe6, 0x88, 0x86, 0x46, 0x33,
0xdc, 0x9c, 0xa8, 0xa3, 0x57, 0x84, 0x3e, 0xea, 0xcf, 0x23, 0x14, 0x64, 0x99, 0x65, 0xfe, 0x22,
];
pub const DAVE: [u8; 32] = [
0x30, 0x67, 0x21, 0x21, 0x1d, 0x54, 0x04, 0xbd, 0x9d, 0xa8, 0x8e, 0x05, 0x04, 0xde, 0x71, 0xe0,
0x2b, 0x14, 0xc9, 0x31, 0x81, 0x90, 0x11, 0xbc, 0x36, 0x44, 0x01, 0x0e, 0x97, 0xbf, 0xfd, 0x32,
];
pub const EVE: [u8; 32] = [
0xe6, 0x59, 0xa7, 0xa1, 0x62, 0x85, 0x07, 0x36, 0x04, 0x00, 0xd6, 0x01, 0x28, 0x46, 0x7d, 0xc1,
0xac, 0xce, 0x9f, 0xaa, 0xe5, 0xd1, 0x6f, 0x57, 0x72, 0x48, 0xaf, 0x86, 0xad, 0x63, 0x42, 0x60,
];
pub const FERDIE: [u8; 32] = [
0x1c, 0x12, 0xba, 0x5a, 0x19, 0xa3, 0x4d, 0x39, 0x02, 0xd3, 0x67, 0xf1, 0xb7, 0xbc, 0x3b, 0x28,
0x8c, 0x15, 0xac, 0x12, 0x77, 0x16, 0x55, 0x0b, 0x5c, 0x24, 0x93, 0x56, 0xe2, 0x6c, 0x13, 0x1e,
];
pub const SUBSTRATE_DEV_ACCOUNTS: [(&str, [u8; 32]); 6] = [
("Alice", ALICE),
("Bob", BOB),
("Charlie", CHARLIE),
("Dave", DAVE),
("Eve", EVE),
("Ferdie", FERDIE),
];
pub const ALITH: [u8; 20] = [
0xf2, 0x4f, 0xf3, 0xa9, 0xcf, 0x04, 0xc7, 0x1d, 0xbc, 0x94, 0xd0, 0xb5, 0x66, 0xf7, 0xa2, 0x7b,
0x94, 0x56, 0x6c, 0xac,
];
pub const BALTATHAR: [u8; 20] = [
0x3c, 0xd0, 0xa7, 0x05, 0xa2, 0xdc, 0x65, 0xe5, 0xb1, 0xe1, 0x20, 0x58, 0x96, 0xba, 0xa2, 0xbe,
0x8a, 0x07, 0xc6, 0xe0,
];
pub const CHARLETH: [u8; 20] = [
0x79, 0x8d, 0x4b, 0xa9, 0xba, 0xf0, 0x06, 0x4e, 0xc1, 0x9e, 0xb4, 0xf0, 0xa1, 0xa4, 0x57, 0x85,
0xae, 0x9d, 0x6d, 0xfc,
];
pub const DOROTHY: [u8; 20] = [
0x77, 0x35, 0x39, 0xd4, 0xac, 0x0e, 0x78, 0x62, 0x33, 0xd9, 0x0a, 0x23, 0x36, 0x54, 0xcc, 0xee,
0x26, 0xa6, 0x13, 0xd9,
];
pub const ETHAN: [u8; 20] = [
0xff, 0x64, 0xd3, 0xf6, 0xef, 0xe2, 0x31, 0x7e, 0xe2, 0x80, 0x7d, 0x22, 0x3a, 0x0b, 0xdc, 0x4c,
0x0c, 0x49, 0xdf, 0xdb,
];
pub const FAITH: [u8; 20] = [
0xc0, 0xf0, 0xf4, 0xab, 0x32, 0x4c, 0x46, 0xe5, 0x5d, 0x02, 0xd0, 0x03, 0x33, 0x43, 0xb4, 0xbe,
0x8a, 0x55, 0x53, 0x2d,
];
pub const ETHEREUM_DEV_ACCOUNTS: [(&str, [u8; 20]); 6] = [
("Alith", ALITH),
("Baltathar", BALTATHAR),
("Charleth", CHARLETH),
("Dorothy", DOROTHY),
("Ethan", ETHAN),
("Faith", FAITH),
];
pub fn account_storage_key(account: &[u8]) -> Vec<u8> {
let mut key = Vec::new();
key.extend(sp_core::twox_128(storage::SYSTEM_PALLET));
key.extend(sp_core::twox_128(storage::ACCOUNT_STORAGE));
key.extend(sp_core::blake2_128(account));
key.extend(account);
key
}
pub fn sudo_key_storage_key() -> Vec<u8> {
let mut key = Vec::new();
key.extend(sp_core::twox_128(storage::SUDO_PALLET));
key.extend(sp_core::twox_128(storage::SUDO_KEY_STORAGE));
key
}
pub fn build_account_info(free_balance: u128) -> Vec<u8> {
let mut data = vec![0u8; 80];
data[8..12].copy_from_slice(&1u32.to_le_bytes());
data[16..32].copy_from_slice(&free_balance.to_le_bytes());
data
}
pub fn patch_free_balance(existing: &[u8], new_balance: u128) -> Vec<u8> {
let mut patched = existing.to_vec();
patched[16..32].copy_from_slice(&new_balance.to_le_bytes());
patched
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn substrate_account_storage_key_has_correct_length() {
let key = account_storage_key(&ALICE);
assert_eq!(key.len(), 80);
}
#[test]
fn ethereum_account_storage_key_has_correct_length() {
let key = account_storage_key(&ALITH);
assert_eq!(key.len(), 68);
}
#[test]
fn sudo_key_storage_key_has_correct_length() {
let key = sudo_key_storage_key();
assert_eq!(key.len(), 32);
}
#[test]
fn build_account_info_sets_providers_and_balance() {
let balance: u128 = 1_000_000_000_000;
let info = build_account_info(balance);
assert_eq!(info.len(), 80);
assert_eq!(u32::from_le_bytes(info[8..12].try_into().unwrap()), 1);
assert_eq!(u128::from_le_bytes(info[16..32].try_into().unwrap()), balance);
}
#[test]
fn patch_free_balance_preserves_other_fields() {
let original = build_account_info(100);
let patched = patch_free_balance(&original, 999);
assert_eq!(u128::from_le_bytes(patched[16..32].try_into().unwrap()), 999);
assert_eq!(u32::from_le_bytes(patched[8..12].try_into().unwrap()), 1);
assert_eq!(patched.len(), 80);
}
}