Linkage fixes (#2184)
* Fix linkage decoding * Actually fix linkage * CHANGELOG
This commit is contained in:
@@ -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]);
|
||||
});
|
||||
});
|
||||
@@ -24,6 +24,8 @@ export default class Linkage<T extends Codec> extends Struct {
|
||||
// eslint-disable-next-line sort-keys
|
||||
next: Option.with(Type)
|
||||
}, value);
|
||||
|
||||
console.error([...this.entries()]);
|
||||
}
|
||||
|
||||
public static withKey<O extends Codec> (Type: Constructor | keyof InterfaceTypes): Constructor<Linkage<O>> {
|
||||
|
||||
@@ -110,7 +110,8 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
// We have circular deps between Linkage & Struct
|
||||
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => {
|
||||
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 {
|
||||
return `Linkage<${this.next.toRawType(true)}>`;
|
||||
|
||||
Reference in New Issue
Block a user