-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: unit testing Hardhat Task: getDefaultConfig
- Loading branch information
1 parent
8f8b4c6
commit 557bd21
Showing
6 changed files
with
122 additions
and
121 deletions.
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
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
103 changes: 79 additions & 24 deletions
103
packages/ua-utils-evm-hardhat/src/tasks/getDefaultConfig.ts
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 |
---|---|---|
@@ -1,34 +1,89 @@ | ||
import { ActionType } from "hardhat/types" | ||
import { task, types } from "hardhat/config" | ||
import "hardhat-deploy-ethers/internal/type-extensions" | ||
import { ethers } from "ethers" | ||
import { getProvider, getLayerZeroChainId, getEndpointAddress } from "@/utils/crossChainHelper" | ||
import { ENDPOINT_ABI, MESSAGING_LIBRARY_ABI } from "@/constants/abi" | ||
import { getNetworkRuntimeEnvironment } from "@layerzerolabs/utils-evm-hardhat" | ||
|
||
export default async (taskArgs: any, hre: any) => { | ||
const networks = taskArgs.networks.split(",") | ||
const CONFIG_TYPE_MAX_MESSAGE_SIZE = 1 | ||
const CONFIG_TYPE_OUTBOUND_CONFIRMATIONS = 2 | ||
const CONFIG_TYPE_EXECUTOR = 3 | ||
const CONFIG_TYPE_INBOUND_CONFIRMATIONS = 4 | ||
const CONFIG_TYPE_VERIFIERS = 5 | ||
const CONFIG_TYPE_OPTIONAL_VERIFIERS = 6 | ||
interface TaskArgs { | ||
networks: string | ||
} | ||
export const getDefaultConfig: ActionType<TaskArgs> = async (taskArgs, hre) => { | ||
// TODO add logging | ||
// const logger = createLogger() | ||
|
||
const networks = taskArgs.networks.split(",") | ||
const configByNetwork = await Promise.all( | ||
networks.map(async (network: string) => { | ||
const provider = getProvider(hre, network) | ||
console.log() | ||
const endpoint = new ethers.Contract(getEndpointAddress(network), ENDPOINT_ABI, provider) | ||
const sendVersion = await endpoint.defaultSendVersion() | ||
const receiveVersion = await endpoint.defaultReceiveVersion() | ||
const sendLibraryAddress = await endpoint.defaultSendLibrary() | ||
const messagingLibrary = new ethers.Contract(sendLibraryAddress, MESSAGING_LIBRARY_ABI, provider) | ||
const config = await messagingLibrary.defaultAppConfig(getLayerZeroChainId(network)) | ||
|
||
return { | ||
const environment = await getNetworkRuntimeEnvironment(network) | ||
const endpointV2 = await environment.ethers.getContract("EndpointV2") | ||
const eid = await endpointV2.eid() | ||
|
||
const defaultSendLibrary = await endpointV2.defaultSendLibrary(eid) | ||
const defaultReceiveLibrary = await endpointV2.defaultReceiveLibrary(eid) | ||
|
||
const maxMessageSizeEncodedData = await endpointV2.defaultConfig(defaultSendLibrary, eid, CONFIG_TYPE_MAX_MESSAGE_SIZE) | ||
const maxMessageSize = ethers.utils.defaultAbiCoder.decode(["uint32"], maxMessageSizeEncodedData) | ||
|
||
const outboundConfirmationsEncodedData = await endpointV2.defaultConfig(defaultSendLibrary, eid, CONFIG_TYPE_OUTBOUND_CONFIRMATIONS) | ||
const outboundConfirmations = ethers.utils.defaultAbiCoder.decode(["uint64"], outboundConfirmationsEncodedData) | ||
|
||
const executorEncodedData = await endpointV2.defaultConfig(defaultSendLibrary, eid, CONFIG_TYPE_EXECUTOR) | ||
const executor = ethers.utils.defaultAbiCoder.decode(["address"], executorEncodedData) | ||
|
||
const inboundBlockConfirmationsEncodedData = await endpointV2.defaultConfig( | ||
defaultReceiveLibrary, | ||
eid, | ||
CONFIG_TYPE_INBOUND_CONFIRMATIONS | ||
) | ||
const inboundConfirmations = ethers.utils.defaultAbiCoder.decode(["uint64"], inboundBlockConfirmationsEncodedData) | ||
|
||
const verifiersEncodedData = await endpointV2.defaultConfig(defaultReceiveLibrary, eid, CONFIG_TYPE_VERIFIERS) | ||
const verifiers = ethers.utils.defaultAbiCoder.decode(["address[]"], verifiersEncodedData) | ||
|
||
const optionalVerifierEncodedData = await endpointV2.defaultConfig(defaultReceiveLibrary, eid, CONFIG_TYPE_OPTIONAL_VERIFIERS) | ||
const [optionalVerifiers, optionalVerifierThreshold] = ethers.utils.defaultAbiCoder.decode( | ||
["address[]", "uint8"], | ||
optionalVerifierEncodedData | ||
) | ||
|
||
const defaultConfig = { | ||
network, | ||
defaultSendLibrary, | ||
defaultReceiveLibrary, | ||
maxMessageSize: maxMessageSize[0], | ||
outboundConfirmations: outboundConfirmations[0], | ||
executor: executor.toString(), | ||
inboundConfirmations: inboundConfirmations[0], | ||
verifiers: verifiers[0], | ||
optionalVerifiers, | ||
optionalVerifierThreshold, | ||
} | ||
|
||
const consoleTableDefaultConfig = { | ||
network, | ||
sendVersion, | ||
receiveVersion, | ||
inboundProofLibraryVersion: config.inboundProofLibraryVersion, | ||
inboundBlockConfirmations: config.inboundBlockConfirmations.toNumber(), | ||
relayer: config.relayer, | ||
outboundProofType: config.outboundProofType, | ||
outboundBlockConfirmations: config.outboundBlockConfirmations.toNumber(), | ||
oracle: config.oracle, | ||
defaultSendLibrary, | ||
defaultReceiveLibrary, | ||
maxMessageSize: maxMessageSize[0], | ||
outboundConfirmations: outboundConfirmations[0].toNumber(), | ||
executor: executor.toString(), | ||
inboundBlockConfirmations: inboundConfirmations[0].toNumber(), | ||
verifiers: verifiers[0].toString(), | ||
optionalVerifiers, | ||
optionalVerifierThreshold, | ||
} | ||
return { defaultConfig, consoleTableDefaultConfig } | ||
}) | ||
) | ||
|
||
console.table(configByNetwork) | ||
console.log(configByNetwork[0].consoleTableDefaultConfig) | ||
return configByNetwork[0].defaultConfig | ||
} | ||
|
||
task("getDefaultConfig", "outputs the default Send and Receive Messaging Library versions and the default application config") | ||
.addParam("networks", "comma separated list of networks") | ||
.setAction(getDefaultConfig) |
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 |
---|---|---|
@@ -1,63 +1 @@ | ||
import { task, types } from "hardhat/config" | ||
import wireAll from "./wireAll" | ||
import setConfig from "./setConfig" | ||
import getDefaultConfig from "./getDefaultConfig" | ||
import getConfig from "./getConfig" | ||
import checkWireAllConfig from "./checkWireAllConfig" | ||
|
||
task( | ||
"setConfig", | ||
"sets Send and Receive Messaging Library versions and a custom application config for contracts implementing ILayerZeroUserApplicationConfig interface", | ||
setConfig | ||
) | ||
.addParam("configPath", "the application config file path") | ||
.addOptionalParam( | ||
"name", | ||
"name of the deployed contracts. Should be specified if the same contract deployed on different chains and the deployment information is located in the deployments folder" | ||
) | ||
.addOptionalParam("address", "address of the deployed contracts. Should be specified if the contract address is the same on all chains") | ||
.addOptionalParam("gnosisConfigPath", "the path to a file with Gnosis config. If specified, the transactions will be sent to Gnosis") | ||
.addOptionalParam("gasLimit", "override execution gasLimit") | ||
|
||
task( | ||
"getDefaultConfig", | ||
"outputs the default Send and Receive Messaging Library versions and the default application config", | ||
getDefaultConfig | ||
).addParam("networks", "comma separated list of networks") | ||
|
||
task("getConfig", "outputs the application's Send and Receive Messaging Library versions and the config for remote networks", getConfig) | ||
.addParam("remoteNetworks", "comma separated list of remote networks") | ||
.addOptionalParam( | ||
"name", | ||
"name of the deployed contract. Should be specified only if the deployment information is located in the deployments folder" | ||
) | ||
.addOptionalParam("address", "the contract address") | ||
|
||
task("checkWireAllConfig", "", checkWireAllConfig) | ||
.addParam("e", "the environment ie: mainnet, testnet or sandbox") | ||
.addFlag("u", "show use custom adapter params") | ||
.addFlag("t", "show trusted remote lookup") | ||
.addFlag("m", "show min destination gas lookup") | ||
.addParam("chains", "comma separated list of networks") | ||
.addOptionalParam("contract", "name of contract") | ||
.addOptionalParam("addresses", "addresses of contracts in same order as chains") | ||
.addOptionalParam("proxyContract", "name of proxy contract") | ||
.addOptionalParam("proxyChain", "name of proxy chain") | ||
|
||
task("wireAll", "", wireAll) | ||
.addParam("e", "the environment ie: mainnet, testnet or sandbox") | ||
.addOptionalParam("noPrompt", "no prompt", false, types.boolean) | ||
.addOptionalParam( | ||
"configPath", | ||
"Optional config path. Default: ./constants/wireUpConfig.json", | ||
"./constants/wireUpConfig.json", | ||
types.string | ||
) | ||
.addOptionalParam("n", "send to gnosis", false, types.boolean) | ||
.addOptionalParam("gasLimit", "override execution gasLimit") | ||
.addOptionalParam( | ||
"gnosisConfigPath", | ||
"Optional config path. Default: ./constants/gnosisConfig.json", | ||
"./constants/gnosisConfig.json", | ||
types.string | ||
) | ||
import "./getDefaultConfig" |