Files
common/packages/trie-codec/src/decode.spec.ts
T
Jaco Greeff f82092e603 Allow blake2 & parity-codec in trie (#251)
* Start codec implementation

* Expose all constants

* NodeHeader encoding/decoding

* Encoding in NodeHeader

* Constants for Node types

* Moce codec to trie-codec

* Encode/decode in place (untested)

* WIP, tests starting to be put in place

* One passing test :)

* Another test bites the dust...

* One more test down...

* One more down

* Additional tests

* Formatting

* Long keys passing

* Trie tests

* Follow the script, no all-in-all encoder

* First simple trie test passing

* Another one down

* Extra checks remove (debug)

* 80% there with tests...

* One more, one left

* Trie tests passing

* ISC -> Apache-2.0

* Add compact util functions

* Tests to TypeScript

* Remove @polkadot/types deps, ethereum stub

* Bump

* Genesis tests with chainspecs

* Cleanup tests (ease of debugging)

* Substrate test passes, branch fails (again)

* Checks passing, tests passing

* Re-add Ethereum & snapshot tests (not passing atm)

* Re-add index test (also not 100%)

* Mid-way in generic trie-root

* Cleanup ethereumjs-testing definitions

* Update deps

* Less intrusive renames in trie-hash

* Self-review cleanups #1

* asNibbles -> toNibbles

* Cleanups

* Expand tests

* Cleanup imports

* Fix logger test (fly-by refactor)

* Update snapshot test
2018-11-22 14:29:34 +01:00

75 lines
2.0 KiB
TypeScript

// Copyright 2017-2018 @polkadot/trie-codec 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 { hexToU8a } from '@polkadot/util/index';
import decode from './decode';
describe('decode', () => {
it('decodes a leaf', () => {
expect(
decode(Uint8Array.from([
0x05, 0x48, 0x19, 0x04, 0xfe
]))
).toEqual([
Uint8Array.from([0x20, 0x48, 0x19]),
Uint8Array.from([0xfe])
]);
});
it('decodes a branch', () => {
expect(
decode(Uint8Array.from([
0xfe, 0x00, 0x0c, 0x48, 0x81, 0x0a, 0x3c, 0xff, 0x00, 0x0c, 0x04, 0xa0, 0x10, 0x02, 0x0a, 0x04,
0xaa, 0x10, 0x02, 0x0b, 0x04, 0xab, 0x10, 0x02, 0x0b, 0x04, 0xb0
]))
).toEqual([
null, null, null, null, null, null, null, null, null, null,
[
Uint8Array.from([26]),
Uint8Array.from([255, 0, 12, 4, 160, 16, 2, 10, 4, 170, 16, 2, 11, 4, 171])
],
[
Uint8Array.from([59]),
Uint8Array.from([176])
],
null, null, null, null, null
]);
});
it('decodes a complex branch', () => {
expect(
decode(hexToU8a(
'0xfe8c00682007b3872d47181b4a2dc15f0da43e702620e80300000000000080170d322ac49d8708f151346c68d9e58452d83a9d3b710e1ead35eb3269ab235368200935e46f94f24b82716c0142e2271de9200087000000000000'
))
).toEqual([
null,
null,
[
hexToU8a('0x37b3872d47181b4a2dc15f0da43e7026'),
hexToU8a('0xe803000000000000')
],
Uint8Array.from([
23, 13, 50, 42, 196, 157, 135, 8, 241, 81, 52, 108, 104, 217, 229, 132, 82, 216, 58, 157, 59, 113, 14, 30, 173, 53, 235, 50, 105, 171, 35, 83
]),
null,
null,
null,
[
hexToU8a('0x3935e46f94f24b82716c0142e2271de9'),
hexToU8a('0x0087000000000000')
],
null,
null,
null,
null,
null,
null,
null,
null,
null
]);
});
});