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

Test suite #8

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
*.env
dist
/.vscode
214 changes: 214 additions & 0 deletions test/cases/BaseDeployMissionUnit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import assert from "node:assert";
import {
DBVersioner,
DeployCampaign,
HardhatDeployer,
IContractState,
IDeployCampaignConfig,
IHardhatBase,
ISignerBase,
MongoDBAdapter,
} from "../../src";
import { HardhatMock } from "../mocks/hardhat";
import { loggerMock } from "../mocks/logger";
import { testMissions } from "../mocks/missions";
import { MongoClientMock } from "../mocks/mongo";


// this.timeout() doesn't work for arrow functions.
describe("Base deploy mission", function () {
this.timeout(5000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this here?

Copy link
Collaborator Author

@MichaelKorchagin MichaelKorchagin Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From time to time, flow falls by timeout of 2000ms. When I increased this, it helps. I know, its not for our soft, It's only for my machine. But I just wanted to keep it while the PR has WIP status. Or should I remove it before each push?


let campaign : DeployCampaign<IHardhatBase, ISignerBase, IDeployCampaignConfig<ISignerBase>, IContractState>;
let hardhatMock : HardhatMock;
let missionIdentifiers : Array<string>;

// it has any type in the DeployCampaign class
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let config : any;

before(async () => {
hardhatMock = new HardhatMock();

config = {
env: "prod",
deployAdmin: {
address: "0xdeployAdminAddress",
getAddress: async () => Promise.resolve("0xdeployAdminAddress"),
MichaelKorchagin marked this conversation as resolved.
Show resolved Hide resolved
},
postDeploy: {
tenderlyProjectSlug: "tenderlyProject",
monitorContracts: true,
verifyContracts: true,
},
};

const signerMock = {
getAddress: async () => Promise.resolve("0xsignerAddress"),
address: "0xsignerAddress",
};

const deployer = new HardhatDeployer({
hre: hardhatMock,
signer: signerMock,
env: "prod",
});

const contractsVersion = "1.7.9";
const dbVersion = "109381236293746234";

const mongoAdapterMock = new MongoDBAdapter({
logger: loggerMock,
dbUri: "mongodb://mockedMongo",
dbName: "TestDatabase",
mongoClientClass: MongoClientMock,
versionerClass: DBVersioner,
dbVersion,
contractsVersion,
});

await mongoAdapterMock.initialize(dbVersion);

missionIdentifiers = [
"buildObject",
"needsDeploy",
"deployed",
"proxyPost",
];

const postDeployRun = [
false,
false,
false,
];

campaign = new DeployCampaign({
logger: loggerMock,
missions: await testMissions(
missionIdentifiers,
postDeployRun
),
deployer,
dbAdapter: mongoAdapterMock,
config,
});

await campaign.execute();
});

describe("#deploy()", () => {
it("Should deploy all contracts from `missionIdentifiers`", async () => {
for (const mission of missionIdentifiers) {
assert.equal(
await campaign.state.contracts[mission].getAddress(),
`0xcontractAddress_Contract_${mission}`
);
// does it make sense to do this?
assert.deepEqual(
await campaign.state.instances[mission].deployArgs(),
[`arg_${mission}1`, `arg_${mission}2`]
);
}
});

it("#savetoDB() Should call `saveToDB()` when deploy a contract", async () => {
for (const mission of missionIdentifiers) {
if (mission !== "deployed") {
assert.equal(
// ts complains about `called` prop
// @ts-ignore
await campaign.state.instances[mission].called.includes("saveToDB"),
true
);
}
}
});
});

describe("Minor methods", () => {
it("#deployArgs() Should return correct deploy arguments", async () => {
MichaelKorchagin marked this conversation as resolved.
Show resolved Hide resolved
for (const mission of missionIdentifiers) {
await campaign.state.instances[mission].deployArgs();
}
});

it("#updateStateContract() Should update state contract when deploys the contracts", async () => {
MichaelKorchagin marked this conversation as resolved.
Show resolved Hide resolved
const state = await campaign.state.contracts;

for (const mission of missionIdentifiers) {
const contract = state[mission];

assert.strictEqual(
typeof contract.deploymentTransaction,
"function",
"Not a contract. Method 'deploymentTransaction' should exist"
);

assert.strictEqual(
typeof contract.getAddress,
"function",
"Not a contract. Method 'getAddress' should exist"
);

assert.strictEqual(
typeof contract.interface,
"object",
"Not a contract. Property 'interface' should exist"
);

assert.strictEqual(
typeof contract.target,
"string",
"Not a contract. Property 'target' should exist and be an address"
);

assert.strictEqual(
typeof contract.waitForDeployment,
"function",
"Not a contract. Function 'waitForDeployment' should exist"
);
}
});

it("#buildObject() Should build correct object of contract and call insertOne()", async () => {
const {
buildObject,
} = campaign.state.instances;

const {
buildObject: contractBuildObject,
} = campaign.state.contracts;

const buildedDbObject = await buildObject.buildDbObject(contractBuildObject, buildObject.implAddress);

const resultBuildedDbObject = {
address: "0xcontractAddress_Contract_buildObject",
abi: "[]",
bytecode: "0xbytecode",
implementation: null,
name: "Contract_buildObject",
};

assert.deepEqual(
buildedDbObject,
resultBuildedDbObject
);
});
});

describe("#needsDeploy()",() => {
it("Should return FALSE, because it found itself in db", async () => {
MichaelKorchagin marked this conversation as resolved.
Show resolved Hide resolved
assert.equal(
await campaign.state.instances.deployed.needsDeploy(),
false
);
});

it("Should return TRUE, because it's missing in db", async () => {
assert.equal(
await campaign.state.instances.needsDeploy.needsDeploy(),
true
);
});
});
});
Loading