Check ss58 for additions (#257)

This commit is contained in:
Jaco
2021-04-14 09:12:07 +03:00
committed by GitHub
parent 227de97747
commit 1f240c0b0b
2 changed files with 26 additions and 3 deletions
+1 -1
View File
@@ -152,7 +152,7 @@ describe('addrcheck', (): void => {
const results = _results.map(([url, addrs]): [string, string[]] => {
return [url, addrs.filter((a) => {
try {
return !!decodeAddress(a);
return decodeAddress(a).length === 32;
} catch (error) {
console.error(url, (error as Error).message);
+25 -2
View File
@@ -1,7 +1,9 @@
// Copyright 2020-2021 @polkadot/phishing authors & contributors
// SPDX-License-Identifier: Apache-2.0
import denied from '../../../address.json';
import { decodeAddress } from '@polkadot/util-crypto';
import addresses from '../../../address.json';
import allowed from '../../../known.json';
import { checkAddress, checkIfDenied } from '.';
@@ -64,9 +66,30 @@ describe('checkAddress', (): void => {
});
describe('check additions', (): void => {
it('has no malformed addresses', (): void => {
const invalids = Object
.entries(addresses as Record<string, string[]>)
.map(([url, addrs]): [string, string[]] => {
return [url, addrs.filter((a) => {
try {
return decodeAddress(a).length !== 32;
} catch (error) {
console.error(url, (error as Error).message);
return true;
}
})];
})
.filter(([, addrs]) => addrs.length);
if (invalids.length) {
throw new Error(`Invalid ss58 checksum addresses found: ${invalids.map(([url, addrs]) => `\n\t${url}: ${addrs.join(', ')}`).join('')}`);
}
});
it('has no entries on the known addresses list', (): void => {
const added = Object
.values(denied as Record<string, string[]>)
.values(addresses as Record<string, string[]>)
.reduce<string[]>((all, addrs) => all.concat(addrs), []);
const dupes = Object
.entries(allowed as Record<string, string[]>)