-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add collectDeployments utility to utils-evm-hardhat
- Loading branch information
1 parent
4c54913
commit 69d82b4
Showing
7 changed files
with
187 additions
and
9 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
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
File renamed without changes.
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,39 @@ | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import { Deployment } from 'hardhat-deploy/dist/types' | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
import { assertHardhatDeploy } from '../internal/assertions' | ||
import { getNetworkNamesByEid, getNetworkRuntimeEnvironment } from '../runtime' | ||
|
||
export interface OmniDeployment { | ||
eid: EndpointId | ||
deployment: Deployment | ||
} | ||
|
||
/** | ||
* Collects all deployment of a certain contract along with their endpoint IDs. | ||
* | ||
* Network s which don't have `endpointId` configured in their hardhat network config will be ignored | ||
* | ||
* @param hre `HardhatRuntimeEnvironment` | ||
* @param contractName `string` | ||
* @returns `OmniDeployment[]` | ||
*/ | ||
export const collectDeployments = async ( | ||
hre: HardhatRuntimeEnvironment, | ||
contractName: string | ||
): Promise<OmniDeployment[]> => { | ||
assertHardhatDeploy(hre) | ||
|
||
const deployments: OmniDeployment[] = [] | ||
const networkNamesByEid = getNetworkNamesByEid(hre) | ||
|
||
for (const [eid, networkName] of networkNamesByEid) { | ||
const env = await getNetworkRuntimeEnvironment(networkName) | ||
const deployment = await env.deployments.getOrNull(contractName) | ||
if (deployment == null) continue | ||
|
||
deployments.push({ eid, deployment }) | ||
} | ||
|
||
return deployments | ||
} |
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 @@ | ||
export * from './coordinates' |
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
118 changes: 118 additions & 0 deletions
118
packages/utils-evm-hardhat/test/omnigraph/coordinates.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,118 @@ | ||
import { collectDeployments } from '../../src/omnigraph' | ||
import { expect } from 'chai' | ||
import { describe } from 'mocha' | ||
import hre from 'hardhat' | ||
import { DeploymentSubmission } from 'hardhat-deploy/dist/types' | ||
import { getNetworkRuntimeEnvironment } from '../../src/runtime' | ||
|
||
describe('omnigraph/coordinates', () => { | ||
beforeEach(async () => { | ||
const bscTestnetRuntime = await getNetworkRuntimeEnvironment('bsc-testnet') | ||
const ethMainnetRuntime = await getNetworkRuntimeEnvironment('ethereum-mainnet') | ||
const ethTestnetRuntime = await getNetworkRuntimeEnvironment('ethereum-testnet') | ||
|
||
await bscTestnetRuntime.deployments.delete('MyWeirdContract') | ||
await ethMainnetRuntime.deployments.delete('MyWeirdContract') | ||
await ethTestnetRuntime.deployments.delete('MyWeirdContract') | ||
}) | ||
|
||
describe('collectDeployments', () => { | ||
it('should return an empty array if there are no deployments', async () => { | ||
const deployments = await collectDeployments(hre, 'NonExistentContract') | ||
|
||
expect(deployments).to.eql([]) | ||
}) | ||
|
||
it('should skip a network if endpointId is missing', async () => { | ||
// First we make sure that the network we want to deploy to has no endpointId | ||
const bscRuntime = await getNetworkRuntimeEnvironment('bsc-testnet') | ||
expect(bscRuntime.network.config.endpointId).to.be.undefined | ||
|
||
// Now we create a mock deployment | ||
const now = Date.now() | ||
const deploymentSubmission = { | ||
args: [now], | ||
} as DeploymentSubmission | ||
|
||
// Save it | ||
await bscRuntime.deployments.save('MyWeirdContract', deploymentSubmission) | ||
|
||
// And check that it will not be picked up | ||
const deployments = await collectDeployments(hre, 'MyWeirdContract') | ||
|
||
expect(deployments).to.eql([]) | ||
}) | ||
|
||
it('should skip a network if deployment is missing', async () => { | ||
// First we make sure that the network we want to deploy to has an endpointId | ||
const ethRuntime = await getNetworkRuntimeEnvironment('ethereum-mainnet') | ||
expect(ethRuntime.network.config.endpointId).not.to.be.undefined | ||
|
||
// Now we create a mock deployment | ||
const now = Date.now() | ||
const deploymentSubmission = { | ||
args: [now], | ||
} as DeploymentSubmission | ||
|
||
// Save it | ||
await ethRuntime.deployments.save('MyWeirdContract', deploymentSubmission) | ||
|
||
// And check that it will not be picked up | ||
const deployments = await collectDeployments(hre, 'MyWeirdContract') | ||
|
||
// Now check that bsc-testnet and ethereum-testnet did not get included | ||
expect(deployments).to.eql([ | ||
{ | ||
eid: ethRuntime.network.config.endpointId, | ||
deployment: { | ||
...deploymentSubmission, | ||
numDeployments: 1, | ||
}, | ||
}, | ||
]) | ||
}) | ||
|
||
it('should include all deployments that have endpointId configured', async () => { | ||
// First we make sure that the networks we want to deploy to have endpointId | ||
const ethMainnetRuntime = await getNetworkRuntimeEnvironment('ethereum-mainnet') | ||
const ethTestnetRuntime = await getNetworkRuntimeEnvironment('ethereum-testnet') | ||
expect(ethMainnetRuntime.network.config.endpointId).not.to.be.undefined | ||
expect(ethTestnetRuntime.network.config.endpointId).not.to.be.undefined | ||
|
||
// Now we create mock deployments | ||
const now = Date.now() | ||
const deploymentSubmissionMainnet = { | ||
args: ['mainnet', now], | ||
} as DeploymentSubmission | ||
|
||
const deploymentSubmissionTestnet = { | ||
args: ['testnet', now], | ||
} as DeploymentSubmission | ||
|
||
// Save it | ||
await ethMainnetRuntime.deployments.save('MyWeirdContract', deploymentSubmissionMainnet) | ||
await ethTestnetRuntime.deployments.save('MyWeirdContract', deploymentSubmissionTestnet) | ||
|
||
// And check that it will not be picked up | ||
const deployments = await collectDeployments(hre, 'MyWeirdContract') | ||
|
||
// Now check that bsc-testnet and ethereum-testnet did not get included | ||
expect(deployments).to.eql([ | ||
{ | ||
eid: ethMainnetRuntime.network.config.endpointId, | ||
deployment: { | ||
...deploymentSubmissionMainnet, | ||
numDeployments: 1, | ||
}, | ||
}, | ||
{ | ||
eid: ethTestnetRuntime.network.config.endpointId, | ||
deployment: { | ||
...deploymentSubmissionTestnet, | ||
numDeployments: 1, | ||
}, | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |