-
Notifications
You must be signed in to change notification settings - Fork 339
/
StorageKey.spec.ts
233 lines (210 loc) · 8.44 KB
/
StorageKey.spec.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Metadata from '@polkadot/metadata/Decorated';
import rpcDataV3 from '@polkadot/metadata/Metadata/v3/static';
import rpcDataV4 from '@polkadot/metadata/Metadata/v4/static';
import rpcDataV5 from '@polkadot/metadata/Metadata/v5/static';
import rpcDataV6 from '@polkadot/metadata/Metadata/v6/static';
import rpcDataV7 from '@polkadot/metadata/Metadata/v7/static';
import rpcDataV8 from '@polkadot/metadata/Metadata/v8/static';
import { hexToU8a } from '@polkadot/util';
import { TypeRegistry } from '../codec';
import StorageKey from './StorageKey';
describe('StorageKey', (): void => {
const registry = new TypeRegistry();
describe('with MetadataV3 (uses xxHash by default)', (): void => {
const metadata = new Metadata(registry, rpcDataV3);
it('should correctly get Alice\'s freeBalance storage key (hex)', (): void => {
expect(
new StorageKey(
registry,
metadata
.query
.balances
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toHex()
).toBe('0xc99f5446efa57788f39ab529311f4550'); // FIXME OK this should be length-prefixed in reality
});
it('should correctly get Alice\'s freeBalance storage key (u8a)', (): void => {
expect(
new StorageKey(
registry,
metadata
.query
.balances
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toU8a()
).toEqual(
// length prefix attached
hexToU8a('0x40c99f5446efa57788f39ab529311f4550')
);
});
});
describe('with MetadataV4 (uses xxHash by default)', (): void => {
const metadata = new Metadata(registry, rpcDataV4);
it('should correctly get Alice\'s freeBalance storage key (hex)', (): void => {
expect(
new StorageKey(
registry,
metadata
.query
.balances
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toHex()
).toBe('0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587bb');
});
it('should correctly get Alice\'s freeBalance storage key (u8a)', (): void => {
expect(
new StorageKey(
registry,
metadata
.query
.balances
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toU8a()
).toEqual(
// length prefix attached
Uint8Array.from([
128, 127, 134, 78, 24, 227, 221, 139, 88, 56, 99, 16, 210, 254, 9, 25, 238, 242, 124, 110, 85, 133, 100, 183, 246, 127, 34, 217, 157, 32, 245, 135, 187
])
);
});
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toHex()
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
});
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toU8a()
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
});
});
describe('with MetadataV5', (): void => {
const metadata = new Metadata(registry, rpcDataV5);
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toHex()
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
});
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toU8a()
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
});
});
describe('with MetadataV6', (): void => {
const metadata = new Metadata(registry, rpcDataV6);
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toHex()
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
});
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toU8a()
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
});
});
describe('with MetadataV7', (): void => {
const metadata = new Metadata(registry, rpcDataV7);
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toHex()
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
});
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toU8a()
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
});
});
describe('with MetadataV8', (): void => {
const metadata = new Metadata(registry, rpcDataV8);
it('should correctly get the EventTopics double map storage key (hex)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toHex()
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
});
it('should correctly get the EventTopics double map storage key (u8a)', (): void => {
expect(
new StorageKey(registry, [
metadata
.query
.system
.eventTopics,
['any', [1, 2, 3]]
])
.toU8a()
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
});
});
});