Skip to content

Commit

Permalink
🪚 Add addChecksum utility to devtools-evm (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jan 30, 2024
1 parent b443aaa commit fac1c06
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/khaki-nails-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@layerzerolabs/build-lz-options": patch
"@layerzerolabs/devtools-evm": patch
"@layerzerolabs/toolbox-hardhat": patch
---

Add addChecksum utility
1 change: 1 addition & 0 deletions packages/build-lz-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"yoga-layout-prebuilt": "^1.10.0"
},
"devDependencies": {
"@ethersproject/address": "~5.7.0",
"@layerzerolabs/devtools": "~0.0.6",
"@layerzerolabs/devtools-evm": "~0.0.7",
"@layerzerolabs/io-devtools": "~0.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/devtools-evm/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
cache: false,
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools-evm/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// add all jest-extended matchers
// eslint-disable-next-line @typescript-eslint/no-var-requires
expect.extend(require('jest-extended'));
3 changes: 3 additions & 0 deletions packages/devtools-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
Expand All @@ -54,6 +55,7 @@
"@types/jest": "^29.5.11",
"fast-check": "^3.15.0",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"ts-node": "^10.9.2",
"tslib": "~2.6.2",
"tsup": "~8.0.1",
Expand All @@ -64,6 +66,7 @@
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/devtools-evm/src/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { OmniAddress } from '@layerzerolabs/devtools'
import { getAddress } from '@ethersproject/address'
import { AddressZero } from '@ethersproject/constants'

/**
Expand All @@ -9,3 +10,12 @@ import { AddressZero } from '@ethersproject/constants'
* @returns {string}
*/
export const makeZeroAddress = (address?: OmniAddress | null | undefined): string => address ?? AddressZero

/**
* Applies checksum to a given address, lower/uppercasing
* necessary characters
*
* @param {OmniAddress} address
* @returns {OmniAddress}
*/
export const addChecksum = (address: OmniAddress): OmniAddress => getAddress(address)
23 changes: 22 additions & 1 deletion packages/devtools-evm/test/address.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/// <reference types="jest-extended" />

import fc from 'fast-check'
import { AddressZero } from '@ethersproject/constants'
import { evmAddressArbitrary } from '@layerzerolabs/test-devtools'
import { makeZeroAddress } from '@/address'
import { addChecksum, makeZeroAddress } from '@/address'
import { isAddress } from '@ethersproject/address'

describe('address', () => {
describe('makeZeroAddress', () => {
Expand All @@ -27,4 +30,22 @@ describe('address', () => {
expect(makeZeroAddress(null)).toBe(AddressZero)
})
})

describe('addChecksum', () => {
it('should return the same address, just checksumed', () => {
fc.assert(
fc.property(evmAddressArbitrary, (address) => {
expect(addChecksum(address)).toEqualCaseInsensitive(address)
})
)
})

it('should return a valid EVM address', () => {
fc.assert(
fc.property(evmAddressArbitrary, (address) => {
expect(isAddress(addChecksum(address))).toBe(true)
})
)
})
})
})
1 change: 1 addition & 0 deletions packages/toolbox-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/hash": "^5.7.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/ua-devtools-evm-hardhat-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@babel/core": "^7.23.7",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "~5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
Expand Down

0 comments on commit fac1c06

Please sign in to comment.