Fix CompactAssignment decoding (#2242)
* Fix CompactAssignment decoding * CHANGELOG
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
- Add support for ECDSA keypairs in extrinsic signers (Thanks to https://github.com/akru)
|
||||
- Rework type generation to use templating for better maintenance (Thanks to https://github.com/xlc)
|
||||
- Adjust extrinsic `sign/signAsync` signature to optional options (Thanks to https://github.com/KiChjang)
|
||||
- Remove static test-only metadata for Polkadot dev chains (not updated regularly, Substrate dev to remain)
|
||||
- Revert error swallow for wrong preimage data (temp. override for Kusama upgrade with no migration)
|
||||
- Fix `.encodedLength` calculation on `[Type; N]` types
|
||||
- Update types & metadata as per latest Substrate master
|
||||
|
||||
# 1.12.2 Apr 30, 2020
|
||||
|
||||
@@ -44,13 +44,21 @@ describe('Tuple', (): void => {
|
||||
testDecode('hex', '0x1c62617a7a696e6745000000');
|
||||
testDecode('Uint8Array', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0]));
|
||||
|
||||
it('decodes reusing instanciated inputs', (): void => {
|
||||
it('decodes reusing instantiated inputs', (): void => {
|
||||
const foo = new Text(registry, 'bar');
|
||||
|
||||
expect(
|
||||
(new Tuple(registry, [Text], [foo]))[0]
|
||||
).toBe(foo);
|
||||
});
|
||||
|
||||
it('decodes properly from complex types', (): void => {
|
||||
const INPUT = '0xcc0200000000';
|
||||
const test = registry.createType('(u32, [u32; 0], u16)' as any, INPUT);
|
||||
|
||||
expect(test.encodedLength).toEqual(4 + 0 + 2);
|
||||
expect(test.toHex()).toEqual(INPUT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encoding', (): void => {
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('Vec', (): void => {
|
||||
expect(vector.Type).toEqual('Text');
|
||||
});
|
||||
|
||||
it('decodes reusing instanciated inputs', (): void => {
|
||||
it('decodes reusing instantiated inputs', (): void => {
|
||||
const foo = new Text(registry, 'bar');
|
||||
|
||||
expect(
|
||||
@@ -79,6 +79,14 @@ describe('Vec', (): void => {
|
||||
expect((first[1] as AccountId).toString()).toEqual('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua');
|
||||
});
|
||||
|
||||
it('decodes a complex type via construction', (): void => {
|
||||
const INPUT = '0x08cc0200000000ce0200000001';
|
||||
const test = createTypeUnsafe(registry, 'Vec<(u32, [u32; 0], u16)>' as any, [INPUT]);
|
||||
|
||||
expect((test as Vec<any>).length).toEqual(2);
|
||||
expect(test.toHex()).toEqual(INPUT);
|
||||
});
|
||||
|
||||
describe('vector-like functions', (): void => {
|
||||
it('allows retrieval of a specific item', (): void => {
|
||||
expect(
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('VecFixed', (): void => {
|
||||
expect(new VecFixed(registry, Text, 2, new Uint8Array([0x00, 0x04, 0x31])).toHex()).toEqual('0x000431');
|
||||
});
|
||||
|
||||
it('decodes reusing instanciated inputs', (): void => {
|
||||
it('decodes reusing instance inputs', (): void => {
|
||||
const foo = new Text(registry, 'bar');
|
||||
|
||||
expect(
|
||||
@@ -43,5 +43,19 @@ describe('VecFixed', (): void => {
|
||||
// each entry length 1 << 2, char as hex (0x31 === `1`), one empty
|
||||
expect(test.toHex()).toEqual('0x043104320433000435');
|
||||
});
|
||||
|
||||
it('has empty Uint8Array when length is 0', (): void => {
|
||||
const test = new (VecFixed.with(Text, 0))(registry);
|
||||
|
||||
expect(test.encodedLength).toEqual(0);
|
||||
expect(test.toU8a()).toEqual(new Uint8Array([]));
|
||||
});
|
||||
|
||||
it('has equivalent to 1 Uint8Array when length is 1', (): void => {
|
||||
const test = new (VecFixed.with(Text, 1))(registry, ['hello']);
|
||||
|
||||
expect(test.encodedLength).toEqual(1 + 5);
|
||||
expect(test.toU8a()).toEqual(new Uint8Array([20, 104, 101, 108, 108, 111]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,12 +59,21 @@ export default class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
return new this._Type(this.registry).toRawType();
|
||||
}
|
||||
|
||||
public toU8a (): Uint8Array {
|
||||
// we override, we don't add the length prefix for outselves, and at the same time we
|
||||
// ignore isBare on entries, since they should be properly encoded at all times
|
||||
const encoded = this.map((entry): Uint8Array => entry.toU8a());
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
return this.toU8a().length;
|
||||
}
|
||||
|
||||
return u8aConcat(...encoded);
|
||||
public toU8a (): Uint8Array {
|
||||
// we override, we don't add the length prefix for ourselves, and at the same time we
|
||||
// ignore isBare on entries, since they should be properly encoded at all times
|
||||
const encoded = this.map((entry) => entry.toU8a());
|
||||
|
||||
return encoded.length
|
||||
? u8aConcat(...encoded)
|
||||
: new Uint8Array([]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -24,24 +24,24 @@ export default {
|
||||
start: 'Option<Moment>'
|
||||
},
|
||||
CompactAssignments: {
|
||||
votes1: 'Vec<(ValidatorIndex, [CompactScore; 0], NominatorIndex)>',
|
||||
votes2: 'Vec<(ValidatorIndex, [CompactScore; 1], NominatorIndex)>',
|
||||
votes3: 'Vec<(ValidatorIndex, [CompactScore; 2], NominatorIndex)>',
|
||||
votes4: 'Vec<(ValidatorIndex, [CompactScore; 3], NominatorIndex)>',
|
||||
votes5: 'Vec<(ValidatorIndex, [CompactScore; 4], NominatorIndex)>',
|
||||
votes6: 'Vec<(ValidatorIndex, [CompactScore; 5], NominatorIndex)>',
|
||||
votes7: 'Vec<(ValidatorIndex, [CompactScore; 6], NominatorIndex)>',
|
||||
votes8: 'Vec<(ValidatorIndex, [CompactScore; 7], NominatorIndex)>',
|
||||
votes9: 'Vec<(ValidatorIndex, [CompactScore; 8], NominatorIndex)>',
|
||||
votes10: 'Vec<(ValidatorIndex, [CompactScore; 9], NominatorIndex)>',
|
||||
votes11: 'Vec<(ValidatorIndex, [CompactScore; 10], NominatorIndex)>',
|
||||
votes12: 'Vec<(ValidatorIndex, [CompactScore; 11], NominatorIndex)>',
|
||||
votes13: 'Vec<(ValidatorIndex, [CompactScore; 12], NominatorIndex)>',
|
||||
votes14: 'Vec<(ValidatorIndex, [CompactScore; 13], NominatorIndex)>',
|
||||
votes15: 'Vec<(ValidatorIndex, [CompactScore; 14], NominatorIndex)>',
|
||||
votes16: 'Vec<(ValidatorIndex, [CompactScore; 15], NominatorIndex)>'
|
||||
votes1: 'Vec<(NominatorIndex, [CompactScore; 0], ValidatorIndex)>',
|
||||
votes2: 'Vec<(NominatorIndex, [CompactScore; 1], ValidatorIndex)>',
|
||||
votes3: 'Vec<(NominatorIndex, [CompactScore; 2], ValidatorIndex)>',
|
||||
votes4: 'Vec<(NominatorIndex, [CompactScore; 3], ValidatorIndex)>',
|
||||
votes5: 'Vec<(NominatorIndex, [CompactScore; 4], ValidatorIndex)>',
|
||||
votes6: 'Vec<(NominatorIndex, [CompactScore; 5], ValidatorIndex)>',
|
||||
votes7: 'Vec<(NominatorIndex, [CompactScore; 6], ValidatorIndex)>',
|
||||
votes8: 'Vec<(NominatorIndex, [CompactScore; 7], ValidatorIndex)>',
|
||||
votes9: 'Vec<(NominatorIndex, [CompactScore; 8], ValidatorIndex)>',
|
||||
votes10: 'Vec<(NominatorIndex, [CompactScore; 9], ValidatorIndex)>',
|
||||
votes11: 'Vec<(NominatorIndex, [CompactScore; 10], ValidatorIndex)>',
|
||||
votes12: 'Vec<(NominatorIndex, [CompactScore; 11], ValidatorIndex)>',
|
||||
votes13: 'Vec<(NominatorIndex, [CompactScore; 12], ValidatorIndex)>',
|
||||
votes14: 'Vec<(NominatorIndex, [CompactScore; 13], ValidatorIndex)>',
|
||||
votes15: 'Vec<(NominatorIndex, [CompactScore; 14], ValidatorIndex)>',
|
||||
votes16: 'Vec<(NominatorIndex, [CompactScore; 15], ValidatorIndex)>'
|
||||
},
|
||||
CompactScore: '(u16, OffchainAccuracy)',
|
||||
CompactScore: '(ValidatorIndex, OffchainAccuracy)',
|
||||
ElectionCompute: {
|
||||
_enum: ['OnChain', 'Signed', 'Authority']
|
||||
},
|
||||
|
||||
@@ -14,26 +14,26 @@ export interface ActiveEraInfo extends Struct {
|
||||
|
||||
/** @name CompactAssignments */
|
||||
export interface CompactAssignments extends Struct {
|
||||
readonly votes1: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes2: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes3: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes4: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes5: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes6: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes7: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes8: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes9: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes10: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes11: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes12: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes13: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes14: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes15: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes16: Vec<ITuple<[ValidatorIndex, Vec<CompactScore>, NominatorIndex]>>;
|
||||
readonly votes1: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes2: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes3: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes4: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes5: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes6: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes7: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes8: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes9: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes10: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes11: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes12: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes13: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes14: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes15: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
readonly votes16: Vec<ITuple<[NominatorIndex, Vec<CompactScore>, ValidatorIndex]>>;
|
||||
}
|
||||
|
||||
/** @name CompactScore */
|
||||
export interface CompactScore extends ITuple<[u16, OffchainAccuracy]> {}
|
||||
export interface CompactScore extends ITuple<[ValidatorIndex, OffchainAccuracy]> {}
|
||||
|
||||
/** @name ElectionCompute */
|
||||
export interface ElectionCompute extends Enum {
|
||||
|
||||
Reference in New Issue
Block a user