Skip to content

Commit

Permalink
use deploymentLoader exclusively and deprecate artifactLoader for status
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Dec 15, 2024
1 parent c951b94 commit b70deb0
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 56 deletions.
21 changes: 4 additions & 17 deletions packages/core/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ 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 { Abi, Artifact, ArtifactResolver } from "./types/artifact";
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
* @param _artifactResolver - DEPRECATED: this parameter is not used and will be removed in the future
*
* @beta
*/
export async function status(
deploymentDir: string,
artifactResolver: Omit<ArtifactResolver, "getBuildInfo">
_artifactResolver?: Omit<ArtifactResolver, "getBuildInfo">
): Promise<StatusResult> {
const deploymentLoader = new FileDeploymentLoader(deploymentDir);

Expand All @@ -38,19 +37,7 @@ export async function status(
for (const [futureId, deployedContract] of Object.entries(
deployedContracts
)) {
let artifact: Artifact<Abi>;

try {
artifact = await artifactResolver.loadArtifact(
deployedContract.contractName
);
} catch (e) {
if (e instanceof Error && /HH700/g.test(e.message)) {
artifact = await deploymentLoader.loadArtifact(deployedContract.id);
} else {
throw e;
}
}
const artifact = await deploymentLoader.loadArtifact(deployedContract.id);

contracts[futureId] = {
...deployedContract,
Expand Down
232 changes: 193 additions & 39 deletions packages/core/test/status.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { assert } from "chai";
import path from "path";

import { Artifact, status } from "../src";

import { setupMockArtifactResolver } from "./helpers";
import { status } from "../src";

describe("status", () => {
it("should return a status result for a successful deployment", async () => {
Expand All @@ -17,27 +15,81 @@ describe("status", () => {
contracts: {
"LockModule#Lock": {
id: "LockModule#Lock",
contractName: "ArtifactLock",
contractName: "Lock",
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
sourceName: "contracts/ArtifactLock.sol",
abi: ["test"],
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",
},
],
},
},
};

const fakeArtifact: Artifact = {
abi: ["test"],
contractName: "ArtifactLock",
sourceName: "contracts/ArtifactLock.sol",
bytecode: "",
linkReferences: {},
};

const deploymentDir = path.join(__dirname, "mocks", "status", "success");

const artifactResolver = setupMockArtifactResolver({ Lock: fakeArtifact });

const result = await status(deploymentDir, artifactResolver);
const result = await status(deploymentDir);

assert.deepEqual(result, expectedResult);
});
Expand All @@ -55,53 +107,155 @@ describe("status", () => {
id: "LockModule#Basic",
contractName: "Basic",
address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
sourceName: "",
abi: [],
sourceName: "contracts/Basic.sol",
abi: [
{
inputs: [
{
internalType: "uint256",
name: "a",
type: "uint256",
},
{
internalType: "uint256",
name: "b",
type: "uint256",
},
],
name: "add",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "pure",
type: "function",
},
],
},
"LockModule#Basic2": {
id: "LockModule#Basic2",
contractName: "Basic2",
contractName: "Basic",
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
sourceName: "",
abi: [],
sourceName: "contracts/Basic.sol",
abi: [
{
inputs: [
{
internalType: "uint256",
name: "a",
type: "uint256",
},
{
internalType: "uint256",
name: "b",
type: "uint256",
},
],
name: "add",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "pure",
type: "function",
},
],
},
"LockModule#Lock": {
id: "LockModule#Lock",
contractName: "ArtifactLock",
contractName: "Lock",
address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
sourceName: "contracts/ArtifactLock.sol",
abi: ["test"],
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",
},
],
},
},
};

const fakeArtifact: Artifact = {
abi: ["test"],
contractName: "ArtifactLock",
sourceName: "contracts/ArtifactLock.sol",
bytecode: "",
linkReferences: {},
};

const deploymentDir = path.join(
__dirname,
"mocks",
"status",
"external-artifact"
);

const artifactResolver = setupMockArtifactResolver({ Lock: fakeArtifact });

const result = await status(deploymentDir, artifactResolver);
const result = await status(deploymentDir);

assert.deepEqual(result, expectedResult);
});

it("should throw an error if the deployment is not initialized", async () => {
const artifactResolver = setupMockArtifactResolver();

await assert.isRejected(
status("fake", artifactResolver),
status("fake"),
/IGN800: Cannot get status for nonexistant deployment at fake/
);
});
Expand Down

0 comments on commit b70deb0

Please sign in to comment.