From 4537a32099fd48b8cd014e07ba382c0f6e06b671 Mon Sep 17 00:00:00 2001 From: crypto-matto Date: Fri, 7 Jun 2024 12:21:09 +0800 Subject: [PATCH] fix: add test case --- lib/src/utils/address.spec.ts | 12 ++++++++++++ lib/src/utils/address.ts | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/src/utils/address.spec.ts b/lib/src/utils/address.spec.ts index fbfc81e..62f40c1 100644 --- a/lib/src/utils/address.spec.ts +++ b/lib/src/utils/address.spec.ts @@ -116,6 +116,15 @@ describe('Validate address against network and checksums', function () { it(`isAddress should return true for valid EVM address`, function () { expect(isAddress(address.EVM)).to.be.eq(true); }); + it(`isAddress should return false for non 40-length string`, function () { + expect(isAddress('should return false')).to.be.eq(false); + }); + it(`isAddress should return false for 40-length non EVM-valid string`, function () { + expect(isAddress('0xD47286f025F947482a2C374Fb70e9D4c94d809CG')).to.be.eq(false); + }); + it(`isAddress should return true for valid capitalized EVM address`, function () { + expect(isAddress(address.EVM.toUpperCase())).to.be.eq(true); + }); it(`isAddress should return true for valid trimmed EVM address`, function () { expect(isAddress(stripHexPrefix(address.EVM))).to.be.eq(true); }); @@ -125,6 +134,9 @@ describe('Validate address against network and checksums', function () { it(`checkAddressCheckSum should return false for invalid EVM address`, function () { expect(checkAddressCheckSum('0x6c46a1e212f127a6a8787b456a243c0d')).to.be.eq(false); }); + it(`checkAddressCheckSum should return false`, function () { + expect(checkAddressCheckSum('0xd47286f025F947482a2C374Fb70e9D4c94d809CF')).to.be.eq(false); + }); }); describe('AddressValidator', function () { diff --git a/lib/src/utils/address.ts b/lib/src/utils/address.ts index 8e968d9..f242be9 100644 --- a/lib/src/utils/address.ts +++ b/lib/src/utils/address.ts @@ -61,11 +61,7 @@ export function checkAddressCheckSum(data: string): boolean { return true; } -export const isAddress = (value: Uint8Array | bigint | string | number | boolean, checkChecksum = true) => { - if (typeof value !== 'string' && !isUint8Array(value)) { - return false; - } - +export const isAddress = (value: Uint8Array | string, checkChecksum = true) => { let valueToCheck: string; if (isUint8Array(value)) {