-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f9dca1
commit 3a1afdb
Showing
17 changed files
with
783 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
artifacts | ||
cache | ||
deployments | ||
dist | ||
node_modules |
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 @@ | ||
{ | ||
"extends": "../../.eslintrc.json" | ||
} |
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 @@ | ||
artifacts | ||
cache | ||
deployments |
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,5 @@ | ||
artifacts/ | ||
cache/ | ||
deployments/ | ||
dist/ | ||
node_modules/ |
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,13 @@ | ||
<p align="center"> | ||
<a href="https://layerzero.network"> | ||
<img alt="LayerZero" style="max-width: 500px" src="https://d3a2dpnnrypp5h.cloudfront.net/bridge-app/lz.png"/> | ||
</a> | ||
</p> | ||
|
||
<h1 align="center">@layerzerolabs/ua-devtools-evm-hardhat-v1-test</h1> | ||
|
||
## Development | ||
|
||
This package provides integration tests for `@layerzerolabs/ua-devtools-evm-hardhat` executed within a containerized setup. These tests are dependent on two networks that are bootstrapped in the root `docker-compose.yaml` and will only run when executed within that environment. | ||
|
||
Please see the root [`README.md`](../../README.md) for more information. |
16 changes: 16 additions & 0 deletions
16
tests/ua-devtools-evm-hardhat-v1-test/contracts/DefaultLzApp.sol
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,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { LzApp } from "@layerzerolabs/lz-evm-oapp-v1/contracts/lzApp/LzApp.sol"; | ||
|
||
contract DefaultLzApp is LzApp { | ||
constructor(address _endpoint, address _delegate) LzApp(_endpoint) Ownable(_delegate) {} | ||
|
||
function _blockingLzReceive( | ||
uint16 _srcChainId, | ||
bytes memory _srcAddress, | ||
uint64 _nonce, | ||
bytes memory _payload | ||
) internal virtual override {} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/ua-devtools-evm-hardhat-v1-test/deploy/001_bootstrap.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { formatEid } from '@layerzerolabs/devtools' | ||
import assert from 'assert' | ||
import { type DeployFunction } from 'hardhat-deploy/types' | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types' | ||
|
||
/** | ||
* This `deploy` function will deploy and configure LayerZero Endpoint (V1) | ||
* | ||
* @param {HardhatRuntimeEnvironment} env | ||
*/ | ||
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => { | ||
assert(network.config.eid != null, `Missing endpoint ID for network ${network.name}`) | ||
|
||
const [deployer] = await getUnnamedAccounts() | ||
assert(deployer, 'Missing deployer') | ||
|
||
await deployments.delete('Endpoint') | ||
const endpointDeployment = await deployments.deploy('Endpoint', { | ||
from: deployer, | ||
args: [network.config.eid, deployer], | ||
}) | ||
|
||
console.table({ | ||
Network: `${network.name} (endpoint ${formatEid(network.config.eid)})`, | ||
EndpointV2: endpointDeployment.address, | ||
}) | ||
} | ||
|
||
deploy.tags = ['Bootstrap', 'Endpoint'] | ||
|
||
export default deploy |
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,31 @@ | ||
import { formatEid } from '@layerzerolabs/devtools' | ||
import { type DeployFunction } from 'hardhat-deploy/types' | ||
import assert from 'assert' | ||
|
||
/** | ||
* This deploy function will deploy DefaultLzApp | ||
* | ||
* @param env `HardhatRuntimeEnvironment` | ||
*/ | ||
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => { | ||
assert(network.config.eid != null, `Missing endpoint ID for network ${network.name}`) | ||
|
||
const [deployer] = await getUnnamedAccounts() | ||
assert(deployer, 'Missing deployer') | ||
|
||
await deployments.delete('DefaultLzApp') | ||
const endpointV2 = await deployments.get('Endpoint') | ||
const defaultLzAppDeployment = await deployments.deploy('DefaultLzApp', { | ||
from: deployer, | ||
args: [endpointV2.address, deployer], | ||
}) | ||
|
||
console.table({ | ||
Network: `${network.name} (endpoint ${formatEid(network.config.eid)})`, | ||
DefaultLzApp: defaultLzAppDeployment.address, | ||
}) | ||
} | ||
|
||
deploy.tags = ['LzApp', 'DefaultLzApp'] | ||
|
||
export default deploy |
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,78 @@ | ||
import 'hardhat-deploy' | ||
import '@layerzerolabs/toolbox-hardhat' | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import type { HardhatUserConfig } from 'hardhat/types' | ||
|
||
const MNEMONIC = process.env.MNEMONIC ?? '' | ||
|
||
/** | ||
* This is a dummy hardhat config that enables us to test | ||
* hardhat functionality without mocking too much | ||
*/ | ||
const config: HardhatUserConfig = { | ||
layerZero: { | ||
// Since we are deploying our own protocol contracts, | ||
// we'll skip the external deployment imports | ||
deploymentSourcePackages: [], | ||
// Since we are working with V1 only here, we'll only include the V1 SDKs | ||
artifactSourcePackages: ['@layerzerolabs/lz-evm-sdk-v1', '@layerzerolabs/test-devtools-evm-hardhat'], | ||
}, | ||
solidity: { | ||
version: '0.8.22', | ||
}, | ||
networks: { | ||
vengaboys: { | ||
eid: EndpointId.ETHEREUM_MAINNET, | ||
// Containerized setup defines these environment variables | ||
// to point the networks to the internal ones | ||
// | ||
// If these are not specified, exposed networks are used | ||
// | ||
// See root README.md for usage with exposed network | ||
url: process.env.NETWORK_URL_VENGABOYS ?? 'http://localhost:10001', | ||
accounts: { | ||
mnemonic: MNEMONIC, | ||
// We'll offset the initial index for the accounts by 10 | ||
// for every test project so that the project can use 10 accounts | ||
// without getting any nonce race conditions with other test runs | ||
initialIndex: 20, | ||
}, | ||
}, | ||
britney: { | ||
eid: EndpointId.AVALANCHE_MAINNET, | ||
// Containerized setup defines these environment variables | ||
// to point the networks to the internal ones | ||
// | ||
// If these are not specified, exposed networks are used | ||
// | ||
// See root README.md for usage with exposed network | ||
url: process.env.NETWORK_URL_BRITNEY ?? 'http://localhost:10002', | ||
accounts: { | ||
mnemonic: MNEMONIC, | ||
// We'll offset the initial index for the accounts by 10 | ||
// for every test project so that the project can use 10 accounts | ||
// without getting any nonce race conditions with other test runs | ||
initialIndex: 20, | ||
}, | ||
}, | ||
tango: { | ||
eid: EndpointId.BSC_MAINNET, | ||
// Containerized setup defines these environment variables | ||
// to point the networks to the internal ones | ||
// | ||
// If these are not specified, exposed networks are used | ||
// | ||
// See root README.md for usage with exposed network | ||
url: process.env.NETWORK_URL_TANGO ?? 'http://localhost:10003', | ||
accounts: { | ||
mnemonic: MNEMONIC, | ||
// We'll offset the initial index for the accounts by 10 | ||
// for every test project so that the project can use 10 accounts | ||
// without getting any nonce race conditions with other test runs | ||
initialIndex: 20, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default config |
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,14 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
cache: false, | ||
testEnvironment: 'node', | ||
testTimeout: 300_000, | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
transform: { | ||
'^.+\\.(t|j)sx?$': '@swc/jest', | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!zx)'], | ||
}; |
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,11 @@ | ||
import { rmSync } from 'fs'; | ||
import * as jestExtended from 'jest-extended'; | ||
|
||
// add all jest-extended matchers | ||
expect.extend(jestExtended); | ||
|
||
// clear all deployments before & after every test | ||
const clearDeployments = () => rmSync('./deployments', { force: true, recursive: true }); | ||
|
||
beforeEach(clearDeployments); | ||
afterEach(clearDeployments); |
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,67 @@ | ||
{ | ||
"name": "@layerzerolabs/ua-devtools-evm-hardhat-v1-test", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "Integration tests for ua-devtools-evm-hardhat for V1", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/LayerZero-Labs/devtools.git", | ||
"directory": "tests/ua-devtools-evm-hardhat-v1-test" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm -rf artifacts cache deployments", | ||
"compile": "$npm_execpath hardhat compile", | ||
"lint": "$npm_execpath eslint '**/*.{js,ts,json}'", | ||
"lint:fix": "eslint --fix '**/*.{js,ts,json}'", | ||
"test": "jest --ci --runInBand --forceExit" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.23.9", | ||
"@ethersproject/abi": "^5.7.0", | ||
"@ethersproject/abstract-signer": "^5.7.0", | ||
"@ethersproject/address": "~5.7.0", | ||
"@ethersproject/constants": "^5.7.0", | ||
"@ethersproject/contracts": "^5.7.0", | ||
"@ethersproject/providers": "^5.7.2", | ||
"@ethersproject/wallet": "^5.7.0", | ||
"@layerzerolabs/devtools": "~0.2.1", | ||
"@layerzerolabs/devtools-evm": "~0.2.1", | ||
"@layerzerolabs/devtools-evm-hardhat": "~0.2.1", | ||
"@layerzerolabs/io-devtools": "~0.1.3", | ||
"@layerzerolabs/lz-definitions": "~2.1.5", | ||
"@layerzerolabs/lz-evm-messagelib-v2": "~2.1.5", | ||
"@layerzerolabs/lz-evm-oapp-v1": "~2.1.5", | ||
"@layerzerolabs/lz-evm-oapp-v2": "~2.1.5", | ||
"@layerzerolabs/lz-evm-protocol-v2": "~2.1.5", | ||
"@layerzerolabs/lz-evm-sdk-v1": "~2.1.5", | ||
"@layerzerolabs/lz-evm-sdk-v2": "~2.1.5", | ||
"@layerzerolabs/lz-evm-v1-0.7": "~2.1.5", | ||
"@layerzerolabs/lz-v2-utilities": "~2.1.5", | ||
"@layerzerolabs/omnicounter-devtools": "~0.2.1", | ||
"@layerzerolabs/omnicounter-devtools-evm": "~0.2.1", | ||
"@layerzerolabs/protocol-devtools": "~0.2.1", | ||
"@layerzerolabs/protocol-devtools-evm": "~0.2.1", | ||
"@layerzerolabs/test-devtools-evm-hardhat": "~0.1.4", | ||
"@layerzerolabs/toolbox-hardhat": "~0.1.5", | ||
"@layerzerolabs/ua-devtools": "~0.2.1", | ||
"@layerzerolabs/ua-devtools-evm": "~0.2.1", | ||
"@layerzerolabs/ua-devtools-evm-hardhat": "~0.2.2", | ||
"@nomicfoundation/hardhat-ethers": "^3.0.5", | ||
"@nomiclabs/hardhat-ethers": "^2.2.3", | ||
"@openzeppelin/contracts": "^5.0.1", | ||
"@swc/core": "^1.4.0", | ||
"@swc/jest": "^0.2.36", | ||
"@types/jest": "^29.5.12", | ||
"ethers": "^5.7.2", | ||
"fast-check": "^3.15.1", | ||
"hardhat": "^2.19.5", | ||
"hardhat-deploy": "^0.11.45", | ||
"jest": "^29.7.0", | ||
"jest-extended": "^4.0.2", | ||
"solidity-bytes-utils": "^0.8.2", | ||
"ts-node": "^10.9.2", | ||
"tslib": "~2.6.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ua-devtools-evm-hardhat-v1-test/test/__utils__/endpoint.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getDefaultRuntimeEnvironment } from '@layerzerolabs/devtools-evm-hardhat' | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
import { TASK_LZ_DEPLOY } from '@layerzerolabs/devtools-evm-hardhat' | ||
|
||
export const ethEndpoint = { eid: EndpointId.ETHEREUM_MAINNET, contractName: 'Endpoint' } | ||
export const avaxEndpoint = { eid: EndpointId.AVALANCHE_MAINNET, contractName: 'Endpoint' } | ||
export const bscEndpoint = { eid: EndpointId.BSC_MAINNET, contractName: 'Endpoint' } | ||
|
||
/** | ||
* Deploys the Endpoint contracts | ||
*/ | ||
export const deployEndpoint = async (hre = getDefaultRuntimeEnvironment()) => { | ||
await hre.run(TASK_LZ_DEPLOY, { | ||
tags: ['Endpoint'], | ||
}) | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ua-devtools-evm-hardhat-v1-test/test/__utils__/lzapp.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getDefaultRuntimeEnvironment } from '@layerzerolabs/devtools-evm-hardhat' | ||
import { TASK_LZ_DEPLOY } from '@layerzerolabs/devtools-evm-hardhat' | ||
import { EndpointId } from '@layerzerolabs/lz-definitions' | ||
|
||
export const ethLzApp = { eid: EndpointId.ETHEREUM_MAINNET, contractName: 'DefaultLzApp' } | ||
export const avaxLzApp = { eid: EndpointId.AVALANCHE_MAINNET, contractName: 'DefaultLzApp' } | ||
export const bscLzApp = { eid: EndpointId.BSC_MAINNET, contractName: 'DefaultLzApp' } | ||
|
||
/** | ||
* Deploys the DefaultLzApp contracts | ||
*/ | ||
export const deployLzApp = async (hre = getDefaultRuntimeEnvironment()) => { | ||
await hre.run(TASK_LZ_DEPLOY, { | ||
tags: ['DefaultLzApp'], | ||
}) | ||
} |
73 changes: 73 additions & 0 deletions
73
tests/ua-devtools-evm-hardhat-v1-test/test/lzapp/config.test.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'hardhat' | ||
import { avaxLzApp, deployLzApp, ethLzApp } from '../__utils__/lzapp' | ||
import { createConnectedContractFactory, OmniContractFactoryHardhat } from '@layerzerolabs/devtools-evm-hardhat' | ||
import { configureLzApp, ILzApp, LzAppFactory, LzAppOmniGraph } from '@layerzerolabs/ua-devtools' | ||
import { OmniContract, omniContractToPoint } from '@layerzerolabs/devtools-evm' | ||
import { deployEndpoint } from '../__utils__/endpoint' | ||
import { OmniPoint, OmniTransaction } from '@layerzerolabs/devtools' | ||
import { createLzAppFactory } from '@layerzerolabs/ua-devtools-evm' | ||
|
||
describe('lzapp/config', () => { | ||
let contractFactory: OmniContractFactoryHardhat | ||
let lzappSdkFactory: LzAppFactory | ||
|
||
let ethContract: OmniContract | ||
let ethLzAppPoint: OmniPoint | ||
let ethLzAppSdk: ILzApp | ||
|
||
let avaxContract: OmniContract | ||
let avaxLzAppPoint: OmniPoint | ||
let avaxLzAppSdk: ILzApp | ||
let transactions: OmniTransaction[] | ||
|
||
// This is the LzApp config that we want to use against our contracts | ||
beforeEach(async () => { | ||
await deployEndpoint() | ||
await deployLzApp() | ||
|
||
contractFactory = createConnectedContractFactory() | ||
lzappSdkFactory = createLzAppFactory(contractFactory) | ||
|
||
ethContract = await contractFactory(ethLzApp) | ||
avaxContract = await contractFactory(avaxLzApp) | ||
|
||
ethLzAppPoint = omniContractToPoint(ethContract) | ||
ethLzAppSdk = await lzappSdkFactory(ethLzAppPoint) | ||
|
||
avaxLzAppPoint = omniContractToPoint(avaxContract) | ||
avaxLzAppSdk = await lzappSdkFactory(avaxLzAppPoint) | ||
}) | ||
|
||
describe('configureLzAppTrustedRemotes', () => { | ||
it('should return all setPeer transactions', async () => { | ||
const graph: LzAppOmniGraph = { | ||
contracts: [ | ||
{ | ||
point: ethLzAppPoint, | ||
}, | ||
{ | ||
point: avaxLzAppPoint, | ||
}, | ||
], | ||
connections: [ | ||
{ | ||
vector: { from: ethLzAppPoint, to: avaxLzAppPoint }, | ||
config: undefined, | ||
}, | ||
{ | ||
vector: { from: avaxLzAppPoint, to: ethLzAppPoint }, | ||
config: undefined, | ||
}, | ||
], | ||
} | ||
|
||
// This is the LzApp config that we want to use against our contracts | ||
transactions = await configureLzApp(graph, lzappSdkFactory) | ||
|
||
expect(transactions).toEqual([ | ||
await ethLzAppSdk.setTrustedRemote(avaxLzAppPoint.eid, avaxLzAppPoint.address), | ||
await avaxLzAppSdk.setTrustedRemote(ethLzAppPoint.eid, ethLzAppPoint.address), | ||
]) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.