Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a deployments task to show all deployments #647

Merged
merged 8 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/core/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
/temp
/test-integrations/fixture-projects/*/artifacts
/test-integrations/fixture-projects/*/cache
/test/mocks/verify/*/artifacts
/test/mocks/verify/*/build-info
/test/mocks/*
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { deploy } from "./deploy";
export * from "./errors";
export { IgnitionModuleSerializer } from "./ignition-module-serializer";
export { formatSolidityParameter } from "./internal/formatters";
export { listDeployments } from "./list-deployments";
export { status } from "./status";
export * from "./type-guards";
export * from "./types/artifact";
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/internal/views/find-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import { assertIgnitionInvariant } from "../utils/assertions";
export function findStatus(
deploymentState: DeploymentState
): Omit<ExecutionErrorDeploymentResult, "type"> {
const executionStates = Object.values(deploymentState.executionStates);

return {
started: Object.values(deploymentState.executionStates)
started: executionStates
.filter((ex) => ex.status === ExecutionStatus.STARTED)
.map((ex) => ex.id),
successful: Object.values(deploymentState.executionStates)
successful: executionStates
.filter((ex) => ex.status === ExecutionStatus.SUCCESS)
.map((ex) => ex.id),
held: Object.values(deploymentState.executionStates)
held: executionStates
.filter(canFail)
.filter((ex) => ex.status === ExecutionStatus.HELD)
.map((ex) => {
Expand All @@ -43,14 +45,14 @@ export function findStatus(
reason: ex.result.reason,
};
}),
timedOut: Object.values(deploymentState.executionStates)
timedOut: executionStates
.filter(canTimeout)
.filter((ex) => ex.status === ExecutionStatus.TIMEOUT)
.map((ex) => ({
futureId: ex.id,
networkInteractionId: ex.networkInteractions.at(-1)!.id,
})),
failed: Object.values(deploymentState.executionStates)
failed: executionStates
.filter(canFail)
.filter((ex) => ex.status === ExecutionStatus.FAILED)
.map((ex) => {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/list-deployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { readdir, pathExists } from "fs-extra";

/**
* Return a list of all deployments in the deployment directory.
*
* @param deploymentDir - the directory of the deployments
*
* @beta
*/
export async function listDeployments(
deploymentDir: string
): Promise<string[]> {
if (!(await pathExists(deploymentDir))) {
return [];
}

return readdir(deploymentDir);
}
27 changes: 25 additions & 2 deletions packages/core/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import { ERRORS } from "./internal/errors-list";
import { loadDeploymentState } from "./internal/execution/deployment-state-helpers";
import { findDeployedContracts } from "./internal/views/find-deployed-contracts";
import { findStatus } from "./internal/views/find-status";
import { ArtifactResolver } from "./types/artifact";
import { StatusResult } from "./types/status";

/**
* Show the status of a deployment.
*
* @param deploymentDir - the directory of the deployment to get the status of
* @param artifactResolver - the artifact resolver to use when loading artifacts
* for a future
*
* @beta
*/
export async function status(deploymentDir: string): Promise<StatusResult> {
export async function status(
deploymentDir: string,
artifactResolver: Omit<ArtifactResolver, "getBuildInfo">
): Promise<StatusResult> {
const deploymentLoader = new FileDeploymentLoader(deploymentDir);

const deploymentState = await loadDeploymentState(deploymentLoader);
Expand All @@ -25,7 +31,24 @@ export async function status(deploymentDir: string): Promise<StatusResult> {
}

const futureStatuses = findStatus(deploymentState);
const contracts = findDeployedContracts(deploymentState);
const deployedContracts = findDeployedContracts(deploymentState);

const contracts: StatusResult["contracts"] = {};

for (const [futureId, deployedContract] of Object.entries(
deployedContracts
)) {
const artifact = await artifactResolver.loadArtifact(
deployedContract.contractName
);

contracts[futureId] = {
...deployedContract,
contractName: artifact.contractName,
sourceName: artifact.sourceName,
abi: artifact.abi,
};
}

const statusResult: StatusResult = {
...futureStatuses,
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/types/status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { Abi } from "./artifact";
import { DeployedContract, ExecutionErrorDeploymentResult } from "./deploy";

/**
* The information of a deployed contract.
*
* @beta
*/
export interface GenericContractInfo extends DeployedContract {
sourceName: string;
abi: Abi;
}

/**
* The result of requesting the status of a deployment. It lists the futures
* broken down by their status, and includes the deployed contracts.
Expand All @@ -9,6 +20,6 @@ import { DeployedContract, ExecutionErrorDeploymentResult } from "./deploy";
export interface StatusResult
extends Omit<ExecutionErrorDeploymentResult, "type"> {
contracts: {
[key: string]: DeployedContract;
[key: string]: GenericContractInfo;
};
}
38 changes: 38 additions & 0 deletions packages/core/test/listDeployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { assert } from "chai";
import path from "path";

import { listDeployments } from "../src";

describe("listDeployments", () => {
it("should return an empty array if given a directory that doesn't exist", async () => {
const result = await listDeployments("nonexistant");

assert.deepEqual(result, []);
});

it("should return an empty array if given a directory containing no deployments", async () => {
const deploymentDir = path.join(
__dirname,
"mocks",
"listDeployments",
"no-deployments"
);

const result = await listDeployments(deploymentDir);

assert.deepEqual(result, []);
});

it("should return an array of deployment IDs if given a directory containing deployments", async () => {
const deploymentDir = path.join(
__dirname,
"mocks",
"listDeployments",
"has-deployments"
);

const result = await listDeployments(deploymentDir);

assert.deepEqual(result, ["chain-1", "chain-2"]);
});
});
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../build-info/a119b7bb4b3dd21e4ae94d5054092087.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Lock",
"sourceName": "contracts/Lock.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "_unlockTime",
"type": "uint256"
}
],
"stateMutability": "payable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "when",
"type": "uint256"
}
],
"name": "Withdrawal",
"type": "event"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "unlockTime",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x60806040526040516105d83803806105d8833981810160405281019061002591906100f0565b804210610067576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161005e906101a0565b60405180910390fd5b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506101c0565b600080fd5b6000819050919050565b6100cd816100ba565b81146100d857600080fd5b50565b6000815190506100ea816100c4565b92915050565b600060208284031215610106576101056100b5565b5b6000610114848285016100db565b91505092915050565b600082825260208201905092915050565b7f556e6c6f636b2074696d652073686f756c6420626520696e207468652066757460008201527f7572650000000000000000000000000000000000000000000000000000000000602082015250565b600061018a60238361011d565b91506101958261012e565b604082019050919050565b600060208201905081810360008301526101b98161017d565b9050919050565b610409806101cf6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063251c1aa3146100465780633ccfd60b146100645780638da5cb5b1461006e575b600080fd5b61004e61008c565b60405161005b919061024a565b60405180910390f35b61006c610092565b005b61007661020b565b60405161008391906102a6565b60405180910390f35b60005481565b6000544210156100d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100ce9061031e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015e9061038a565b60405180910390fd5b7fbf2ed60bd5b5965d685680c01195c9514e4382e28e3a5a2d2d5244bf59411b9347426040516101989291906103aa565b60405180910390a1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610208573d6000803e3d6000fd5b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61024481610231565b82525050565b600060208201905061025f600083018461023b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061029082610265565b9050919050565b6102a081610285565b82525050565b60006020820190506102bb6000830184610297565b92915050565b600082825260208201905092915050565b7f596f752063616e27742077697468647261772079657400000000000000000000600082015250565b60006103086016836102c1565b9150610313826102d2565b602082019050919050565b60006020820190508181036000830152610337816102fb565b9050919050565b7f596f75206172656e277420746865206f776e6572000000000000000000000000600082015250565b60006103746014836102c1565b915061037f8261033e565b602082019050919050565b600060208201905081810360008301526103a381610367565b9050919050565b60006040820190506103bf600083018561023b565b6103cc602083018461023b565b939250505056fea2646970667358221220f92f73d2a3284a3c1cca55a0fe6ec1a91b13bec884aecdbcf644cebf2774f32f64736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063251c1aa3146100465780633ccfd60b146100645780638da5cb5b1461006e575b600080fd5b61004e61008c565b60405161005b919061024a565b60405180910390f35b61006c610092565b005b61007661020b565b60405161008391906102a6565b60405180910390f35b60005481565b6000544210156100d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100ce9061031e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015e9061038a565b60405180910390fd5b7fbf2ed60bd5b5965d685680c01195c9514e4382e28e3a5a2d2d5244bf59411b9347426040516101989291906103aa565b60405180910390a1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610208573d6000803e3d6000fd5b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61024481610231565b82525050565b600060208201905061025f600083018461023b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061029082610265565b9050919050565b6102a081610285565b82525050565b60006020820190506102bb6000830184610297565b92915050565b600082825260208201905092915050565b7f596f752063616e27742077697468647261772079657400000000000000000000600082015250565b60006103086016836102c1565b9150610313826102d2565b602082019050919050565b60006020820190508181036000830152610337816102fb565b9050919050565b7f596f75206172656e277420746865206f776e6572000000000000000000000000600082015250565b60006103746014836102c1565b915061037f8261033e565b602082019050919050565b600060208201905081810360008301526103a381610367565b9050919050565b60006040820190506103bf600083018561023b565b6103cc602083018461023b565b939250505056fea2646970667358221220f92f73d2a3284a3c1cca55a0fe6ec1a91b13bec884aecdbcf644cebf2774f32f64736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Loading
Loading