From 382f7d75c8e671e460681574acac1840d13d8af8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 15 Dec 2019 09:56:30 +0100 Subject: [PATCH] Data has custom encodedLength --- .../interfaces/identity/Registration.spec.ts | 35 +++++++++++++++++++ packages/types/src/primitive/Data.ts | 7 ++++ 2 files changed, 42 insertions(+) create mode 100644 packages/types/src/interfaces/identity/Registration.spec.ts diff --git a/packages/types/src/interfaces/identity/Registration.spec.ts b/packages/types/src/interfaces/identity/Registration.spec.ts new file mode 100644 index 0000000000..5a8d0c6f75 --- /dev/null +++ b/packages/types/src/interfaces/identity/Registration.spec.ts @@ -0,0 +1,35 @@ +// 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 { TypeRegistry, createType } from '../../codec/create'; + +const registry = new TypeRegistry(); + +describe('Registration', (): void => { + it('decodes a Registration', (): void => { + expect( + createType( + registry, 'Registration', + '0x' + + '00' + // no judgements + '00a0724e180900000000000000000000' + // balance + '00' + // no length + '0399110399220399440399550399330000' + ).toJSON() + ).toEqual({ + deposit: 10000000000000, + info: { + additional: [], + display: { Raw: '0x9911' }, + email: { Raw: '0x9933' }, + image: { None: null }, + legal: { Raw: '0x9922' }, + pgpFingerprint: null, + riot: { Raw: '0x9955' }, + web: { Raw: '0x9944' } + }, + judgements: [] + }); + }); +}); diff --git a/packages/types/src/primitive/Data.ts b/packages/types/src/primitive/Data.ts index 881f0c1740..e16e5290f6 100644 --- a/packages/types/src/primitive/Data.ts +++ b/packages/types/src/primitive/Data.ts @@ -61,6 +61,13 @@ export default class Data extends Enum { }, ...decodeData(registry, value)); } + /** + * @description The encoded length + */ + public get encodedLength (): number { + return this.toU8a().length; + } + /** * @description Encodes the value as a Uint8Array as per the SCALE specifications */