Data has custom encodedLength

This commit is contained in:
Jaco Greeff
2019-12-15 09:56:30 +01:00
parent 88e4518f64
commit 382f7d75c8
2 changed files with 42 additions and 0 deletions
@@ -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: []
});
});
});
+7
View File
@@ -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
*/