Skip to content

Commit

Permalink
chore: add full e2e dockerfile and upgrade node version (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
DefiCake committed Aug 16, 2024
1 parent c50d3ad commit c978d08
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-buses-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@fuel-bridge/solidity-contracts': minor
'@fuel-bridge/test-utils': minor
---

Adapted deployments for a full e2e environment, and minor util adaptions to anvil quirks
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OS
.DS_Store
# Node.js
node_modules
.env
.turbo

# Misc
.idea
.DS_Store

# Hardhat files
cache
artifacts

# Cargo and Forc artifacts
out
target
*/out
*/target

# fuels-ts typegen artifacts
packages/fungible-token/exports/types

# General dist folders
dist
11 changes: 10 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Build and push Fuel Bridge Ethereum Test Image
- name: Build and push a test image containing only the ETH node and contracts
uses: ./.github/actions/docker-publish
id: publish
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
image: ghcr.io/fuellabs/fuel-bridge
dockerfile: docker/l1-chain/Dockerfile

- name: Build and push a test image containing all components for e2e tests
uses: ./.github/actions/docker-publish
id: publish-full
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
image: ghcr.io/fuellabs/fuel-bridge-full
dockerfile: docker/full-env/Dockerfile
1 change: 1 addition & 0 deletions .github/workflows/pr-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- uses: ./.github/actions/setup-rust
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- uses: FuelLabs/github-actions/setups/npm@master
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- run: pnpm audit --prod --audit-level high

Expand Down Expand Up @@ -50,6 +51,7 @@ jobs:
fetch-depth: 0
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- run: pnpm changeset:check

Expand All @@ -60,6 +62,7 @@ jobs:
- uses: actions/checkout@v3
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- uses: FuelLabs/github-actions/setups/docker@master
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
fetch-depth: 0
- uses: FuelLabs/github-actions/setups/node@master
with:
node-version: 20.16.0
pnpm-version: 9.0.6
- uses: FuelLabs/github-actions/setups/npm@master
with:
Expand Down
76 changes: 76 additions & 0 deletions docker/full-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This image is built for external projects that want to have
# an e2e test environment
FROM ghcr.io/fuellabs/fuel-core:v0.31.0 as fuel-core
FROM ghcr.io/fuellabs/fuel-block-committer:v0.4.0 as fuel-committer

FROM node:20-slim as base
USER 0
ENV DEBIAN_FRONTEND=noninteractive
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

RUN apt update
RUN apt install -y curl git file jq

# Download and install forc binaries
FROM base as forc-downloader

ENV FORC_VERSION=v0.60.0
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ]; then \
FORC_URL="https://github.com/FuelLabs/sway/releases/download/$FORC_VERSION/forc-binaries-linux_arm64.tar.gz"; \
elif [ "$ARCH" = "x86_64" ]; then \
FORC_URL="https://github.com/FuelLabs/sway/releases/download/$FORC_VERSION/forc-binaries-linux_amd64.tar.gz"; \
else \
echo "Unsupported architecture: $ARCH" && exit 1; \
fi && \
mkdir -p /tmp/forc-binaries && \
curl -L $FORC_URL | tar -xz -C /tmp && \
mv /tmp/forc-binaries/* /usr/local/bin/

# Download and install anvil
FROM base as foundry-downloader
RUN curl -L https://foundry.paradigm.xyz | bash
RUN /root/.foundry/bin/foundryup

FROM base as base-builder

COPY --from=fuel-core /root/fuel-core /root/fuel-core
COPY --from=fuel-committer /root/fuel-block-committer /root/fuel-block-committer
COPY --from=forc-downloader /usr/local/bin/forc* /usr/local/bin
COPY --from=foundry-downloader /root/.foundry /root/.foundry

ENV DEBIAN_FRONTEND=noninteractive
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN npm i -g pm2

WORKDIR /fuel-bridge

COPY packages packages
COPY package.json package.json
COPY pnpm-* .
COPY Forc* .
COPY fuel-toolchain.toml .
COPY tsconfig.json .
COPY turbo.json .

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

FROM base-builder as sway-contracts
RUN cd /fuel-bridge/packages/esbuild-bin-loader && pnpm build
RUN cd /fuel-bridge && forc build --release
RUN cd /fuel-bridge/packages/fungible-token && pnpm build

FROM base-builder as solidity-contracts
RUN cd /fuel-bridge/packages/solidity-contracts && pnpm build

FROM solidity-contracts as full-env

COPY --from=sway-contracts /fuel-bridge/packages/esbuild-bin-loader /fuel-bridge/packages/esbuild-bin-loader
COPY --from=sway-contracts /fuel-bridge/packages/fungible-token /fuel-bridge/packages/fungible-token

COPY docker/full-env/run.sh /run.sh

ENTRYPOINT [ "bash", "/run.sh" ]
67 changes: 67 additions & 0 deletions docker/full-env/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

#### ETHEREUM BOOTSTRAP
export ETH_BLOCK_TIME=${ETH_BLOCK_TIME:-12}
export ETH_ACCOUNTS=${ETH_ACCOUNTS:-20}
export ETH_MNEMONIC="${ETH_MNEMONIC:-test test test test test test test test test test test junk}"
pm2 --name eth start "/root/.foundry/bin/anvil \
--host 0.0.0.0 \
--mnemonic \"$ETH_MNEMONIC\" \
--accounts $ETH_ACCOUNTS \
--block-time $ETH_BLOCK_TIME \
--mixed-mining \
--slots-in-an-epoch 1"

cd /fuel-bridge/packages/solidity-contracts \
&& npx hardhat deploy --network localhost --reset \
&& cd -

export DEPLOYMENTS_DIR=/fuel-bridge/packages/solidity-contracts/deployments/localhost
export STATE_ADDRESS=$(jq -r '.address' $DEPLOYMENTS_DIR/FuelChainState.json)
export PORTAL_ADDRESS=$(jq -r '.address' $DEPLOYMENTS_DIR/FuelMessagePortal.json)
export GATEWAY_ADDRESS=$(jq -r '.address' $DEPLOYMENTS_DIR/FuelERC20Gateway.json)

#### FUEL BOOTSTRAP
pm2 --name fuel start "/root/fuel-core run \
--ip 0.0.0.0 \
--port 4000 \
--db-type in-memory \
--utxo-validation \
--vm-backtrace \
--enable-relayer \
--relayer http://localhost:8545 \
--relayer-v2-listening-contracts $PORTAL_ADDRESS \
--poa-interval-period 1sec \
--debug \
--min-gas-price 0"

export COMMIT_INTERVAL=${COMMIT_INTERVAL:-30}
export COMMITTER_PRIVATE_KEY=${COMMITTER_PRIVATE_KEY:-0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d}
pm2 --name committer start "/root/fuel-block-committer \
--host 0.0.0.0 \
--port 8888 \
--ethereum-chain anvil \
--ethereum-rpc ws://localhost:8545 \
--ethereum-wallet-key $COMMITTER_PRIVATE_KEY \
--state-contract-address $STATE_ADDRESS \
--commit-interval $COMMIT_INTERVAL"

#### L2 BRIDGE DEPLOYMENT
export L2_BRIDGE_DEPLOYER=${L2_BRIDGE_DEPLOYER:-0xde97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c}
export ASSET_ISSUER_ID=$(cd /fuel-bridge/packages/test-utils \
&& L1_TOKEN_GATEWAY=$GATEWAY_ADDRESS \
L2_SIGNER=$L2_BRIDGE_DEPLOYER \
L2_RPC=http://localhost:4000/v1/graphql \
pnpm deploy:bridge 2>&1 | grep "Proxy at" | awk '{print $3}')

echo "Asset issuer ID is at $ASSET_ISSUER_ID"

cd /fuel-bridge/packages/solidity-contracts \
&& npx hardhat deploy --network localhost --tags set_asset_issuer_id,all \
&& cd -

#### HTTP SERVER FOR BACKWARDS COMPAT
pm2 --name deployments start "pnpm run serve-deployments" --cwd /fuel-bridge/packages/solidity-contracts

#### Attach to logs
pm2 logs
2 changes: 1 addition & 1 deletion docker/l1-chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ====== Build Image ======
FROM node:18-alpine AS BUILD_IMAGE
FROM node:20-alpine AS BUILD_IMAGE

ARG L1_IP=0.0.0.0
ARG L1_PORT=9545
Expand Down
28 changes: 19 additions & 9 deletions packages/integration-tests/tests/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type { Signer } from 'ethers';
import { Address, BN } from 'fuels';
import type {
AbstractAddress,
Contract,
WalletUnlocked as FuelWallet,
MessageProof,
} from 'fuels';
Expand Down Expand Up @@ -65,6 +64,7 @@ describe('Bridging ERC20 tokens', async function () {
fuel_bridgeImpl = implementation;

fuel_bridgeContractId = fuel_bridge.id.toHexString();

await env.eth.fuelERC20Gateway.setAssetIssuerId(fuel_bridgeContractId);
fuel_testAssetId = getTokenId(fuel_bridge, eth_testTokenAddress);

Expand All @@ -84,11 +84,17 @@ describe('Bridging ERC20 tokens', async function () {

// mint tokens as starting balances

await eth_testToken.mint(await env.eth.deployer.getAddress(), 10_000);
await eth_testToken
.mint(await env.eth.deployer.getAddress(), 10_000)
.then((tx) => tx.wait());

await eth_testToken.mint(await env.eth.signers[0].getAddress(), 10_000);
await eth_testToken
.mint(await env.eth.signers[0].getAddress(), 10_000)
.then((tx) => tx.wait());

await eth_testToken.mint(await env.eth.signers[1].getAddress(), 10_000);
await eth_testToken
.mint(await env.eth.signers[1].getAddress(), 10_000)
.then((tx) => tx.wait());
});

describe('Bridge ERC20 to Fuel', async () => {
Expand All @@ -105,7 +111,10 @@ describe('Bridging ERC20 tokens', async function () {
before(async () => {
ethereumTokenSender = env.eth.signers[0];
ethereumTokenSenderAddress = await ethereumTokenSender.getAddress();
await eth_testToken.mint(ethereumTokenSenderAddress, NUM_TOKENS);

await eth_testToken
.mint(ethereumTokenSenderAddress, NUM_TOKENS)
.then((tx) => tx.wait());

ethereumTokenSenderBalance = await eth_testToken.balanceOf(
ethereumTokenSenderAddress
Expand All @@ -121,14 +130,15 @@ describe('Bridging ERC20 tokens', async function () {
// approve FuelERC20Gateway to spend the tokens
await eth_testToken
.connect(ethereumTokenSender)
.approve(eth_erc20GatewayAddress, NUM_TOKENS);
.approve(eth_erc20GatewayAddress, NUM_TOKENS)
.then((tx) => tx.wait());

// use the FuelERC20Gateway to deposit test tokens and receive equivalent tokens on Fuel
const tx = await env.eth.fuelERC20Gateway
const receipt = await env.eth.fuelERC20Gateway
.connect(ethereumTokenSender)
.deposit(fuelTokenReceiverAddress, eth_testTokenAddress, NUM_TOKENS);
.deposit(fuelTokenReceiverAddress, eth_testTokenAddress, NUM_TOKENS)
.then((tx) => tx.wait());

const receipt = await tx.wait();
expect(receipt.status).to.equal(1);

// parse events from logs
Expand Down
2 changes: 0 additions & 2 deletions packages/solidity-contracts/deploy/hardhat/001.chain_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
abi: [...FuelChainState.abi],
implementation,
});

return true;
};

func.tags = ['state', 'chain-state', 'chain_state', 'FuelChainState'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
abi: [],
implementation,
});

return true;
};

func.tags = ['portal', 'message_portal', 'FuelMessagePortal'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
abi: [...FuelERC20Gateway.abi],
implementation,
});

return true;
};

func.tags = ['erc20', 'erc20_gateway', 'FuelERC20GatewayV4'];
Expand Down
2 changes: 0 additions & 2 deletions packages/solidity-contracts/deploy/hardhat/004.token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const [deployer] = await ethers.getSigners();

await deploy('Token', { from: deployer.address, log: true });

return true;
};

func.tags = ['token'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
.then((tx) => tx.wait());

console.log('Granted role COMMITTER_ROLE to', COMMITTER_ADDRESS);

return true;
};

func.tags = ['register_committer'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
abi: [],
implementation,
});

return true;
};

func.tags = ['erc721', 'erc721_gateway', 'FuelERC721GatewayV2'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { DeployFunction } from 'hardhat-deploy/dist/types';
// public addr: `0x6b63804cfbf9856e68e5b6e7aef238dc8311ec55bec04df774003a2c96e0418e`
// private key: `0xde97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c`
const ASSET_ISSUER_ID =
process.env.ASSET_ISSUER_ID ||
'0x5434af870bc7f3b589719c737a82c67c8a562bea28bba0db82e7a22a8a1f7e87';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand All @@ -24,7 +25,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
ASSET_ISSUER_ID
);

return true;
await deployments.save('FuelL2BridgeId', {
address: ASSET_ISSUER_ID,
abi: [],
});
};

func.tags = ['set_asset_issuer_id'];
Expand Down
Loading

0 comments on commit c978d08

Please sign in to comment.