Cleanup isPedantic mismatches (#1220)
* Don't assert, warn on isPedantic mismatches * Re-apply assert
This commit is contained in:
@@ -33,6 +33,13 @@ export default class Linkage<T extends Codec> extends Struct {
|
|||||||
return this.get('next') as Option<T>;
|
return this.get('next') as Option<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Returns the base runtime type name for this instance
|
||||||
|
*/
|
||||||
|
public toRawType (): string {
|
||||||
|
return `Linkage<${this.next.toRawType(true)}>`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -115,8 +115,12 @@ export default class Option<T extends Codec> extends Base<T> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (isBare?: boolean): string {
|
||||||
return `Option<${new this._Type().toRawType()}>`;
|
const wrapped = new this._Type().toRawType();
|
||||||
|
|
||||||
|
return isBare
|
||||||
|
? wrapped
|
||||||
|
: `Option<${wrapped}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -313,22 +313,19 @@ function initType<T extends Codec = Codec, K extends string = string> (Type: Con
|
|||||||
|
|
||||||
// in pedantic mode, actually check that the encoding matches that supplied - this
|
// in pedantic mode, actually check that the encoding matches that supplied - this
|
||||||
// is much slower, but ensures that we have a 100% grasp on the actual provided value
|
// is much slower, but ensures that we have a 100% grasp on the actual provided value
|
||||||
if (isPedantic && value && value.toHex && value.toU8a) {
|
if (isPedantic && value && value.toHex && value.toU8a && !value.isEmpty) {
|
||||||
const inHex = value.toHex(true);
|
const inHex = value.toHex(true);
|
||||||
const crHex = created.toHex(true);
|
const crHex = created.toHex(true);
|
||||||
|
const hasMatch = inHex === crHex || (
|
||||||
assert(
|
(value instanceof ClassOf('StorageData')) && // input is from storage
|
||||||
inHex === crHex || // check that the hex matches, if matching, all-ok
|
(created instanceof Uint8Array) // we are a variable-length structure
|
||||||
(
|
// strip the input length
|
||||||
(value instanceof ClassOf('StorageData')) && // input is from storage
|
? (value.toU8a(true).toString() === created.toU8a().toString())
|
||||||
(created instanceof Uint8Array) // we are a variable-length structure
|
// compare raw
|
||||||
// strip the input length
|
: (value.toU8a(true).toString() === created.toU8a(true).toString())
|
||||||
? (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}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert(hasMatch, `Input doesn't match output, received ${inHex}, created ${crHex}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return created;
|
return created;
|
||||||
|
|||||||
Reference in New Issue
Block a user