Skip to content

Commit 4806416

Browse files
authored
Merge pull request #184 from 0xs34n/feature/checksum-addresses
2 parents fd0c9c6 + ebe05f6 commit 4806416

File tree

8 files changed

+129
-7922
lines changed

8 files changed

+129
-7922
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ npm-debug.log
55
.DS_Store
66
.eslintcache
77
coverage
8+
yarn.lock

__tests__/utils/address.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { addAddressPadding, validateAndParseAddress } from '../../src/utils/address';
1+
import {
2+
addAddressPadding,
3+
getChecksumAddress,
4+
validateAndParseAddress,
5+
validateChecksumAddress,
6+
} from '../../src/utils/address';
27
// import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
38

49
describe('validateAndParseAddress', () => {
@@ -14,3 +19,27 @@ describe('validateAndParseAddress', () => {
1419
return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
1520
});
1621
});
22+
23+
describe('address checksums', () => {
24+
test('should be able to calculate checksum address', () => {
25+
const checksumAddress = getChecksumAddress(
26+
'0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914'
27+
);
28+
expect(checksumAddress).toEqual(
29+
'0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
30+
);
31+
});
32+
test('should be able to verify checksum address', () => {
33+
const isValid = validateChecksumAddress(
34+
'0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
35+
);
36+
expect(isValid).toEqual(true);
37+
});
38+
test('calculated checksum address should validate', () => {
39+
const checksumAddress = getChecksumAddress(
40+
'0x26cb0b500d175111341fabb53bf7fa4f5a0b8c5cbb31896cec1e8383a5edda8'
41+
);
42+
const isValid = validateChecksumAddress(checksumAddress);
43+
expect(isValid).toEqual(true);
44+
});
45+
});

0 commit comments

Comments
 (0)