Files
common/packages/trie-hash/src/encode/hexPrefix.spec.js
T
Jaco Greeff 78e01a0e16 Combine util, types & trie into common (#150)
* Pull in trie repo

* Bring in types repo
2018-06-26 21:26:51 +02:00

74 lines
1.4 KiB
JavaScript

// Copyright 2017-2018 @polkadot/trie-hash authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import encodeHexPrefix from './hexPrefix';
describe('encodeHexPrefix', () => {
it('encodes [0, 0, 1, 2, 3, 4, 5], false', () => {
expect(
encodeHexPrefix(
[0, 0, 1, 2, 3, 4, 5],
false
)
).toEqual(
new Uint8Array([0x10, 0x01, 0x23, 0x45])
);
});
it('encodes [0, 1, 2, 3, 4, 5], false', () => {
expect(
encodeHexPrefix(
[0, 1, 2, 3, 4, 5],
false
)
).toEqual(
new Uint8Array([0x00, 0x01, 0x23, 0x45])
);
});
it('encodes [0, 1, 2, 3, 4, 5], true', () => {
expect(
encodeHexPrefix(
[0, 1, 2, 3, 4, 5],
true
)
).toEqual(
new Uint8Array([0x20, 0x01, 0x23, 0x45])
);
});
it('encodes [1, 2, 3, 4, 5], true', () => {
expect(
encodeHexPrefix(
[1, 2, 3, 4, 5],
true
)
).toEqual(
new Uint8Array([0x31, 0x23, 0x45])
);
});
it('encodes [1, 2, 3, 4], false', () => {
expect(
encodeHexPrefix(
[1, 2, 3, 4],
false
)
).toEqual(
new Uint8Array([0x00, 0x12, 0x34])
);
});
it('encodes [4, 1], true', () => {
expect(
encodeHexPrefix(
[4, 1],
true
)
).toEqual(
new Uint8Array([0x20, 0x41])
);
});
});