Skip to content

Commit

Permalink
fix: display all deployed contracts
Browse files Browse the repository at this point in the history
The result was constrained to only those contracts returned by the
module. It now returns all contracts and contractAts that have been
deployed in this run and previous runs.

The `ignition-helper` now takes the responsibility of resolving the
modules results to contracts (and only the result contracts).

Note the types have not been altered.

Resolves #480.
  • Loading branch information
kanej committed Sep 20, 2023
1 parent a02a881 commit 31edccd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 52 deletions.
1 change: 1 addition & 0 deletions examples/ens/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ typechain
#Hardhat files
cache
artifacts
ignition/deployments
43 changes: 5 additions & 38 deletions packages/core/src/internal/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Reconciler } from "./reconciliation/reconciler";
import { assertIgnitionInvariant } from "./utils/assertions";
import { getFuturesFromModule } from "./utils/get-futures-from-module";
import { validateStageTwo } from "./validation/validateStageTwo";
import { findDeployedContracts } from "./views/find-deployed-contracts";

/**
* Run an Igntition deployment.
Expand Down Expand Up @@ -220,26 +221,17 @@ export class Deployer {
IgnitionModuleResultsT extends IgnitionModuleResult<ContractNameT>
>(
deploymentState: DeploymentState,
module: IgnitionModule<ModuleIdT, ContractNameT, IgnitionModuleResultsT>
_module: IgnitionModule<ModuleIdT, ContractNameT, IgnitionModuleResultsT>
): Promise<DeploymentResult<ContractNameT, IgnitionModuleResultsT>> {
if (!this._isSuccessful(deploymentState)) {
return this._getExecutionErrorResult(deploymentState);
}

const deployedContracts = findDeployedContracts(deploymentState);

return {
type: DeploymentResultType.SUCCESSFUL_DEPLOYMENT,
contracts: Object.fromEntries(
Object.entries(module.results).map(([name, contractFuture]) => [
name,
{
id: contractFuture.id,
contractName: contractFuture.contractName,
address: getContractAddress(
deploymentState.executionStates[contractFuture.id]
),
},
])
) as SuccessfulDeploymentResult<
contracts: deployedContracts as SuccessfulDeploymentResult<
ContractNameT,
IgnitionModuleResultsT
>["contracts"],
Expand Down Expand Up @@ -406,28 +398,3 @@ function canFail(
exState.type === ExecutionSateType.STATIC_CALL_EXECUTION_STATE
);
}

// TODO: Does this exist somewhere else?
function getContractAddress(exState: ExecutionState): string {
assertIgnitionInvariant(
exState.type === ExecutionSateType.DEPLOYMENT_EXECUTION_STATE ||
exState.type === ExecutionSateType.CONTRACT_AT_EXECUTION_STATE,
`Execution state ${exState.id} should be a deployment or contract at execution state`
);

assertIgnitionInvariant(
exState.status === ExecutionStatus.SUCCESS,
`Cannot get contract address from execution state ${exState.id} because it is not successful`
);

if (exState.type === ExecutionSateType.CONTRACT_AT_EXECUTION_STATE) {
return exState.contractAddress;
}

assertIgnitionInvariant(
exState.result?.type === ExecutionResultType.SUCCESS,
`Cannot get contract address from execution state ${exState.id} because it is not successful`
);

return exState.result.address;
}
24 changes: 14 additions & 10 deletions packages/core/src/internal/views/find-deployed-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
import { assertIgnitionInvariant } from "../utils/assertions";

interface DeployedContract {
futureId: string;
id: string;
contractName: string;
contractAddress: string;
address: string;
}

export function findDeployedContracts(
deploymentState: DeploymentState
): DeployedContract[] {
export function findDeployedContracts(deploymentState: DeploymentState): {
[futureId: string]: DeployedContract;
} {
return Object.values(deploymentState.executionStates)
.filter(
(
Expand All @@ -26,7 +26,11 @@ export function findDeployedContracts(
exState.type === ExecutionSateType.CONTRACT_AT_EXECUTION_STATE
)
.filter((des) => des.status === ExecutionStatus.SUCCESS)
.map(_toDeployedContract);
.map(_toDeployedContract)
.reduce<{ [futureId: string]: DeployedContract }>((acc, contract) => {
acc[contract.id] = contract;
return acc;
}, {});
}

function _toDeployedContract(
Expand All @@ -41,16 +45,16 @@ function _toDeployedContract(
);

return {
futureId: des.id,
id: des.id,
contractName: des.contractName,
contractAddress: des.result.address,
address: des.result.address,
};
}
case ExecutionSateType.CONTRACT_AT_EXECUTION_STATE: {
return {
futureId: des.id,
id: des.id,
contractName: des.contractName,
contractAddress: des.contractAddress,
address: des.contractAddress,
};
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/hardhat-plugin/src/ignition-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ export class IgnitionHelper {
> {
return Object.fromEntries(
await Promise.all(
Object.entries(result.contracts).map(
async ([name, deployedContract]) => [
Object.entries(ignitionModule.results).map(
async ([name, contractFuture]) => [
name,
await this._getContract(
ignitionModule.results[name],
deployedContract
contractFuture,
result.contracts[contractFuture.id]
),
]
)
Expand Down

0 comments on commit 31edccd

Please sign in to comment.