-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪚 Adding E2E test infrastructure (#23)
- Loading branch information
1 parent
b37332b
commit 6db10e9
Showing
14 changed files
with
298 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# CI/CD files | ||
.changeset | ||
.github | ||
.husky | ||
|
||
# Dependencies & deployments | ||
node_modules | ||
deployments | ||
|
||
# Metadata | ||
*.md | ||
|
||
# Docker files | ||
docker-compose.templates.yaml |
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,83 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Base node image with project dependencies | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
FROM node:18.16.0 as dependencies | ||
|
||
ARG NPM_TOKEN | ||
ENV YARN_CACHE_FOLDER=/tmp/yarn_cache | ||
|
||
# Update the system packages | ||
RUN apt-get update | ||
RUN apt-get install -y \ | ||
# Get the envsubst command (see below) | ||
gettext-base | ||
|
||
WORKDIR /app | ||
|
||
# Get the source code | ||
# | ||
# Oh god why yarn, paleolithic technology | ||
# | ||
# This would normally only copy package.json and/or lockfile | ||
# and install the dependencies from lockfile in order not to break the cache | ||
# everytime a file changes | ||
COPY . . | ||
|
||
# Get the .npmrc under a different name since envsubst will not work in place | ||
# due to how pipes work on linux | ||
# | ||
# envsubst is a neat little thing that can substitute environment variables in a string | ||
# and we can use it to keep NPM_TOKEN secret | ||
# | ||
# What we do is : | ||
# | ||
# - We pass the NPM_TOKEN as ARG | ||
# - Set it as ENV variable only for the envsubst command so that it does not hang in the environment | ||
# - Replace the environment variables in .npmrctemplate | ||
# - Pipe the result to .npmrc | ||
# | ||
# We cannot do it in place (i.e. envsubst < .npmrc > .npmrc) because how linux works | ||
# (it will create the output .npmrc file first, the pipe to it - but since it is now empty nothing will be piped) | ||
COPY .npmrc .npmrctemplate | ||
|
||
RUN \ | ||
# Mount yarn cache | ||
--mount=type=cache,target=/tmp/yarn_cache \ | ||
# Substitute NPM_TOKEN in .npmrc | ||
NPM_TOKEN=$NPM_TOKEN envsubst < .npmrctemplate > .npmrc && \ | ||
# Install dependencies (fail if we forgot to update the lockfile) | ||
yarn install --prefer-offline --frozen-lockfile --non-interactive && \ | ||
# Remove .npmrc immediately | ||
rm -rf .npmrc | ||
|
||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Image that builds the project | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
FROM dependencies as build | ||
|
||
# Let's now add some fancy shit to compensate for the yarn fail above | ||
# | ||
# Turborepo allows us to be specific about the scope of the scripts | ||
# using the --filter flag - see more here https://turbo.build/repo/docs/core-concepts/monorepos/filtering | ||
ARG FILTER | ||
|
||
WORKDIR /app | ||
|
||
# Since our FILTER arg can be empty, we only want to pass the --filter | ||
# flag to turborepo if FILTER is actually used | ||
# | ||
# This is nicely accomplished by the + alternate value substitution | ||
# and results in something like --filter=my-filter | ||
RUN yarn build ${FILTER:+--filter=$FILTER} |
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,18 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Reusable services for docker compose | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
version: "3.9" | ||
|
||
services: | ||
# Service that can build the whole project | ||
project: | ||
build: | ||
context: . | ||
args: | ||
NPM_TOKEN: $NPM_TOKEN |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
cache | ||
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,26 @@ | ||
import { type DeployFunction } from "hardhat-deploy/types" | ||
import { AddressZero } from "@ethersproject/constants" | ||
import assert from "assert" | ||
|
||
/** | ||
* This deploy function will deploy and configure LayerZero endpoint | ||
* | ||
* @param env `HardhatRuntimeEnvironment` | ||
*/ | ||
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => { | ||
assert(network.config.endpointId != null, `Missing endpoint ID for network ${network.name}`) | ||
|
||
const [deployer] = await getUnnamedAccounts() | ||
const endpointV2Deployment = await deployments.deploy("EndpointV2", { | ||
from: deployer, | ||
args: [network.config.endpointId, AddressZero], | ||
}) | ||
|
||
console.table({ | ||
EndpointV2: endpointV2Deployment.address, | ||
}) | ||
} | ||
|
||
deploy.tags = ["Bootstrap", "EndpointV2"] | ||
|
||
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,33 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Reusable services for docker compose | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
version: "3.9" | ||
|
||
services: | ||
# Service that can build this package | ||
package: | ||
build: | ||
args: | ||
FILTER: ua-utils-test-v2... | ||
extends: | ||
file: ../../docker-compose.templates.yaml | ||
service: project | ||
working_dir: /app/packages/ua-utils-test-v2 | ||
volumes: | ||
- ./:/app/packages/ua-utils-test-v2 | ||
|
||
# Hardhat node started on port 8545 | ||
node: | ||
extends: | ||
service: package | ||
expose: | ||
- 8545 | ||
command: ["npx", "hardhat", "node", "--hostname", "0.0.0.0", "--no-deploy"] | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://0.0.0.0:8545/"] |
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 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Docker compose for running E2E tests | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
version: "3.9" | ||
|
||
services: | ||
# ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ | ||
# | ||
# Network nodes, one for every hardhat network | ||
# | ||
# .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. | ||
network-vengaboys: | ||
extends: | ||
file: docker-compose.templates.yaml | ||
service: node | ||
|
||
network-britney: | ||
extends: | ||
file: docker-compose.templates.yaml | ||
service: node | ||
|
||
# ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ | ||
# | ||
# Bootstrap script that deploys all the networks | ||
# | ||
# .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. | ||
bootstrap: | ||
extends: | ||
file: docker-compose.templates.yaml | ||
service: package | ||
depends_on: | ||
network-vengaboys: | ||
condition: service_healthy | ||
network-britney: | ||
condition: service_healthy | ||
# Can't say I love the fact that the deploy scripts are inlined here | ||
# but at least it's all in this file that bootstraps the whole environment | ||
# | ||
# The "&" at the end of the lines and "wait" work together to execute the deployments | ||
# in parallel and wait until they are all complete | ||
command: | ||
- /bin/bash | ||
- -c | ||
- | | ||
npx hardhat --network vengaboys deploy --reset & | ||
npx hardhat --network britney deploy --reset & | ||
wait | ||
# ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~ | ||
# | ||
# The actual tests | ||
# | ||
# .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo. | ||
tests: | ||
extends: | ||
file: docker-compose.templates.yaml | ||
service: package | ||
depends_on: | ||
bootstrap: | ||
condition: service_completed_successfully | ||
command: ["npx", "hardhat", "test"] |
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 |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import hre from "hardhat" | ||
import { expect } from "chai" | ||
import { describe } from "mocha" | ||
import { NetworkEnvironment, createGetNetworkEnvironment } from "@layerzerolabs/hardhat-utils" | ||
|
||
const NETWORK_NAMES = ["vengaboys", "britney"] | ||
|
||
describe("config", () => { | ||
it("should always succeed", () => { | ||
expect(1).to.equal(1) | ||
NETWORK_NAMES.forEach((networkName) => { | ||
const getEnvironment = createGetNetworkEnvironment(hre) | ||
|
||
describe(`Network '${networkName}`, () => { | ||
let environment: NetworkEnvironment | ||
|
||
before(async () => { | ||
environment = await getEnvironment(networkName) | ||
}) | ||
|
||
it("should have an endpoint deployed", async () => { | ||
const endpoint = await environment.getContract("EndpointV2", environment.provider) | ||
const endpointId = await endpoint.eid() | ||
|
||
expect(environment.network.config.endpointId).to.be.a("number") | ||
expect(endpointId).to.eql(environment.network.config.endpointId) | ||
}) | ||
}) | ||
}) | ||
}) |
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