Rewrite yarn.lock (#2127)

This commit is contained in:
Jaco Greeff
2020-04-01 23:49:56 +02:00
committed by GitHub
parent 1f97c5e9e3
commit 58de0b8b9c
37 changed files with 172 additions and 154 deletions
@@ -38,6 +38,7 @@ describe('BTreeMap', (): void => {
placeholder: U32,
value: 'BTreeMap<Text, U32>' as any
});
s.set('value', new (BTreeMap.with(Text, U32))(registry, mockU32TextMap));
expect(s.toString()).toBe('{"placeholder":0,"value":{"bazzing":69}}');
});
@@ -13,10 +13,12 @@ import BTreeSet from './BTreeSet';
const registry = new TypeRegistry();
const mockU32Set = new Set<U32>();
mockU32Set.add(new U32(registry, 2));
mockU32Set.add(new U32(registry, 24));
mockU32Set.add(new U32(registry, 30));
mockU32Set.add(new U32(registry, 80));
const mockU32SetString = '[2,24,30,80]';
const mockU32SetObject = [2, 24, 30, 80];
const mockU32SetHexString = '0x1002000000180000001e00000050000000';
@@ -44,6 +46,7 @@ describe('BTreeSet', (): void => {
const testEncode = (to: CodecTo, expected: any): void =>
it(`can encode ${to}`, (): void => {
const s = new BTreeSet(registry, U32, mockU32Set);
expect(s[to]()).toEqual(expected);
});
@@ -74,6 +77,7 @@ describe('BTreeSet', (): void => {
placeholder: U32,
value: BTreeSet.with(U32)
});
s.set('value', new BTreeSet(registry, U32, mockU32Set));
expect(s.toString()).toBe('{"placeholder":0,"value":[2,24,30,80]}');
});
+6
View File
@@ -11,17 +11,21 @@ import CodecMap from './Map';
const registry = new TypeRegistry();
const mockU32TextMap = new Map<Text, U32>();
mockU32TextMap.set(new Text(registry, 'bazzing'), new U32(registry, 69));
const mockU32TextMapString = '{"bazzing":69}';
const mockU32TextMapObject = { bazzing: 69 };
const mockU32TextMapHexString = '0x041c62617a7a696e6745000000';
const mockU32TextMapUint8Array = Uint8Array.from([4, 28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0]);
const mockU32U32Map = new Map<U32, U32>();
mockU32U32Map.set(new U32(registry, 1), new U32(registry, 2));
mockU32U32Map.set(new U32(registry, 23), new U32(registry, 24));
mockU32U32Map.set(new U32(registry, 28), new U32(registry, 30));
mockU32U32Map.set(new U32(registry, 45), new U32(registry, 80));
const mockU32U32MapString = '{"1":2,"23":24,"28":30,"45":80}';
const mockU32U32MapObject = { 1: 2, 23: 24, 28: 30, 45: 80 };
const mockU32U32MapHexString = '0x10043102000000083233180000000832381e00000008343550000000';
@@ -49,6 +53,7 @@ describe('CodecMap', (): void => {
const testEncode = (to: CodecTo, expected: any): void =>
it(`can encode ${to}`, (): void => {
const s = new CodecMap(registry, 'BTreeMap', Text, U32, mockU32TextMap);
expect(s[to]()).toEqual(expected);
});
@@ -62,6 +67,7 @@ describe('CodecMap', (): void => {
const testEncode = (to: CodecTo, expected: any): void =>
it(`can encode ${to}`, (): void => {
const s = new CodecMap(registry, 'BTreeMap', Text, U32, mockU32U32Map);
expect(s[to]()).toEqual(expected);
});
+4
View File
@@ -22,6 +22,7 @@ describe('Struct', (): void => {
foo: Text,
bar: U32
}, input);
expect([...s.keys()]).toEqual(['foo', 'bar']);
expect(
[...s.values()].map((v): string =>
@@ -43,6 +44,7 @@ describe('Struct', (): void => {
foo: Text,
bar: U32
}, { foo: 'bazzing', bar: 69 });
expect(s[to]()).toEqual(expected);
});
@@ -81,6 +83,7 @@ describe('Struct', (): void => {
bar: Text
}))
}, { foo: [{ bar: 1 }, { bar: 2 }] });
expect(s.toString()).toBe('{"foo":[{"bar":"1"},{"bar":"2"}]}');
});
@@ -94,6 +97,7 @@ describe('Struct', (): void => {
foo: U32,
bar: U32
}, input);
expect(s.toString()).toEqual('{"txt":"fubar","foo":0,"bar":0}');
});
+1
View File
@@ -34,6 +34,7 @@ describe('Tuple', (): void => {
Text,
U32
], input);
expect(
t.toJSON()
).toEqual(['bazzing', 69]);
+1
View File
@@ -51,6 +51,7 @@ export default class Tuple extends AbstractArray<Codec> {
return Types.map((Type, index): Codec => {
try {
if (value?.[index] instanceof Type) return value[index] as any;
return new Type(registry, value?.[index]);
} catch (error) {
throw new Error(`Tuple: failed on ${index}:: ${error.message}`);
+1
View File
@@ -12,6 +12,7 @@ function isNotNested (...counters: number[]): boolean {
export function typeSplit (type: string): string[] {
let [cDepth, fDepth, sDepth, tDepth, start] = [0, 0, 0, 0, 0];
const result = [];
const extract = (index: number): void => {
if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
result.push(type.substr(start, index - start).trim());
@@ -76,7 +76,9 @@ export class MortalEra extends Tuple {
private static decodeMortalObject (registry: Registry, value: MortalMethod): MortalEraValue {
const { current, period } = value;
let calPeriod = Math.pow(2, Math.ceil(Math.log2(period)));
calPeriod = Math.min(Math.max(calPeriod, 4), 1 << 16);
const phase = current % calPeriod;
const quantizeFactor = Math.max(calPeriod >> 12, 1);
const quantizedPhase = phase / quantizeFactor * quantizeFactor;
@@ -30,6 +30,7 @@ describe('AccountId', (): void => {
const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string): void =>
it(`can decode from ${type}`, (): void => {
const a = registry.createType('AccountId', input);
expect(a.toString()).toBe(expected);
});
@@ -13,6 +13,7 @@ describe('Address', (): void => {
const testDecode = (type: string, input: Address | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
it(`can decode from ${type}`, (): void => {
const a = registry.createType('Address', input);
expect(a.toString()).toBe(expected);
});
@@ -98,6 +99,7 @@ describe('Address', (): void => {
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: string | Uint8Array): void =>
it(`can encode ${to}`, (): void => {
const a = registry.createType('Address', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
expect(a[to]()).toEqual(expected);
});
+1
View File
@@ -32,6 +32,7 @@ function getArgsDef (registry: Registry, meta: FunctionMetadataLatest): ArgsDef
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return Call.filterOrigin(meta).reduce((result, { name, type }): ArgsDef => {
const Type = getTypeClass(registry, getTypeDef(type.toString()));
result[name.toString()] = Type;
return result;