1use crate::strings::rpc_server::storage;
13
14pub const DEV_BALANCE: u128 = u128::MAX / 2;
16
17pub const ALICE: [u8; 32] = [
23 0xd4, 0x35, 0x93, 0xc7, 0x15, 0xfd, 0xd3, 0x1c, 0x61, 0x14, 0x1a, 0xbd, 0x04, 0xa9, 0x9f, 0xd6,
24 0x82, 0x2c, 0x85, 0x58, 0x85, 0x4c, 0xcd, 0xe3, 0x9a, 0x56, 0x84, 0xe7, 0xa5, 0x6d, 0xa2, 0x7d,
25];
26
27pub const BOB: [u8; 32] = [
29 0x8e, 0xaf, 0x04, 0x15, 0x16, 0x87, 0x73, 0x63, 0x26, 0xc9, 0xfe, 0xa1, 0x7e, 0x25, 0xfc, 0x52,
30 0x87, 0x61, 0x36, 0x93, 0xc9, 0x12, 0x90, 0x9c, 0xb2, 0x26, 0xaa, 0x47, 0x94, 0xf2, 0x6a, 0x48,
31];
32
33pub const CHARLIE: [u8; 32] = [
35 0x90, 0xb5, 0xab, 0x20, 0x5c, 0x69, 0x74, 0xc9, 0xea, 0x84, 0x1b, 0xe6, 0x88, 0x86, 0x46, 0x33,
36 0xdc, 0x9c, 0xa8, 0xa3, 0x57, 0x84, 0x3e, 0xea, 0xcf, 0x23, 0x14, 0x64, 0x99, 0x65, 0xfe, 0x22,
37];
38
39pub const DAVE: [u8; 32] = [
41 0x30, 0x67, 0x21, 0x21, 0x1d, 0x54, 0x04, 0xbd, 0x9d, 0xa8, 0x8e, 0x02, 0x04, 0x36, 0x0a, 0x1a,
42 0x9a, 0xb8, 0xb8, 0x7c, 0x66, 0xc1, 0xbc, 0x2f, 0xcd, 0xd3, 0x7f, 0x3c, 0x22, 0x22, 0xcc, 0x20,
43];
44
45pub const EVE: [u8; 32] = [
47 0xe6, 0x59, 0xa7, 0xa1, 0x62, 0x8c, 0xdd, 0x93, 0xfe, 0xbc, 0x04, 0xa4, 0xe0, 0x64, 0x6e, 0xa2,
48 0x0e, 0x9f, 0x5f, 0x0c, 0xe0, 0x97, 0xd9, 0xa0, 0x52, 0x90, 0xd4, 0xa9, 0xe0, 0x54, 0xdf, 0x4e,
49];
50
51pub const FERDIE: [u8; 32] = [
53 0x1c, 0xbd, 0x2d, 0x43, 0x53, 0x0a, 0x44, 0x70, 0x5a, 0xd0, 0x88, 0xaf, 0x31, 0x3e, 0x18, 0xf8,
54 0x0b, 0x53, 0xef, 0x16, 0xb3, 0x61, 0x77, 0xcd, 0x4b, 0x77, 0xb8, 0x46, 0xf2, 0xa5, 0xf0, 0x7c,
55];
56
57pub const SUBSTRATE_DEV_ACCOUNTS: [(&str, [u8; 32]); 6] = [
59 ("Alice", ALICE),
60 ("Bob", BOB),
61 ("Charlie", CHARLIE),
62 ("Dave", DAVE),
63 ("Eve", EVE),
64 ("Ferdie", FERDIE),
65];
66
67pub const ALITH: [u8; 20] = [
73 0xf2, 0x4f, 0xf3, 0xa9, 0xcf, 0x04, 0xc7, 0x1d, 0xbc, 0x94, 0xd0, 0xb5, 0x66, 0xf7, 0xa2, 0x7b,
74 0x94, 0x56, 0x6c, 0xac,
75];
76
77pub const BALTATHAR: [u8; 20] = [
79 0x3c, 0xd0, 0xa7, 0x05, 0xa2, 0xdc, 0x65, 0xe5, 0xb1, 0xe1, 0x20, 0x58, 0x96, 0xba, 0xa2, 0xbe,
80 0x8a, 0x07, 0xc6, 0xe0,
81];
82
83pub const CHARLETH: [u8; 20] = [
85 0x79, 0x8d, 0x4b, 0xa9, 0xba, 0xf0, 0x06, 0x4e, 0xc1, 0x9e, 0xb4, 0xf0, 0xa1, 0xa4, 0x57, 0x85,
86 0xae, 0x9d, 0x6d, 0xfc,
87];
88
89pub const DOROTHY: [u8; 20] = [
91 0x77, 0x35, 0x39, 0xd4, 0xac, 0x0e, 0x78, 0x62, 0x33, 0xd9, 0x0a, 0x23, 0x36, 0x54, 0xcc, 0xee,
92 0x26, 0xa6, 0x13, 0xd9,
93];
94
95pub const ETHAN: [u8; 20] = [
97 0xff, 0x64, 0xd3, 0xf6, 0xef, 0xe2, 0x31, 0x7e, 0xe2, 0x80, 0x7d, 0x22, 0x3a, 0x0b, 0xdc, 0x4c,
98 0x0c, 0x49, 0xdf, 0xdb,
99];
100
101pub const FAITH: [u8; 20] = [
103 0xc0, 0xf0, 0xf4, 0xab, 0x32, 0x4c, 0x46, 0xe5, 0x5d, 0x02, 0xd0, 0x03, 0x33, 0x43, 0xb4, 0xbe,
104 0x8a, 0x55, 0x53, 0x2d,
105];
106
107pub const ETHEREUM_DEV_ACCOUNTS: [(&str, [u8; 20]); 6] = [
109 ("Alith", ALITH),
110 ("Baltathar", BALTATHAR),
111 ("Charleth", CHARLETH),
112 ("Dorothy", DOROTHY),
113 ("Ethan", ETHAN),
114 ("Faith", FAITH),
115];
116
117pub fn account_storage_key(account: &[u8]) -> Vec<u8> {
125 let mut key = Vec::new();
126 key.extend(sp_core::twox_128(storage::SYSTEM_PALLET));
127 key.extend(sp_core::twox_128(storage::ACCOUNT_STORAGE));
128 key.extend(sp_core::blake2_128(account));
129 key.extend(account);
130 key
131}
132
133pub fn sudo_key_storage_key() -> Vec<u8> {
135 let mut key = Vec::new();
136 key.extend(sp_core::twox_128(storage::SUDO_PALLET));
137 key.extend(sp_core::twox_128(storage::SUDO_KEY_STORAGE));
138 key
139}
140
141pub fn build_account_info(free_balance: u128) -> Vec<u8> {
153 let mut data = vec![0u8; 80];
154 data[8..12].copy_from_slice(&1u32.to_le_bytes());
156 data[16..32].copy_from_slice(&free_balance.to_le_bytes());
158 data
159}
160
161pub fn patch_free_balance(existing: &[u8], new_balance: u128) -> Vec<u8> {
165 let mut patched = existing.to_vec();
166 patched[16..32].copy_from_slice(&new_balance.to_le_bytes());
167 patched
168}
169
170#[cfg(test)]
171mod tests {
172 use super::*;
173
174 #[test]
175 fn substrate_account_storage_key_has_correct_length() {
176 let key = account_storage_key(&ALICE);
177 assert_eq!(key.len(), 80);
180 }
181
182 #[test]
183 fn ethereum_account_storage_key_has_correct_length() {
184 let key = account_storage_key(&ALITH);
185 assert_eq!(key.len(), 68);
188 }
189
190 #[test]
191 fn sudo_key_storage_key_has_correct_length() {
192 let key = sudo_key_storage_key();
193 assert_eq!(key.len(), 32);
195 }
196
197 #[test]
198 fn build_account_info_sets_providers_and_balance() {
199 let balance: u128 = 1_000_000_000_000;
200 let info = build_account_info(balance);
201 assert_eq!(info.len(), 80);
202 assert_eq!(u32::from_le_bytes(info[8..12].try_into().unwrap()), 1);
204 assert_eq!(u128::from_le_bytes(info[16..32].try_into().unwrap()), balance);
206 }
207
208 #[test]
209 fn patch_free_balance_preserves_other_fields() {
210 let original = build_account_info(100);
211 let patched = patch_free_balance(&original, 999);
212 assert_eq!(u128::from_le_bytes(patched[16..32].try_into().unwrap()), 999);
214 assert_eq!(u32::from_le_bytes(patched[8..12].try_into().unwrap()), 1);
216 assert_eq!(patched.len(), 80);
218 }
219}