From 736b1f32ed07d92a591de00e2cf526dcd6656504 Mon Sep 17 00:00:00 2001 From: 3commascapital <90629478+3commascapital@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:29:13 -0500 Subject: [PATCH] Adds deployment stamp modification --- .../ephemeral-deployment-loader.ts | 15 ++++- .../file-deployment-loader.ts | 61 ++++++++++++++----- .../src/internal/deployment-loader/types.ts | 5 +- .../future-processor/future-processor.ts | 21 ++++++- .../src/internal/execution/jsonrpc-client.ts | 5 +- .../execution/types/execution-result.ts | 2 + .../src/internal/execution/types/jsonrpc.ts | 1 + .../journal/types/deployment-stamp.ts | 8 +++ .../journal/utils/emitExecutionEvent.ts | 4 +- .../find-address-for-contract-future-by-id.ts | 8 ++- .../internal/views/find-deployed-contracts.ts | 16 ++++- packages/core/src/types/deploy.ts | 2 + .../helpers/build-initialize-message-for.ts | 3 + .../helpers/network-interaction-execution.ts | 3 +- .../named-contract-at-deploy.ts | 7 +-- .../future-processor/named-contract-deploy.ts | 35 +++++++---- .../test/execution/future-processor/utils.ts | 13 +++- .../test/execution/reducers/running-a-call.ts | 3 + .../running-a-named-contract-deploy.ts | 13 ++++ .../running-a-named-library-deploy.ts | 13 ++++ .../execution/reducers/running-send-data.ts | 4 ++ packages/core/test/helpers.ts | 16 ++++- packages/core/test/reconciliation/helpers.ts | 4 +- packages/core/test/status.ts | 9 ++- .../calculate-deployment-complete-display.ts | 5 ++ .../calculate-deployment-status-display.ts | 15 +++-- 26 files changed, 234 insertions(+), 57 deletions(-) create mode 100644 packages/core/src/internal/journal/types/deployment-stamp.ts diff --git a/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts b/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts index 3a481d413..b854fd45f 100644 --- a/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts +++ b/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts @@ -1,3 +1,5 @@ +import type { DeploymentStamp } from "../journal/types/deployment-stamp"; + import { Artifact, ArtifactResolver, BuildInfo } from "../../types/artifact"; import { ExecutionEventListener } from "../../types/execution-events"; import { JournalMessage } from "../execution/types/messages"; @@ -16,6 +18,10 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { private _journal: Journal; private _deployedAddresses: { [key: string]: string }; + + private _deploymentStamps: { + [key: string]: DeploymentStamp; + }; private _savedArtifacts: { [key: string]: | { _kind: "artifact"; artifact: Artifact } @@ -28,6 +34,7 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { ) { this._journal = new MemoryJournal(this._executionEventListener); this._deployedAddresses = {}; + this._deploymentStamps = {}; this._savedArtifacts = {}; } @@ -41,9 +48,13 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { public async recordDeployedAddress( futureId: string, - contractAddress: string + address: string, + deploymentStamp?: DeploymentStamp ): Promise { - this._deployedAddresses[futureId] = contractAddress; + this._deployedAddresses[futureId] = address; + if (deploymentStamp !== undefined) { + this._deploymentStamps[futureId] = { ...deploymentStamp }; + } } public async storeBuildInfo( diff --git a/packages/core/src/internal/deployment-loader/file-deployment-loader.ts b/packages/core/src/internal/deployment-loader/file-deployment-loader.ts index e1c8dbc65..9fbf93bda 100644 --- a/packages/core/src/internal/deployment-loader/file-deployment-loader.ts +++ b/packages/core/src/internal/deployment-loader/file-deployment-loader.ts @@ -1,3 +1,5 @@ +import type { DeploymentStamp } from "../journal/types/deployment-stamp"; + import { ensureDir, pathExists, readFile, writeFile } from "fs-extra"; import path from "path"; @@ -9,6 +11,27 @@ import { Journal } from "../journal/types"; import { DeploymentLoader } from "./types"; +const updateJsonFile = async ( + pathToFile: string, + updater: (j: Record) => Record +) => { + let fileContents: { [key: string]: T }; + if (await pathExists(pathToFile)) { + const json = (await readFile(pathToFile)).toString(); + + fileContents = JSON.parse(json); + } else { + fileContents = {}; + } + + fileContents = updater(fileContents); + + await writeFile( + pathToFile, + `${JSON.stringify(fileContents, undefined, 2)}\n` + ); +}; + export class FileDeploymentLoader implements DeploymentLoader { private _journal: Journal; private _deploymentDirsEnsured: boolean; @@ -19,6 +42,7 @@ export class FileDeploymentLoader implements DeploymentLoader { buildInfoDir: string; journalPath: string; deployedAddressesPath: string; + deployedDeploymentStampPath: string; }; constructor( @@ -32,6 +56,10 @@ export class FileDeploymentLoader implements DeploymentLoader { this._deploymentDirPath, "deployed_addresses.json" ); + const deployedDeploymentStampPath = path.join( + this._deploymentDirPath, + "deployment_stamps.json" + ); this._journal = new FileJournal(journalPath, this._executionEventListener); @@ -41,6 +69,7 @@ export class FileDeploymentLoader implements DeploymentLoader { buildInfoDir, journalPath, deployedAddressesPath, + deployedDeploymentStampPath, }; this._deploymentDirsEnsured = false; @@ -151,27 +180,27 @@ export class FileDeploymentLoader implements DeploymentLoader { public async recordDeployedAddress( futureId: string, - contractAddress: string + address: string, + deploymentStamp?: DeploymentStamp ): Promise { await this._initialize(); - let deployedAddresses: { [key: string]: string }; - if (await pathExists(this._paths.deployedAddressesPath)) { - const json = ( - await readFile(this._paths.deployedAddressesPath) - ).toString(); - - deployedAddresses = JSON.parse(json); - } else { - deployedAddresses = {}; - } - - deployedAddresses[futureId] = contractAddress; - - await writeFile( + await updateJsonFile( this._paths.deployedAddressesPath, - `${JSON.stringify(deployedAddresses, undefined, 2)}\n` + (contents) => ({ + ...contents, + [futureId]: address, + }) ); + if (deploymentStamp !== undefined) { + await updateJsonFile( + this._paths.deployedDeploymentStampPath, + (contents) => ({ + ...contents, + [futureId]: { ...deploymentStamp }, + }) + ); + } } private async _initialize(): Promise { diff --git a/packages/core/src/internal/deployment-loader/types.ts b/packages/core/src/internal/deployment-loader/types.ts index 74151367b..57639227d 100644 --- a/packages/core/src/internal/deployment-loader/types.ts +++ b/packages/core/src/internal/deployment-loader/types.ts @@ -1,3 +1,5 @@ +import type { DeploymentStamp } from "../journal/types/deployment-stamp"; + import { Artifact, BuildInfo } from "../../types/artifact"; import { JournalMessage } from "../execution/types/messages"; @@ -22,6 +24,7 @@ export interface DeploymentLoader { storeBuildInfo(futureId: string, buildInfo: BuildInfo): Promise; recordDeployedAddress( futureId: string, - contractAddress: string + contractAddress: string, + deploymentStamp?: DeploymentStamp ): Promise; } diff --git a/packages/core/src/internal/execution/future-processor/future-processor.ts b/packages/core/src/internal/execution/future-processor/future-processor.ts index 32c2ed421..25a8f202c 100644 --- a/packages/core/src/internal/execution/future-processor/future-processor.ts +++ b/packages/core/src/internal/execution/future-processor/future-processor.ts @@ -18,6 +18,7 @@ import { StaticCallExecutionState, } from "../types/execution-state"; import { ExecutionStrategy } from "../types/execution-strategy"; +import { TransactionReceiptStatus } from "../types/jsonrpc"; import { JournalMessage, JournalMessageType } from "../types/messages"; import { monitorOnchainInteraction } from "./handlers/monitor-onchain-interaction"; @@ -144,13 +145,31 @@ export class FutureProcessor { lastAppliedMessage: JournalMessage ) { if ( + lastAppliedMessage.type === JournalMessageType.TRANSACTION_CONFIRM && + lastAppliedMessage.receipt.status === TransactionReceiptStatus.SUCCESS + ) { + const { receipt, futureId } = lastAppliedMessage; + const { contractAddress, blockNumber, transactionHash } = receipt; + if (contractAddress !== null && contractAddress !== undefined) { + await this._deploymentLoader.recordDeployedAddress( + futureId, + contractAddress, + { + address: contractAddress, + blockNumber: Number(blockNumber), + transactionHash, + } + ); + } + } else if ( lastAppliedMessage.type === JournalMessageType.DEPLOYMENT_EXECUTION_STATE_COMPLETE && lastAppliedMessage.result.type === ExecutionResultType.SUCCESS ) { await this._deploymentLoader.recordDeployedAddress( lastAppliedMessage.futureId, - lastAppliedMessage.result.address + lastAppliedMessage.result.address, + lastAppliedMessage.result.deploymentStamp ); } else if ( lastAppliedMessage.type === diff --git a/packages/core/src/internal/execution/jsonrpc-client.ts b/packages/core/src/internal/execution/jsonrpc-client.ts index c71449f35..9f92c518a 100644 --- a/packages/core/src/internal/execution/jsonrpc-client.ts +++ b/packages/core/src/internal/execution/jsonrpc-client.ts @@ -566,10 +566,10 @@ export class EIP1193JsonRpcClient implements JsonRpcClient { ): Promise { const method = "eth_getTransactionReceipt"; - const response = await this._provider.request({ + const response = (await this._provider.request({ method, params: [txHash], - }); + })) as TransactionReceipt | null; if (response === null) { return undefined; @@ -622,6 +622,7 @@ export class EIP1193JsonRpcClient implements JsonRpcClient { : toChecksumFormat(contractAddress), status, logs: formatReceiptLogs(method, response), + transactionHash: response.transactionHash, }; } diff --git a/packages/core/src/internal/execution/types/execution-result.ts b/packages/core/src/internal/execution/types/execution-result.ts index f43f41752..550824a05 100644 --- a/packages/core/src/internal/execution/types/execution-result.ts +++ b/packages/core/src/internal/execution/types/execution-result.ts @@ -1,4 +1,5 @@ import { SolidityParameterType } from "../../../types/module"; +import { DeploymentStamp } from "../../journal/types/deployment-stamp"; import { FailedEvmExecutionResult } from "./evm-execution"; @@ -76,6 +77,7 @@ export interface StrategyHeldExecutionResult { export interface SuccessfulDeploymentExecutionResult { type: ExecutionResultType.SUCCESS; address: string; + deploymentStamp?: DeploymentStamp; } /** diff --git a/packages/core/src/internal/execution/types/jsonrpc.ts b/packages/core/src/internal/execution/types/jsonrpc.ts index f157a6523..d1877e7d1 100644 --- a/packages/core/src/internal/execution/types/jsonrpc.ts +++ b/packages/core/src/internal/execution/types/jsonrpc.ts @@ -46,6 +46,7 @@ export interface TransactionReceipt { contractAddress?: string; status: TransactionReceiptStatus; logs: TransactionLog[]; + transactionHash: string; } /** diff --git a/packages/core/src/internal/journal/types/deployment-stamp.ts b/packages/core/src/internal/journal/types/deployment-stamp.ts new file mode 100644 index 000000000..136da1867 --- /dev/null +++ b/packages/core/src/internal/journal/types/deployment-stamp.ts @@ -0,0 +1,8 @@ +export interface DeploymentStamp { + address: string; + blockNumber: number; + transactionHash: string; +} + +export const zeroHash = + "0x0000000000000000000000000000000000000000000000000000000000000000"; diff --git a/packages/core/src/internal/journal/utils/emitExecutionEvent.ts b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts index dd5dbfbc7..ae06575a7 100644 --- a/packages/core/src/internal/journal/utils/emitExecutionEvent.ts +++ b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts @@ -12,6 +12,7 @@ import { ExecutionResultType, SendDataExecutionResult, StaticCallExecutionResult, + SuccessfulDeploymentExecutionResult, } from "../../execution/types/execution-result"; import { JournalMessage, @@ -203,9 +204,10 @@ function convertExecutionResultToEventResult( ): ExecutionEventResult { switch (result.type) { case ExecutionResultType.SUCCESS: { + const res = result as SuccessfulDeploymentExecutionResult; return { type: ExecutionEventResultType.SUCCESS, - result: "address" in result ? result.address : undefined, + result: res.address, }; } case ExecutionResultType.STATIC_CALL_ERROR: diff --git a/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts b/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts index 2bd4b3e23..1459af435 100644 --- a/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts +++ b/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts @@ -1,5 +1,8 @@ import { DeploymentState } from "../execution/types/deployment-state"; -import { ExecutionResultType } from "../execution/types/execution-result"; +import { + ExecutionResultType, + SuccessfulDeploymentExecutionResult, +} from "../execution/types/execution-result"; import { ExecutionSateType } from "../execution/types/execution-state"; import { assertIgnitionInvariant } from "../utils/assertions"; @@ -45,5 +48,6 @@ export function findAddressForContractFuture( `Cannot access the result of ${futureId}, it was not a deployment success` ); - return exState.result.address; + const result = exState.result as SuccessfulDeploymentExecutionResult; + return result.address; } diff --git a/packages/core/src/internal/views/find-deployed-contracts.ts b/packages/core/src/internal/views/find-deployed-contracts.ts index 5c6d9c383..6f4154c8a 100644 --- a/packages/core/src/internal/views/find-deployed-contracts.ts +++ b/packages/core/src/internal/views/find-deployed-contracts.ts @@ -1,12 +1,16 @@ import { DeployedContract } from "../../types/deploy"; import { DeploymentState } from "../execution/types/deployment-state"; -import { ExecutionResultType } from "../execution/types/execution-result"; +import { + ExecutionResultType, + SuccessfulDeploymentExecutionResult, +} from "../execution/types/execution-result"; import { ContractAtExecutionState, DeploymentExecutionState, ExecutionSateType, ExecutionStatus, } from "../execution/types/execution-state"; +import { zeroHash } from "../journal/types/deployment-stamp"; import { assertIgnitionInvariant } from "../utils/assertions"; export function findDeployedContracts(deploymentState: DeploymentState): { @@ -39,10 +43,16 @@ function _toDeployedContract( `Deployment execution state ${des.id} should have a successful result to retrieve address` ); + const res = des.result as SuccessfulDeploymentExecutionResult; return { id: des.id, contractName: des.contractName, - address: des.result.address, + address: res.address, + transactionHash: zeroHash, + blockNumber: 0, + ...(res.deploymentStamp !== null && res.deploymentStamp !== undefined + ? res.deploymentStamp + : {}), }; } case ExecutionSateType.CONTRACT_AT_EXECUTION_STATE: { @@ -50,6 +60,8 @@ function _toDeployedContract( id: des.id, contractName: des.contractName, address: des.contractAddress, + transactionHash: zeroHash, + blockNumber: 0, }; } } diff --git a/packages/core/src/types/deploy.ts b/packages/core/src/types/deploy.ts index a3c404b41..2360cefb6 100644 --- a/packages/core/src/types/deploy.ts +++ b/packages/core/src/types/deploy.ts @@ -176,6 +176,8 @@ export interface DeployedContract { id: string; contractName: string; address: string; + transactionHash: string; + blockNumber: number; } /** diff --git a/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts b/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts index 08a460460..b97ac6468 100644 --- a/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts +++ b/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts @@ -70,6 +70,8 @@ import { describe("buildInitializeMessageFor", () => { const differentAddress = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; const libraryAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"; + const successfulTxHash = + "0x0011223344556677889900112233445566778899001122334455667788990000"; const basicStrategy = { name: "basic", config: {} } as any; let namedContractDeployment: NamedArtifactContractDeploymentFuture; @@ -319,6 +321,7 @@ describe("buildInitializeMessageFor", () => { ], }, ], + transactionHash: successfulTxHash, }, }; diff --git a/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts b/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts index c943c062a..b5c87b2bf 100644 --- a/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts +++ b/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts @@ -762,7 +762,7 @@ class MockGetTransactionJsonRpcClient extends StubJsonRpcClient { } public async getTransactionReceipt( - _txHash: string + transactionHash: string ): Promise { return { blockHash: "0xblockhash", @@ -770,6 +770,7 @@ class MockGetTransactionJsonRpcClient extends StubJsonRpcClient { contractAddress: "0xcontractaddress", logs: [], status: TransactionReceiptStatus.SUCCESS, + transactionHash, }; } } diff --git a/packages/core/test/execution/future-processor/named-contract-at-deploy.ts b/packages/core/test/execution/future-processor/named-contract-at-deploy.ts index d64552676..d2e650e9b 100644 --- a/packages/core/test/execution/future-processor/named-contract-at-deploy.ts +++ b/packages/core/test/execution/future-processor/named-contract-at-deploy.ts @@ -24,10 +24,8 @@ describe("future processor", () => { exampleAddress ); - const { processor, storedDeployedAddresses } = await setupFutureProcessor( - (() => {}) as any, - {} - ); + const { processor, storedDeployedAddresses, storedDeploymentStamps } = + await setupFutureProcessor((() => {}) as any, {}); // Act await processor.processFuture(deploymentFuture, initialDeploymentState); @@ -37,6 +35,7 @@ describe("future processor", () => { storedDeployedAddresses["MyModule:TestContract"], exampleAddress ); + assert.deepEqual(storedDeploymentStamps, {}); }); }); }); diff --git a/packages/core/test/execution/future-processor/named-contract-deploy.ts b/packages/core/test/execution/future-processor/named-contract-deploy.ts index c0704f8e4..b33f11584 100644 --- a/packages/core/test/execution/future-processor/named-contract-deploy.ts +++ b/packages/core/test/execution/future-processor/named-contract-deploy.ts @@ -38,20 +38,22 @@ describe("future processor", () => { exampleAccounts[0] ); - const { processor, storedDeployedAddresses } = await setupFutureProcessor( - async (_transactionParams: TransactionParams) => { - return exampleTxHash; - }, - { - [exampleTxHash]: { - blockHash: `0xblockhash-5`, - blockNumber: 1, - contractAddress: exampleAddress, - status: TransactionReceiptStatus.SUCCESS, - logs: [], + const { processor, storedDeployedAddresses, storedDeploymentStamps } = + await setupFutureProcessor( + async (_transactionParams: TransactionParams) => { + return exampleTxHash; }, - } - ); + { + [exampleTxHash]: { + blockHash: `0xblockhash-5`, + blockNumber: 1, + contractAddress: exampleAddress, + status: TransactionReceiptStatus.SUCCESS, + logs: [], + transactionHash: exampleTxHash, + }, + } + ); // Act const result = await processor.processFuture( @@ -64,6 +66,13 @@ describe("future processor", () => { storedDeployedAddresses["MyModule:TestContract"], exampleAddress ); + assert.deepEqual(storedDeploymentStamps, { + ["MyModule:TestContract"]: { + address: exampleAddress, + blockNumber: 1, + transactionHash: exampleTxHash, + }, + }); const updatedExState = result.newState.executionStates["MyModule:TestContract"]; diff --git a/packages/core/test/execution/future-processor/utils.ts b/packages/core/test/execution/future-processor/utils.ts index c37ded417..7bab6948e 100644 --- a/packages/core/test/execution/future-processor/utils.ts +++ b/packages/core/test/execution/future-processor/utils.ts @@ -1,3 +1,5 @@ +import type { DeploymentStamp } from "../../../src/internal/journal/types/deployment-stamp"; + import { FutureProcessor } from "../../../src/internal/execution/future-processor/future-processor"; import { Block, @@ -30,12 +32,15 @@ export async function setupFutureProcessor( ): Promise<{ processor: FutureProcessor; storedDeployedAddresses: { [key: string]: string }; + storedDeploymentStamps: { [key: string]: DeploymentStamp }; }> { const storedDeployedAddresses: { [key: string]: string } = {}; + const storedDeploymentStamps: { [key: string]: DeploymentStamp } = {}; const mockDeploymentLoader = setupMockDeploymentLoader( new MemoryJournal(), - storedDeployedAddresses + storedDeployedAddresses, + storedDeploymentStamps ); const mockArtifactResolver = setupMockArtifactResolver(); @@ -67,7 +72,11 @@ export async function setupFutureProcessor( getDefaultSender(exampleAccounts) ); - return { processor, storedDeployedAddresses }; + return { + processor, + storedDeployedAddresses, + storedDeploymentStamps, + }; } function setupMockNonceManager(): NonceManager { diff --git a/packages/core/test/execution/reducers/running-a-call.ts b/packages/core/test/execution/reducers/running-a-call.ts index 347bb697b..d52285cfb 100644 --- a/packages/core/test/execution/reducers/running-a-call.ts +++ b/packages/core/test/execution/reducers/running-a-call.ts @@ -30,6 +30,8 @@ describe("DeploymentStateReducer", () => { const senderAddress = "0x0011223344556677889900112233445566778899"; const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; const differentAddress = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; + const successfulTxHash = + "0x0011223344556677889900112233445566778899001122334455667788990000"; const revertedTxHash = "0x0011223344556677889900112233445566778899001122334455667788990011"; @@ -116,6 +118,7 @@ describe("DeploymentStateReducer", () => { contractAddress: exampleAddress, status: TransactionReceiptStatus.SUCCESS, logs: [], + transactionHash: successfulTxHash, }, }; diff --git a/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts b/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts index b029e10eb..c6edf7d51 100644 --- a/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts +++ b/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts @@ -31,6 +31,8 @@ describe("DeploymentStateReducer", () => { const senderAddress = "0x0011223344556677889900112233445566778899"; const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; const differentAddress = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; + const successfulTxHash = + "0x0011223344556677889900112233445566778899001122334455667788990000"; const revertedTxHash = "0x0011223344556677889900112233445566778899001122334455667788990011"; @@ -118,6 +120,7 @@ describe("DeploymentStateReducer", () => { contractAddress: exampleAddress, status: TransactionReceiptStatus.SUCCESS, logs: [], + transactionHash: successfulTxHash, }, }; @@ -127,6 +130,11 @@ describe("DeploymentStateReducer", () => { result: { type: ExecutionResultType.SUCCESS, address: exampleAddress, + deploymentStamp: { + address: exampleAddress, + transactionHash: successfulTxHash, + blockNumber: 0, + }, }, }; @@ -331,6 +339,11 @@ describe("DeploymentStateReducer", () => { assert.deepStrictEqual(updatedDepExState.result, { type: ExecutionResultType.SUCCESS, address: exampleAddress, + deploymentStamp: { + address: exampleAddress, + blockNumber: 0, + transactionHash: successfulTxHash, + }, }); }); diff --git a/packages/core/test/execution/reducers/running-a-named-library-deploy.ts b/packages/core/test/execution/reducers/running-a-named-library-deploy.ts index fbc8b3055..0b32470ee 100644 --- a/packages/core/test/execution/reducers/running-a-named-library-deploy.ts +++ b/packages/core/test/execution/reducers/running-a-named-library-deploy.ts @@ -26,6 +26,8 @@ describe("DeploymentStateReducer", () => { describe("running a named library deploy", () => { const senderAddress = "0x0011223344556677889900112233445566778899"; const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; + const successfulTxHash = + "0x0011223344556677889900112233445566778899001122334455667788990000"; let updatedDeploymentState: DeploymentState; let updatedDepExState: DeploymentExecutionState; @@ -83,6 +85,7 @@ describe("DeploymentStateReducer", () => { contractAddress: exampleAddress, status: TransactionReceiptStatus.SUCCESS, logs: [], + transactionHash: successfulTxHash, }, }; @@ -92,6 +95,11 @@ describe("DeploymentStateReducer", () => { result: { type: ExecutionResultType.SUCCESS, address: exampleAddress, + deploymentStamp: { + address: exampleAddress, + blockNumber: 0, + transactionHash: successfulTxHash, + }, }, }; @@ -137,6 +145,11 @@ describe("DeploymentStateReducer", () => { assert.deepStrictEqual(updatedDepExState.result, { type: ExecutionResultType.SUCCESS, address: exampleAddress, + deploymentStamp: { + address: exampleAddress, + blockNumber: 0, + transactionHash: successfulTxHash, + }, }); }); diff --git a/packages/core/test/execution/reducers/running-send-data.ts b/packages/core/test/execution/reducers/running-send-data.ts index b1639572c..765734340 100644 --- a/packages/core/test/execution/reducers/running-send-data.ts +++ b/packages/core/test/execution/reducers/running-send-data.ts @@ -29,6 +29,8 @@ describe("DeploymentStateReducer", () => { describe("running a named library deploy", () => { const senderAddress = "0x0011223344556677889900112233445566778899"; const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; + const successfulTxHash = + "0x0011223344556677889900112233445566778899001122334455667788990000"; const revertedTxHash = "0x0011223344556677889900112233445566778899001122334455667788990011"; @@ -99,6 +101,7 @@ describe("DeploymentStateReducer", () => { contractAddress: exampleAddress, status: TransactionReceiptStatus.SUCCESS, logs: [], + transactionHash: successfulTxHash, }, }; @@ -113,6 +116,7 @@ describe("DeploymentStateReducer", () => { contractAddress: undefined, status: TransactionReceiptStatus.FAILURE, logs: [], + transactionHash: revertedTxHash, }, }; diff --git a/packages/core/test/helpers.ts b/packages/core/test/helpers.ts index bb4842b58..dad67cd79 100644 --- a/packages/core/test/helpers.ts +++ b/packages/core/test/helpers.ts @@ -1,3 +1,5 @@ +import type { DeploymentStamp } from "../src/internal/journal/types/deployment-stamp"; + import { assert } from "chai"; import { Artifact, ArtifactResolver } from "../src"; @@ -64,11 +66,14 @@ export function setupMockArtifactResolver(artifacts?: { export function setupMockDeploymentLoader( journal: Journal, - deployedAddresses?: { [key: string]: string } + deployedAddresses?: { [key: string]: string }, + deploymentStamps?: { [key: string]: DeploymentStamp } ): DeploymentLoader { const storedArtifacts: { [key: string]: Artifact } = {}; const storedDeployedAddresses: { [key: string]: string } = deployedAddresses ?? {}; + const storedDeploymentStamps: { [key: string]: DeploymentStamp } = + deploymentStamps ?? {}; return { recordToJournal: async (message) => { @@ -77,8 +82,15 @@ export function setupMockDeploymentLoader( readFromJournal: () => { return journal.read(); }, - recordDeployedAddress: async (futureId, contractAddress) => { + recordDeployedAddress: async ( + futureId, + contractAddress, + deploymentStamp + ) => { storedDeployedAddresses[futureId] = contractAddress; + if (deploymentStamp !== undefined) { + storedDeploymentStamps[futureId] = { ...deploymentStamp }; + } }, storeUserProvidedArtifact: async (artifactId, artifact) => { storedArtifacts[artifactId] = artifact; diff --git a/packages/core/test/reconciliation/helpers.ts b/packages/core/test/reconciliation/helpers.ts index 788468165..7da65817f 100644 --- a/packages/core/test/reconciliation/helpers.ts +++ b/packages/core/test/reconciliation/helpers.ts @@ -14,6 +14,7 @@ import { } from "../../src/internal/execution/types/execution-state"; import { JournalMessage } from "../../src/internal/execution/types/messages"; import { getDefaultSender } from "../../src/internal/execution/utils/get-default-sender"; +import { DeploymentStamp } from "../../src/internal/journal/types/deployment-stamp"; import { Reconciler } from "../../src/internal/reconciliation/reconciler"; import { ReconciliationResult } from "../../src/internal/reconciliation/types"; import { IgnitionModule } from "../../src/types/module"; @@ -69,7 +70,8 @@ class MockDeploymentLoader implements DeploymentLoader { public recordDeployedAddress( _futureId: string, - _contractAddress: string + _address: string, + _deploymentStamp: DeploymentStamp ): Promise { throw new Error("Method not implemented."); } diff --git a/packages/core/test/status.ts b/packages/core/test/status.ts index 0f98303f9..9a701b89d 100644 --- a/packages/core/test/status.ts +++ b/packages/core/test/status.ts @@ -2,6 +2,7 @@ import { assert } from "chai"; import path from "path"; import { Artifact, status } from "../src"; +import { zeroHash } from "../src/internal/journal/types/deployment-stamp"; import { setupMockArtifactResolver } from "./helpers"; @@ -16,11 +17,13 @@ describe("status", () => { chainId: 1, contracts: { "LockModule#Lock": { - id: "LockModule#Lock", - contractName: "ArtifactLock", + abi: ["test"], address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", + blockNumber: 0, + contractName: "ArtifactLock", + id: "LockModule#Lock", sourceName: "contracts/ArtifactLock.sol", - abi: ["test"], + transactionHash: zeroHash, }, }, }; diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts index 5e59cc92a..fd4842a5c 100644 --- a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts +++ b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-complete-display.ts @@ -9,6 +9,7 @@ import { } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import chalk from "chalk"; +import { zeroHash } from "viem"; import { calculateDeploymentCompleteDisplay } from "../../../src/ui/helpers/calculate-deployment-complete-display"; import { UiBatches, UiFutureStatusType } from "../../../src/ui/types"; @@ -52,11 +53,15 @@ describe("ui - calculate deployment complete display", () => { id: "MyModule#Token", address: exampleAddress, contractName: "Token", + transactionHash: zeroHash, + blockNumber: 0, }, "MyModule#AnotherToken": { id: "MyModule#AnotherToken", address: differentAddress, contractName: "AnotherToken", + transactionHash: zeroHash, + blockNumber: 0, }, }, }, diff --git a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts index b4f5e3dae..bd2cb1ede 100644 --- a/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts +++ b/packages/hardhat-plugin/test/ui/helpers/calculate-deployment-status-display.ts @@ -1,6 +1,7 @@ import { StatusResult } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import chalk from "chalk"; +import { zeroHash } from "viem"; import { calculateDeploymentStatusDisplay } from "../../../src/ui/helpers/calculate-deployment-status-display"; @@ -10,6 +11,12 @@ describe("ui - calculate deployment status display", () => { const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; const differentAddress = "0x0011223344556677889900112233445566778899"; + const baselineContract = { + abi: [], + transactionHash: zeroHash, + blockNumber: 0, + }; + const exampleStatusResult = { chainId: 1, started: [], @@ -39,14 +46,14 @@ describe("ui - calculate deployment status display", () => { address: exampleAddress, contractName: "Token", sourceName: "contracts/Token.sol", - abi: [], + ...baselineContract, }, "MyModule#AnotherToken": { id: "MyModule#AnotherToken", address: differentAddress, contractName: "AnotherToken", sourceName: "contracts/AnotherToken.sol", - abi: [], + ...baselineContract, }, }, }; @@ -137,14 +144,14 @@ describe("ui - calculate deployment status display", () => { address: exampleAddress, contractName: "Token", sourceName: "contracts/Token.sol", - abi: [], + ...baselineContract, }, "MyModule#AnotherToken": { id: "MyModule#AnotherToken", address: differentAddress, contractName: "AnotherToken", sourceName: "contracts/AnotherToken.sol", - abi: [], + ...baselineContract, }, }, };