Skip to content

Commit

Permalink
fix: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto-matto committed Jun 7, 2024
1 parent 60ea7b0 commit 4537a32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/src/utils/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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 () {
Expand Down
6 changes: 1 addition & 5 deletions lib/src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 4537a32

Please sign in to comment.