Linkage fixes (#2184)

* Fix linkage decoding

* Actually fix linkage

* CHANGELOG
This commit is contained in:
Jaco Greeff
2020-04-16 15:41:42 +02:00
committed by GitHub
parent 03e21ea64b
commit 52ccb9fbbf
4 changed files with 47 additions and 1 deletions
+1
View File
@@ -5,6 +5,7 @@
- Fix bitfield endian encoding (Thanks to investigation by https://github.com/xlc) - Fix bitfield endian encoding (Thanks to investigation by https://github.com/xlc)
- Fix entries decoding for `Option<Number>` (& simplify, decoding correctly on rpc layer) - Fix entries decoding for `Option<Number>` (& simplify, decoding correctly on rpc layer)
- Ensure proper propagation of `api.runtimeVersion` (used for signing) after upgrade - Ensure proper propagation of `api.runtimeVersion` (used for signing) after upgrade
- Field ordering fix for deprecated `Linkage` (used in linked maps)
- `derive.account.info` now returns all field types (not only raw) - `derive.account.info` now returns all field types (not only raw)
- `Digest` has been moved to definitions, removal of `GenericDigest` type - `Digest` has been moved to definitions, removal of `GenericDigest` type
- Support `Fixed128` type - Support `Fixed128` type
+42
View File
@@ -0,0 +1,42 @@
// Copyright 2017-2020 @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 } from '../create/registry';
import Linkage from './Linkage';
const registry = new TypeRegistry();
describe('Linkage', (): void => {
it('decodes with ValidatorPrefs', (): void => {
const LINKA = { next: '5GznmRvdi5htUJKnMSWJgJUzSJJXSvWuHRSEdyUbHJZDNcwU', previous: null };
const PREFS = { commission: '100,000,000' };
// prefs sanity check
expect(
registry.createType(
'ValidatorPrefs',
'0x0284d717'
).toHuman()
).toEqual(PREFS);
// linkage sanity checks
expect(
new Linkage(registry, 'AccountId', '0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36').toHuman()
).toEqual(LINKA);
expect(
registry.createType(
'Linkage<AccountId>' as any,
'0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
).toHuman()
).toEqual(LINKA);
// actual check
expect(
registry.createType(
'(ValidatorPrefs, Linkage<AccountId>)' as any,
'0x0284d7170001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
).toHuman()
).toEqual([PREFS, LINKA]);
});
});
+2
View File
@@ -24,6 +24,8 @@ export default class Linkage<T extends Codec> extends Struct {
// eslint-disable-next-line sort-keys // eslint-disable-next-line sort-keys
next: Option.with(Type) next: Option.with(Type)
}, value); }, value);
console.error([...this.entries()]);
} }
public static withKey<O extends Codec> (Type: Constructor | keyof InterfaceTypes): Constructor<Linkage<O>> { public static withKey<O extends Codec> (Type: Constructor | keyof InterfaceTypes): Constructor<Linkage<O>> {
+2 -1
View File
@@ -110,7 +110,8 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
// We have circular deps between Linkage & Struct // We have circular deps between Linkage & Struct
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => { [TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => {
const type = `Option<${getSubType(value)}>`; const type = `Option<${getSubType(value)}>`;
const Clazz = Struct.with({ next: type, previous: type } as any); // eslint-disable-next-line sort-keys
const Clazz = Struct.with({ previous: type, next: type } as any);
ClassOf.prototype.toRawType = function (): string { ClassOf.prototype.toRawType = function (): string {
return `Linkage<${this.next.toRawType(true)}>`; return `Linkage<${this.next.toRawType(true)}>`;