DoubleMap hashing over full value (#1650)

* DoubleMap hashing over full value

* Expand Bytes tests

* Expand

* Hashing test with soublemaps

* Small extra test comments
This commit is contained in:
Jaco Greeff
2019-12-09 08:37:47 +01:00
committed by GitHub
parent 21c57b60a1
commit 6bf0d5eea9
5 changed files with 95 additions and 15 deletions
+34 -8
View File
@@ -7,34 +7,60 @@ import Bytes from './Bytes';
describe('Bytes', (): void => {
const registry = new TypeRegistry();
const CODE = new Uint8Array([0x14, 0x3a, 0x63, 0x6f, 0x64, 0x65]);
const NUM = [0x3a, 0x63, 0x6f, 0x64, 0x65];
const U8A = new Uint8Array([0x14, ...NUM]);
const HEX = '0x3a636f6465';
describe('construction', (): void => {
it('decodes when input is string', (): void => {
expect(
new Bytes(registry, ':code').toU8a()
).toEqual(CODE);
).toEqual(U8A);
});
it('decodes when hex is not length prefixed', (): void => {
expect(
new Bytes(registry, '0x3a636f6465').toU8a()
).toEqual(CODE);
new Bytes(registry, HEX).toU8a()
).toEqual(U8A);
});
it('decodes from UInt8Array', (): void => {
expect(
new Bytes(registry, U8A).toU8a()
).toEqual(U8A);
});
it('decodes from number[]', (): void => {
expect(
new Bytes(registry, [0x3a, 0x63, 0x6f, 0x64, 0x65]).toU8a()
).toEqual(CODE);
new Bytes(registry, NUM).toU8a()
).toEqual(U8A);
});
it('creates via storagedata (no prefix)', (): void => {
expect(
new Bytes(
registry,
createType(registry, 'StorageData', '0x3a636f6465')
createType(registry, 'StorageData', HEX)
).toU8a()
).toEqual(CODE);
).toEqual(U8A);
});
it('encodes from itself', (): void => {
expect(
new Bytes(registry, new Bytes(registry, HEX)).toU8a()
).toEqual(U8A);
});
it('strips length with toU8a(true)', (): void => {
expect(
new Bytes(registry, HEX).toU8a(true)
).toEqual(U8A.subarray(1));
});
it('strips length with toHex', (): void => {
expect(
new Bytes(registry, HEX).toHex()
).toEqual(HEX);
});
});
});