Skip to content

Commit

Permalink
feat: devnet smoke test (#7629)
Browse files Browse the repository at this point in the history
simple smoke test for devnet

Fix #7569
  • Loading branch information
alexghr authored Jul 30, 2024
1 parent a063d51 commit 54ed386
Show file tree
Hide file tree
Showing 15 changed files with 591 additions and 57 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/devnet-deploys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: "${{ env.GIT_COMMIT }}"
fetch-depth: 0
- uses: ./.github/ci-setup-action
- uses: hashicorp/setup-terraform@v3
with:
Expand Down Expand Up @@ -209,7 +208,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: "${{ env.GIT_COMMIT }}"
fetch-depth: 0

- uses: ./.github/ci-setup-action

Expand Down Expand Up @@ -256,7 +254,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: "${{ env.GIT_COMMIT }}"
fetch-depth: 0
- uses: ./.github/ci-setup-action
- uses: hashicorp/setup-terraform@v3
with:
Expand Down Expand Up @@ -291,7 +288,6 @@ jobs:
- uses: actions/checkout@v4
with:
ref: "${{ env.GIT_COMMIT }}"
fetch-depth: 0
- uses: ./.github/ci-setup-action
- uses: hashicorp/setup-terraform@v3
with:
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/devnet-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run devnet smoke tests
on:
workflow_dispatch:
workflow_run:
workflows:
- Deploy to devnet
types:
# triggered even if the workflow fails
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
GIT_COMMIT: devnet
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AZTEC_NODE_URL: https://api.aztec.network/devnet/aztec-node-1/{{ secrets.FORK_API_KEY }}
FAUCET_URL: https://api.aztec.network/devnet/aztec-faucet/{{ secrets.FORK_API_KEY }}
ETHEREUM_HOST: https://devnet-mainnet-fork.aztec.network:8545/${{ secrets.FORK_API_KEY }}

jobs:
setup:
uses: ./.github/workflows/setup-runner.yml
with:
username: ${{ github.event.pull_request.user.login || github.actor }}
runner_type: builder-x86
secrets: inherit
if: ${{ github.event.workflow_run.conclusion == 'success' }}

build:
needs: setup
runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86
outputs:
e2e_list: ${{ steps.e2e_list.outputs.list }}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
with:
ref: "${{ env.GIT_COMMIT }}"

- uses: ./.github/ci-setup-action
with:
concurrency_key: build-test-artifacts-${{ github.actor }}

- name: "Build E2E Image"
timeout-minutes: 40
run: |
earthly-ci ./yarn-project+export-e2e-test-images
- name: Create list of devnet end-to-end jobs
id: e2e_list
run: echo "list=$(earthly ls ./yarn-project/end-to-end | grep 'devnet' | sed 's/+//' | jq -R . | jq -cs .)" >> $GITHUB_OUTPUT

e2e:
needs: build
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
test: ${{ fromJson( needs.build.outputs.e2e_list )}}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
with: { ref: "${{ env.GIT_COMMIT }}" }
- uses: ./.github/ci-setup-action
- name: Setup and Test
timeout-minutes: 40
uses: ./.github/ensure-tester-with-images
with:
# big machine since we're doing proving
runner_type: "64core-tester-x86"
builder_type: builder-x86
# these are copied to the tester and expected by the earthly command below
# if they fail to copy, it will try to build them on the tester and fail
builder_images_to_copy: aztecprotocol/end-to-end:${{ env.GIT_COMMIT }}
# command to produce the images in case they don't exist
builder_command: scripts/earthly-ci ./yarn-project+export-e2e-test-images
run: |
set -eux
cd ./yarn-project/end-to-end/
export FORCE_COLOR=1
../../scripts/earthly-ci -P --no-output +${{ matrix.test }}
28 changes: 23 additions & 5 deletions yarn-project/cli/src/cmds/devnet/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { type EthAddress } from '@aztec/circuits.js';
import { type LogFn } from '@aztec/foundation/log';

export async function dripFaucet(faucetUrl: string, asset: string, account: EthAddress, log: LogFn): Promise<void> {
import { prettyPrintJSON } from '../../utils/commands.js';

export async function dripFaucet(
faucetUrl: string,
asset: string,
account: EthAddress,
json: boolean,
log: LogFn,
): Promise<void> {
const url = new URL(`${faucetUrl}/drip/${account.toString()}`);
url.searchParams.set('asset', asset);
const res = await fetch(url);
if (res.status === 200) {
log(`Dripped ${asset} for ${account.toString()}`);
} else if (res.status === 429) {
log(`Rate limited when dripping ${asset} for ${account.toString()}`);
if (json) {
log(prettyPrintJSON({ ok: true }));
} else {
log(`Dripped ${asset} for ${account.toString()}`);
}
} else {
log(`Failed to drip ${asset} for ${account.toString()}`);
if (json) {
log(prettyPrintJSON({ ok: false }));
} else if (res.status === 429) {
log(`Rate limited when dripping ${asset} for ${account.toString()}`);
} else {
log(`Failed to drip ${asset} for ${account.toString()}`);
}

process.exit(1);
}
}
3 changes: 2 additions & 1 deletion yarn-project/cli/src/cmds/devnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
.requiredOption('-u, --faucet-url <string>', 'Url of the faucet', 'http://localhost:8082')
.requiredOption('-t, --token <string>', 'The asset to drip', 'eth')
.requiredOption('-a, --address <string>', 'The Ethereum address to drip to', parseEthereumAddress)
.option('--json', 'Output the result as JSON')
.action(async options => {
const { dripFaucet } = await import('./faucet.js');
await dripFaucet(options.faucetUrl, options.token, options.address, log);
await dripFaucet(options.faucetUrl, options.token, options.address, options.json, log);
});

return program;
Expand Down
21 changes: 16 additions & 5 deletions yarn-project/cli/src/cmds/l1/bridge_erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

import { ERC20PortalManager } from '../../portal_manager.js';
import { prettyPrintJSON } from '../../utils/commands.js';

export async function bridgeERC20(
amount: bigint,
Expand All @@ -14,6 +15,7 @@ export async function bridgeERC20(
tokenAddress: EthAddress,
portalAddress: EthAddress,
mint: boolean,
json: boolean,
log: LogFn,
debugLogger: DebugLogger,
) {
Expand All @@ -25,11 +27,20 @@ export async function bridgeERC20(
const portal = await ERC20PortalManager.create(tokenAddress, portalAddress, publicClient, walletClient, debugLogger);
const { secret } = await portal.prepareTokensOnL1(amount, amount, recipient, mint);

if (mint) {
log(`Minted ${amount} tokens on L1 and pushed to L2 portal`);
if (json) {
log(
prettyPrintJSON({
claimAmount: amount,
claimSecret: secret,
}),
);
} else {
log(`Bridged ${amount} tokens to L2 portal`);
if (mint) {
log(`Minted ${amount} tokens on L1 and pushed to L2 portal`);
} else {
log(`Bridged ${amount} tokens to L2 portal`);
}
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
}
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
}
23 changes: 19 additions & 4 deletions yarn-project/cli/src/cmds/l1/bridge_fee_juice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

import { createCompatibleClient } from '../../client.js';
import { FeeJuicePortalManager } from '../../portal_manager.js';
import { prettyPrintJSON } from '../../utils/commands.js';

export async function bridgeL1Gas(
amount: bigint,
recipient: AztecAddress,
rpcUrl: string,
l1RpcUrl: string,
chainId: number,
privateKey: string | undefined,
mnemonic: string,
mint: boolean,
json: boolean,
log: LogFn,
debugLogger: DebugLogger,
) {
// Prepare L1 client
const chain = createEthereumChain(l1RpcUrl, chainId);
const { publicClient, walletClient } = createL1Clients(chain.rpcUrl, mnemonic, chain.chainInfo);
const { publicClient, walletClient } = createL1Clients(chain.rpcUrl, privateKey ?? mnemonic, chain.chainInfo);

// Prepare L2 client
const client = await createCompatibleClient(rpcUrl, debugLogger);
Expand All @@ -27,7 +30,19 @@ export async function bridgeL1Gas(
const portal = await FeeJuicePortalManager.create(client, publicClient, walletClient, debugLogger);
const { secret } = await portal.prepareTokensOnL1(amount, amount, recipient, mint);

log(`Minted ${amount} gas tokens on L1 and pushed to L2 portal`);
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
if (json) {
const out = {
claimAmount: amount,
claimSecret: secret,
};
log(prettyPrintJSON(out));
} else {
if (mint) {
log(`Minted ${amount} fee juice on L1 and pushed to L2 portal`);
} else {
log(`Bridged ${amount} fee juice to L2 portal`);
}
log(`claimAmount=${amount},claimSecret=${secret}\n`);
log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
}
}
9 changes: 2 additions & 7 deletions yarn-project/cli/src/cmds/l1/create_l1_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import { type LogFn } from '@aztec/foundation/log';

import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';

import { stringify } from '../../utils/commands.js';
import { prettyPrintJSON } from '../../utils/commands.js';

export function createL1Account(json: boolean, log: LogFn) {
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(privateKey);

if (json) {
log(
stringify({
privateKey,
address: account.address,
}),
);
log(prettyPrintJSON({ privateKey, address: account.address }));
} else {
log(`Private Key: ${privateKey}`);
log(`Address: ${account.address}`);
Expand Down
36 changes: 28 additions & 8 deletions yarn-project/cli/src/cmds/l1/get_l1_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,37 @@ import { PortalERC20Abi } from '@aztec/l1-artifacts';

import { createPublicClient, getContract, http } from 'viem';

export async function getL1Balance(who: EthAddress, token: EthAddress, l1RpcUrl: string, chainId: number, log: LogFn) {
import { prettyPrintJSON } from '../../utils/commands.js';

export async function getL1Balance(
who: EthAddress,
token: EthAddress | undefined,
l1RpcUrl: string,
chainId: number,
json: boolean,
log: LogFn,
) {
const chain = createEthereumChain(l1RpcUrl, chainId);
const publicClient = createPublicClient({ chain: chain.chainInfo, transport: http(chain.rpcUrl) });

const gasL1 = getContract({
address: token.toString(),
abi: PortalERC20Abi,
client: publicClient,
});
let balance = 0n;
if (token) {
const gasL1 = getContract({
address: token.toString(),
abi: PortalERC20Abi,
client: publicClient,
});

const balance = await gasL1.read.balanceOf([who.toString()]);
balance = await gasL1.read.balanceOf([who.toString()]);
} else {
balance = await publicClient.getBalance({
address: who.toString(),
});
}

log(`L1 gas token balance of ${who.toString()} is ${balance.toString()}`);
if (json) {
log(prettyPrintJSON({ balance }));
} else {
log(`L1 balance of ${who.toString()} is ${balance.toString()}`);
}
}
15 changes: 11 additions & 4 deletions yarn-project/cli/src/cmds/l1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
'test test test test test test test test test test test junk',
)
.option('--mint', 'Mint the tokens on L1', false)
.option('--l1-private-key <string>', 'The private key to the eth account bridging', PRIVATE_KEY)
.addOption(pxeOption)
.addOption(l1ChainIdOption)
.option('--json', 'Output the claim in JSON format')
.action(async (amount, recipient, options) => {
const { bridgeL1Gas } = await import('./bridge_fee_juice.js');
await bridgeL1Gas(
Expand All @@ -111,8 +113,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
options.rpcUrl,
options.l1RpcUrl,
options.l1ChainId,
options.l1PrivateKey,
options.mnemonic,
options.mint,
options.json,
log,
debugLogger,
);
Expand All @@ -137,19 +141,21 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
.addOption(l1ChainIdOption)
.requiredOption('-t, --token <string>', 'The address of the token to bridge', parseEthereumAddress)
.requiredOption('-p, --portal <string>', 'The address of the portal contract', parseEthereumAddress)
.option('-k, --private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option('--l1-private-key <string>', 'The private key to use for deployment', PRIVATE_KEY)
.option('--json', 'Output the claim in JSON format')
.action(async (amount, recipient, options) => {
const { bridgeERC20 } = await import('./bridge_erc20.js');
await bridgeERC20(
amount,
recipient,
options.l1RpcUrl,
options.l1ChainId,
options.privateKey,
options.l1PrivateKey,
options.mnemonic,
options.token,
options.portal,
options.mint,
options.json,
log,
debugLogger,
);
Expand All @@ -172,11 +178,12 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
'Url of the ethereum host. Chain identifiers localhost and testnet can be used',
ETHEREUM_HOST,
)
.requiredOption('-t, --token <string>', 'The address of the token to check the balance of', parseEthereumAddress)
.option('-t, --token <string>', 'The address of the token to check the balance of', parseEthereumAddress)
.addOption(l1ChainIdOption)
.option('--json', 'Output the balance in JSON format')
.action(async (who, options) => {
const { getL1Balance } = await import('./get_l1_balance.js');
await getL1Balance(who, options.token, options.l1RpcUrl, options.l1ChainId, log);
await getL1Balance(who, options.token, options.l1RpcUrl, options.l1ChainId, options.json, log);
});

return program;
Expand Down
Loading

0 comments on commit 54ed386

Please sign in to comment.