-
Notifications
You must be signed in to change notification settings - Fork 1
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
MichaelKorchagin
wants to merge
11
commits into
master
Choose a base branch
from
test-suits
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test suite #8
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa0a9c6
Test preparation. Moved mocks to separate helper files. Preparation f…
MichaelKorchagin 6ab8106
Mission factory upgrade. Overridden some mongo methods. Changed HH co…
MichaelKorchagin 5c149eb
Tests for base deploy mission. Mongo mock minor fixes
MichaelKorchagin a499dcf
DB-Versioner general tests. Base-deploy-mission test organizing. DB m…
MichaelKorchagin d099a98
.only removal
MichaelKorchagin 37aaf73
DB Versioner tests.
MichaelKorchagin 891c473
Review fixes. Added and changed tests for versioner and BDM.
MichaelKorchagin 6d4e76b
HH Deployer tests. HH mock fixes. getAddress method removal. Added te…
MichaelKorchagin 06a763c
Added tests for get adapter module. Timeout removing. DB versioner te…
MichaelKorchagin 8e31bc4
Tests for configureVersioning. BDM test minor fixes.
MichaelKorchagin 4ba902e
Changed design of dbVersioner tests.
MichaelKorchagin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
node_modules | ||
*.env | ||
dist | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
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 | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this here?
There was a problem hiding this comment.
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?