-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Hardhat CLI Argument parsers don't have access to HardhatRuntimeEnv…
…ironment (#311)
- Loading branch information
1 parent
9d4f775
commit 17c8a23
Showing
12 changed files
with
160 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@layerzerolabs/ua-devtools-evm-hardhat-test": patch | ||
"@layerzerolabs/ua-devtools-evm-hardhat": patch | ||
"@layerzerolabs/devtools-evm-hardhat": patch | ||
--- | ||
|
||
Fix problems with --networks hardhat CLI argument parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/devtools-evm-hardhat/test/internal/assertions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'hardhat' | ||
import { assertDefinedNetworks } from '@/internal' | ||
import fc from 'fast-check' | ||
|
||
describe('internal/assertions', () => { | ||
describe('assertDefinedNetworks', () => { | ||
const definedNetworks = ['ethereum-mainnet', 'ethereum-testnet', 'bsc-testnet'] | ||
const definedNetworkArbitrary = fc.constantFrom(...definedNetworks) | ||
|
||
const definedNetworksArrayArbitrary = fc.array(definedNetworkArbitrary) | ||
const definedNetworksSetArbitrary = definedNetworksArrayArbitrary.map((networks) => new Set(networks)) | ||
|
||
it('should not throw if called with an array of networks defined in hardhat config', () => { | ||
fc.assert( | ||
fc.property(definedNetworksArrayArbitrary, (networks) => { | ||
expect(assertDefinedNetworks(networks)).toBe(networks) | ||
}) | ||
) | ||
}) | ||
|
||
it('should not throw if called with a Set of networks defined in hardhat config', () => { | ||
fc.assert( | ||
fc.property(definedNetworksSetArbitrary, (networks) => { | ||
expect(assertDefinedNetworks(networks)).toBe(networks) | ||
}) | ||
) | ||
}) | ||
|
||
it('should throw if called if a network has not been defined in an array', () => { | ||
fc.assert( | ||
fc.property(definedNetworksArrayArbitrary, fc.string(), (networks, network) => { | ||
fc.pre(!definedNetworks.includes(network)) | ||
|
||
expect(() => assertDefinedNetworks([...networks, network])).toThrow() | ||
}) | ||
) | ||
}) | ||
|
||
it('should throw if called if a network has not been defined in a Set', () => { | ||
fc.assert( | ||
fc.property(definedNetworksSetArbitrary, fc.string(), (networks, network) => { | ||
fc.pre(!definedNetworks.includes(network)) | ||
|
||
expect(() => assertDefinedNetworks(networks.add(network))).toThrow() | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/ua-devtools-evm-hardhat-test/test/__utils__/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createGetHreByEid } from '@layerzerolabs/devtools-evm-hardhat' | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import type { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
|
||
export const clearDeployments = async (hre: HardhatRuntimeEnvironment) => { | ||
const deployments = await hre.deployments.all() | ||
const deploymentNames = Object.keys(deployments) | ||
|
||
await Promise.all(deploymentNames.map((name) => hre.deployments.delete(name))) | ||
} | ||
|
||
export const cleanAllDeployments = async () => { | ||
const environmentFactory = createGetHreByEid() | ||
const eth = await environmentFactory(EndpointId.ETHEREUM_V2_MAINNET) | ||
const avax = await environmentFactory(EndpointId.AVALANCHE_V2_MAINNET) | ||
const bsc = await environmentFactory(EndpointId.BSC_V2_MAINNET) | ||
|
||
await Promise.all([clearDeployments(eth), clearDeployments(avax), clearDeployments(bsc)]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters