-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve test fixtures #64
Merged
Merged
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
32b0f4d
Handling ERC4626 vaults in AcreRouter
dimpar 3246552
Adding pnpm-lock.yaml
dimpar a3ba20f
Replacing OZ upgradable lib to a non-upgradable one
dimpar 072f854
Drafting tests for AcreRouter
dimpar cd91d07
Add helpers to get deployed contract
nkuba 4bf5442
Add helpers for hardhat signers
nkuba 16676e9
Improve test fixture used in Acre test
nkuba 07ff2a0
Merge remote-tracking branch 'origin/test-fixtures' into vaults-acre-…
dimpar 9a9c513
Adding AcreRouter to deployed context
dimpar 2ae92ec
Adding AcreRouter deployment scripts
dimpar fd4a287
Refactoring tests adjusting for helper methods
dimpar 1c85545
Adding func-visibility rule
dimpar 2bbf761
Referencing correct vault names in tests
dimpar cc54053
Merge remote-tracking branch 'origin/main' into test-fixtures
nkuba 3a05a45
Replace realpath with another resolution
nkuba aa133de
Removing a rule that already exist in parent config
dimpar 9e0ffd9
Renaming AcreRouter -> Dispatcher
dimpar b56c0ec
Changing a comment for vaults array
dimpar d7e8ac6
Renaming Vault -> VaultInfo struct
dimpar 01086fc
Approve->authorize for vaults and functions around it
dimpar f477e45
Replacing require err messages with custom errors
dimpar d0bd5dd
Renaming events and returning the entire vaults array
dimpar cf0d47d
Adding func.dependencies for Dispatcher ownership transfer
dimpar b131f82
Refactoring Dispatcher tests:
dimpar e94c5fc
Simplifying tests
dimpar 5cdfff9
Handling ERC4626 vaults in AcreRouter (#62)
nkuba e21a50b
Improve signers mapping
nkuba 2831ef6
Don't return awaited promise in getUnnamedSigner
nkuba 790c768
Merge remote-tracking branch 'origin/main' into test-fixtures
nkuba 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
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
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,15 @@ | ||
import { deployments } from "hardhat" | ||
|
||
import { getDeployedContract } from "./contract" | ||
|
||
import type { Acre, TestERC20 } from "../../typechain" | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export async function deployment() { | ||
await deployments.fixture() | ||
|
||
const tbtc: TestERC20 = await getDeployedContract("TBTC") | ||
const acre: Acre = await getDeployedContract("Acre") | ||
|
||
return { tbtc, acre } | ||
} |
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,22 @@ | ||
import { ethers } from "ethers" | ||
import { deployments } from "hardhat" | ||
|
||
import type { BaseContract } from "ethers" | ||
import { getUnnamedSigner } from "./signer" | ||
|
||
/** | ||
* Get instance of a contract from Hardhat Deployments. | ||
* @param deploymentName Name of the contract deployment. | ||
* @returns Deployed Ethers contract instance. | ||
*/ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export async function getDeployedContract<T extends BaseContract>( | ||
deploymentName: string, | ||
): Promise<T> { | ||
const { address, abi } = await deployments.get(deploymentName) | ||
|
||
// Use default unnamed signer from index 0 to initialize the contract runner. | ||
const [defaultSigner] = await getUnnamedSigner() | ||
|
||
return new ethers.BaseContract(address, abi, defaultSigner) as T | ||
} |
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,3 @@ | ||
export * from "./context" | ||
export * from "./contract" | ||
export * from "./signer" |
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,37 @@ | ||
import { ethers, getNamedAccounts, getUnnamedAccounts } from "hardhat" | ||
|
||
import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" | ||
|
||
/** | ||
* Get named Hardhat Ethers Signers. | ||
* @returns Map of named Hardhat Ethers Signers. | ||
*/ | ||
export async function getNamedSigner(): Promise<{ | ||
[name: string]: HardhatEthersSigner | ||
}> { | ||
const namedSigners: { [name: string]: HardhatEthersSigner } = {} | ||
|
||
await Promise.all( | ||
Object.entries(await getNamedAccounts()).map(async ([name, address]) => { | ||
namedSigners[name] = await ethers.getSigner(address) | ||
}), | ||
) | ||
|
||
return namedSigners | ||
} | ||
|
||
/** | ||
* Get unnamed Hardhat Ethers Signers. | ||
* @returns Array of unnamed Hardhat Ethers Signers. | ||
*/ | ||
export async function getUnnamedSigner(): Promise<HardhatEthersSigner[]> { | ||
const unnamedSigners: HardhatEthersSigner[] = [] | ||
|
||
await Promise.all( | ||
(await getUnnamedAccounts()).map(async (address) => { | ||
unnamedSigners.push(await ethers.getSigner(address)) | ||
}), | ||
) | ||
|
||
return unnamedSigners | ||
nkuba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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.
Let's define type eg.
type NamedSigners = { [name: string]: HardhatEthersSigner }
and we can use it in the line below: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.
This is a straightforward mapping holding broadly used
HardhatEthersSigner
properties.When you use the function, you see what to expect:
With
NamedSigners
type, you don't see right away what the function will return:IMHO, it will be more convenient for development to define this helper function using the current approach,
HardhatEthersSigner,
rather than a custom type.