Skip to content
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

Add tests to docker build #339

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,28 @@ name: Build-Docker image

on:
push:
branches: [main]
branches: [main, develop, feature/ongoingPP]
pull_request:
branches: [main, develop, feature/ongoingPP]
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Set int-bot SSH key
run: |
touch /tmp/ssh-key
echo "${{ secrets.INT_BOT_SSH_KEY }}" > /tmp/ssh-key
chmod 400 /tmp/ssh-key
eval "$(ssh-agent -s)"
ssh-add /tmp/ssh-key
- name: Checkout code
uses: actions/checkout@v3
- name: setup
- name: Setup docker
run: |
eval "$(ssh-agent -s)"
ssh-add /tmp/ssh-key
npm i
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker
run: npm run docker:contracts
- name: Push docker image
run: npm run push:docker:contracts
# Steps to push multi-platform image, it relies on the previous step:
# npm run docker:contracts
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
push: true
tags: hermeznetwork/geth-zkevm-contracts:1.5-integration
file: docker/Dockerfile
context: .
run: npm run docker:tests
ignasirv marked this conversation as resolved.
Show resolved Hide resolved
60 changes: 60 additions & 0 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build-Docker image

on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Set int-bot SSH key
run: |
touch /tmp/ssh-key
echo "${{ secrets.INT_BOT_SSH_KEY }}" > /tmp/ssh-key
chmod 400 /tmp/ssh-key
eval "$(ssh-agent -s)"
ssh-add /tmp/ssh-key
- name: Checkout code
uses: actions/checkout@v3
- name: setup
run: |
eval "$(ssh-agent -s)"
ssh-add /tmp/ssh-key
npm i
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker
run: npm run docker:contracts
- name: Push docker image
run: npm run push:docker:contracts
# Steps to push multi-platform image, it relies on the previous step:
# npm run docker:contracts
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
push: true
tags: hermeznetwork/geth-zkevm-contracts:1.5-integration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsut double checking the tag, is this correct?¿

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one is using the image created by the gha. Therefore, we can delete this entire gha

file: docker/Dockerfile
context: .
2 changes: 1 addition & 1 deletion .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
78 changes: 78 additions & 0 deletions docker/docker-tests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {expect} from "chai";
import {ethers} from "hardhat";
import fs from "fs";
import path from "path";
const deployOutput = JSON.parse(fs.readFileSync(path.join(__dirname, "./deploymentOutput/deploy_output.json"), "utf8"));
const {polygonRollupManagerAddress, polygonZkEVMBridgeAddress, polygonZkEVMGlobalExitRootAddress, polTokenAddress} =
deployOutput;
const createRollupOutput = JSON.parse(
fs.readFileSync(path.join(__dirname, "./deploymentOutput/create_rollup_output.json"), "utf8")
);
const {rollupAddress} = createRollupOutput;
import {
PolygonRollupManager,
PolygonZkEVMGlobalExitRootV2,
PolygonZkEVMBridgeV2,
PolygonZkEVMEtrog,
} from "../typechain-types";

