Loosen pedantic check for fully-empty compares (#3873)

* Loosen pedantic check for fully-empty compares

* Bump dev

* Update CHANGELOG

* Bump common
This commit is contained in:
Jaco
2021-08-13 13:16:17 +02:00
committed by GitHub
parent 07594a33b5
commit ce7968f870
13 changed files with 163 additions and 155 deletions
+4 -4
View File
@@ -19,13 +19,13 @@
"bugs": "https://github.com/polkadot-js/api/issues",
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.14.8",
"@polkadot/util": "^7.1.1",
"@polkadot/util-crypto": "^7.1.1",
"@babel/runtime": "^7.15.3",
"@polkadot/util": "^7.1.3-3",
"@polkadot/util-crypto": "^7.1.3-3",
"rxjs": "^7.3.0"
},
"devDependencies": {
"@polkadot/keyring": "^7.1.1",
"@polkadot/keyring": "^7.1.3-3",
"@polkadot/types-support": "5.4.2-5",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.11.9"
+15 -8
View File
@@ -12,18 +12,25 @@ import { createClass } from './createClass';
// With isPedantic, actually check that the encoding matches that supplied. This
// is much slower, but verifies that we have the correct types defined
function checkInstance (created: Codec, value: Uint8Array): void {
function checkInstance (created: Codec, matcher: Uint8Array): void {
const u8a = created.toU8a();
const rawType = created.toRawType();
assert(
u8aEq(value, u8a) || (
// when length-prefixed from hex, just check the actual length
const isOk = (
// full match, all ok
u8aEq(u8a, matcher) ||
(
// on a length-prefixed type, just check the actual length
['Bytes', 'Text', 'Type'].includes(rawType) &&
value.length === (created as Bytes).length
),
() => `${rawType}:: Decoded input doesn't match input, received ${u8aToHex(value, 512)} (${value.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`
matcher.length === (created as Bytes).length
) ||
(
// when the created is empty and matcher is also empty, let it slide...
created.isEmpty &&
matcher.every((v) => !v)
)
);
assert(isOk, () => `${rawType}:: Decoded input doesn't match input, received ${u8aToHex(matcher, 512)} (${matcher.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`);
}
function checkPedantic (created: Codec, [value]: unknown[], isPedantic = false): void {