Linked queries accept params again (#1217)
* Linked queries accept params again * Remove invalidated test, cleanup prefix strip
This commit is contained in:
@@ -7,6 +7,8 @@ import { Constructor, Codec } from '../types';
|
||||
|
||||
type TypeWithValues = [Constructor, any[]];
|
||||
|
||||
const EMPTY = new Uint8Array();
|
||||
|
||||
export default class Linkage<T extends Codec> extends Struct {
|
||||
public constructor (Type: Constructor, value?: any) {
|
||||
super({
|
||||
@@ -30,6 +32,15 @@ export default class Linkage<T extends Codec> extends Struct {
|
||||
public get next (): Option<T> {
|
||||
return this.get('next') as Option<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
return isBare && this.isEmpty
|
||||
? EMPTY
|
||||
: super.toU8a();
|
||||
}
|
||||
}
|
||||
|
||||
export class LinkageResult extends Tuple {
|
||||
|
||||
@@ -273,22 +273,6 @@ describe('createType', (): void => {
|
||||
).toEqual(new Uint8Array([0x00, 0x12, 0x00, 0x23, 0x00, 0x45, 0x00, 0x67]));
|
||||
});
|
||||
|
||||
it('throw error when create base is a StorageData with null value and isPedantic is true', (): void => {
|
||||
const base = createType('StorageData', null);
|
||||
|
||||
expect(
|
||||
(): Codec => createTypeUnsafe('DoubleMap<Vec<(BlockNumber,EventIndex)>>', [base], true)
|
||||
).toThrow(/ Input doesn't match output, received 0x, created 0x00/);
|
||||
});
|
||||
|
||||
it('throw error when create base is a StorageData with null value and isPedantic is true', (): void => {
|
||||
const base = createType('StorageData', null);
|
||||
|
||||
expect(
|
||||
(): Codec => createTypeUnsafe('Vec<(BlockNumber,EventIndex)>', [base], true)
|
||||
).toThrow(/Input doesn't match output, received 0x, created 0x00/);
|
||||
});
|
||||
|
||||
describe('instanceof', (): void => {
|
||||
it('instanceof should work (primitive type)', (): void => {
|
||||
const value = createType('Balance', 1234);
|
||||
|
||||
@@ -321,8 +321,11 @@ function initType<T extends Codec = Codec, K extends string = string> (Type: Con
|
||||
inHex === crHex || // check that the hex matches, if matching, all-ok
|
||||
(
|
||||
(value instanceof ClassOf('StorageData')) && // input is from storage
|
||||
(created instanceof Uint8Array) && // we are a variable-lneght structure
|
||||
(value.toU8a(true).toString() === created.toU8a().toString()) // strip the input length
|
||||
(created instanceof Uint8Array) // we are a variable-length structure
|
||||
// strip the input length
|
||||
? (value.toU8a(true).toString() === created.toU8a().toString())
|
||||
// compare raw
|
||||
: (value.toU8a(true).toString() === created.toU8a(true).toString()) // check raw
|
||||
),
|
||||
`Input doesn't match output, received ${inHex}, created ${crHex}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user