describe("Docker build tests Contract", () => {
it("should check PolygonZkEVMEtrog", async () => {
const PolygonZkEVMEtrogFactory = await ethers.getContractFactory("PolygonZkEVMEtrog");
const PolygonZkEVMEtrogContract = PolygonZkEVMEtrogFactory.attach(rollupAddress) as PolygonZkEVMEtrog;
expect(PolygonZkEVMEtrogContract.target).to.equal(rollupAddress);
expect(await PolygonZkEVMEtrogContract.globalExitRootManager()).to.equal(polygonZkEVMGlobalExitRootAddress);
expect(await PolygonZkEVMEtrogContract.pol()).to.equal(polTokenAddress);
expect(await PolygonZkEVMEtrogContract.bridgeAddress()).to.equal(polygonZkEVMBridgeAddress);
expect(await PolygonZkEVMEtrogContract.rollupManager()).to.equal(polygonRollupManagerAddress);
const admin = await PolygonZkEVMEtrogContract.admin();
// If admin is not zero address, means the contract is already initialized
expect(admin).to.not.equal(ethers.ZeroAddress);
});

it("should check RollupManager", async () => {
const PolygonRollupManagerFactory = await ethers.getContractFactory("PolygonRollupManager");
const rollupManagerContract = PolygonRollupManagerFactory.attach(
polygonRollupManagerAddress
) as PolygonRollupManager;
expect(rollupManagerContract.target).to.equal(polygonRollupManagerAddress);
expect(await rollupManagerContract.bridgeAddress()).to.equal(polygonZkEVMBridgeAddress);
expect(await rollupManagerContract.globalExitRootManager()).to.equal(polygonZkEVMGlobalExitRootAddress);
expect(await rollupManagerContract.pol()).to.equal(polTokenAddress);
});

it("should check GlobalExitRootV2", async () => {
const PolygonZkEVMGlobalExitRootV2Factory = await ethers.getContractFactory("PolygonZkEVMGlobalExitRootV2");
const PolygonZkEVMGlobalExitRootV2Contract = PolygonZkEVMGlobalExitRootV2Factory.attach(
polygonZkEVMGlobalExitRootAddress
) as PolygonZkEVMGlobalExitRootV2;
expect(PolygonZkEVMGlobalExitRootV2Contract.target).to.equal(polygonZkEVMGlobalExitRootAddress);
expect(await PolygonZkEVMGlobalExitRootV2Contract.bridgeAddress()).to.equal(polygonZkEVMBridgeAddress);
expect(await PolygonZkEVMGlobalExitRootV2Contract.rollupManager()).to.equal(polygonRollupManagerAddress);
// Check already initialized
await expect(
PolygonZkEVMGlobalExitRootV2Contract.initialize()
).to.be.revertedWith("Initializable: contract is already initialized");
});

it("should check PolygonZkEVMBridgeV2", async () => {
const PolygonZkEVMBridgeV2Factory = await ethers.getContractFactory("PolygonZkEVMBridgeV2");
const PolygonZkEVMBridgeV2Contract = PolygonZkEVMBridgeV2Factory.attach(
polygonZkEVMBridgeAddress
) as PolygonZkEVMBridgeV2;
expect(PolygonZkEVMBridgeV2Contract.target).to.equal(polygonZkEVMBridgeAddress);
expect(await PolygonZkEVMBridgeV2Contract.globalExitRootManager()).to.equal(polygonZkEVMGlobalExitRootAddress);
expect(await PolygonZkEVMBridgeV2Contract.polygonRollupManager()).to.equal(polygonRollupManagerAddress);
// Check already initialized
await expect(
PolygonZkEVMBridgeV2Contract.initialize(
0,
ethers.ZeroAddress, // zero for ether
ethers.ZeroAddress, // zero for ether
polygonZkEVMGlobalExitRootAddress,
polygonRollupManagerAddress,
"0x"
)
).to.be.revertedWith("Initializable: contract is already initialized");
});
});
3 changes: 3 additions & 0 deletions docker/scripts/v2/deploy-docker.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash
# Set the -e option to stop the script if any command fails
set -e
sudo rm -rf docker/gethData/geth_data
sudo DEV_PERIOD=1 docker-compose -f docker/docker-compose.yml up -d geth
sleep 5
node docker/scripts/fund-accounts.js
cp docker/scripts/v2/deploy_parameters_docker.json deployment/v2/deploy_parameters.json
cp docker/scripts/v2/create_rollup_parameters_docker.json deployment/v2/create_rollup_parameters.json
npm run deploy:testnet:v2:localhost
rm -rf docker/deploymentOutput
mkdir docker/deploymentOutput
sudo mv deployment/v2/deploy_output.json docker/deploymentOutput
sudo mv deployment/v2/genesis.json docker/deploymentOutput
Expand Down
3 changes: 3 additions & 0 deletions docker/scripts/v2/deploy-dockerv2.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash
# Set the -e option to stop the script if any command fails
set -e
sudo rm -rf docker/gethData/geth_data
sudo DEV_PERIOD=1 docker compose -f docker/docker-compose.yml up -d geth
sleep 5
node docker/scripts/fund-accounts.js
cp docker/scripts/v2/deploy_parameters_docker.json deployment/v2/deploy_parameters.json
cp docker/scripts/v2/create_rollup_parameters_docker.json deployment/v2/create_rollup_parameters.json
npm run deploy:testnet:v2:localhost
rm -rf docker/deploymentOutput
mkdir docker/deploymentOutput
sudo mv deployment/v2/deploy_output.json docker/deploymentOutput
sudo mv deployment/v2/genesis.json docker/deploymentOutput
Expand Down
14 changes: 14 additions & 0 deletions docker/scripts/v2/tests-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Set the -e option to stop the script if any command fails
set -e
# Build docker
npm run dockerv2:contracts
# Run docker tests
# Run container
docker run -p 8545:8545 -d --name docker_test hermeznetwork/geth-zkevm-contracts
# Run docker tests
npx hardhat test docker/docker-tests.test.ts --network localhost
# stop container
docker stop docker_test
# remove container
docker container rm docker_test
Loading
Loading