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

test: clean canary env & fixes #2880

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const [TokenPortalAbi, TokenPortalBytecode] =

#include_code deployL1Contract /yarn-project/ethereum/src/deploy_l1_contracts.ts typescript raw

#include_code deployAndInitializeTokenAndBridgeContracts /yarn-project/end-to-end/src/fixtures/utils.ts typescript raw
#include_code deployAndInitializeTokenAndBridgeContracts /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts typescript raw

#include_code delay /yarn-project/end-to-end/src/fixtures/utils.ts typescript raw
```
Expand All @@ -77,7 +77,7 @@ Now let's create another util file to can handle interaction with these contract

In `cross_chain_test_harness.ts`, add:

#include_code cross_chain_test_harness /yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts typescript
#include_code cross_chain_test_harness /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts typescript

This is a class that holds all contracts as objects and exposes easy to use helper methods to interact with our contracts.

Expand All @@ -90,7 +90,7 @@ import { expect, jest} from '@jest/globals'
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, getSandboxAccountsWallets, waitForSandbox } from '@aztec/aztec.js';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';

import { CrossChainTestHarness } from './fixtures/cross_chain_test_harness.js';
import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';
import { delay } from './fixtures/utils.js';
import { mnemonicToAccount } from 'viem/accounts';
import { createPublicClient, createWalletClient, http } from 'viem';
Expand Down
11 changes: 6 additions & 5 deletions docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export FORK_URL=<YOUR_RPC_URL e.g. https://mainnet.infura.io/v3/API_KEY>
```

Now rerun the sandbox:

```sh
/bin/sh -c "$(curl -fsSL 'https://sandbox.aztec.network')"
```
Expand Down Expand Up @@ -94,7 +95,7 @@ import {
parseEther,
} from "viem";
import { foundry } from "viem/chains";
import { CrossChainTestHarness } from "./fixtures/cross_chain_test_harness.js";
import { CrossChainTestHarness } from "./shared/cross_chain_test_harness.js";
import { UniswapContract } from "./fixtures/Uniswap.js";
import { beforeAll, expect, jest } from "@jest/globals";
import {
Expand All @@ -113,18 +114,18 @@ const MNEMONIC = "test test test test test test test test test test test junk";
const hdAccount = mnemonicToAccount(MNEMONIC);
const expectedForkBlockNumber = 17514288;

#include_code uniswap_l1_l2_test_setup_const yarn-project/end-to-end/src/canary/uniswap_l1_l2.ts typescript raw
#include_code uniswap_l1_l2_test_setup_const yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript raw
#include_code uniswap_setup yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts typescript raw
#include_code uniswap_l1_l2_test_beforeAll yarn-project/end-to-end/src/canary/uniswap_l1_l2.ts typescript raw
#include_code uniswap_l1_l2_test_beforeAll yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript raw
```

## Private flow test

#include_code uniswap_private yarn-project/end-to-end/src/canary/uniswap_l1_l2.ts typescript
#include_code uniswap_private yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript

## Public flow test

#include_code uniswap_public yarn-project/end-to-end/src/canary/uniswap_l1_l2.ts typescript
#include_code uniswap_public yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript

## Running the test

Expand Down
3 changes: 3 additions & 0 deletions yarn-project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ RUN rm -rf noir-contracts/target
# Build the entire project.
RUN yarn tsc -b

# Build aztec.js web artifact
RUN cd /usr/src/yarn-project/aztec.js && yarn build:web

FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base
COPY --from=builder /usr/src/yarn-project /usr/src/yarn-project

Expand Down
17 changes: 13 additions & 4 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@ export * from './wallet/index.js';
// here once the issue is resolved.
export { AztecAddress, EthAddress, Point, Fr, FunctionSelector, GrumpkinScalar } from '@aztec/circuits.js';
export {
PXE,
ContractData,
ExtendedContractData as ExtendedContractData,
DeployedContract,
ExtendedContractData as ExtendedContractData,
FunctionCall,
GrumpkinPrivateKey,
L2BlockL2Logs,
LogFilter,
UnencryptedL2Log,
NodeInfo,
NotePreimage,
PackedArguments,
PublicKey,
GrumpkinPrivateKey,
PXE,
SyncStatus,
Tx,
TxExecutionRequest,
TxHash,
TxReceipt,
TxStatus,
UnencryptedL2Log,
emptyFunctionCall,
} from '@aztec/types';

export { createDebugLogger, DebugLogger } from '@aztec/foundation/log';
export { fileURLToPath } from '@aztec/foundation/url';
export { sleep } from '@aztec/foundation/sleep';
export { retry, retryUntil } from '@aztec/foundation/retry';
export * from '@aztec/foundation/crypto';

export {
deployL1Contract,
deployL1Contracts,
DeployL1Contracts,
L1ContractArtifactsForDeployment,
} from '@aztec/ethereum';
41 changes: 21 additions & 20 deletions yarn-project/canary/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS builder
ARG COMMIT_TAG="."
FROM node:18-alpine AS builder

RUN apk update && apk add --no-cache bash jq curl

COPY ./end-to-end /usr/src/end-to-end
COPY ./canary /usr/src/canary

# Setup & Build end-to-end package
WORKDIR /usr/src/yarn-project/end-to-end
WORKDIR /usr/src/end-to-end
# Extract canary @aztec dependencies
RUN ../canary/scripts/extract_packages.sh ../canary/package.json > ./target_pkgs.txt
# Update end-to-end dependencies with target version
RUN ./scripts/setup_canary.sh "$COMMIT_TAG" ./target_pkgs.txt
RUN ./scripts/setup_canary.sh ./target_pkgs.txt package.json
RUN rm ./target_pkgs.txt
# yarn install & build to apply changes (canary packages)
RUN yarn && yarn build

# Build canary package
WORKDIR /usr/src/yarn-project/canary
RUN ./scripts/update_packages.sh "$COMMIT_TAG"
# Install & build canary packages
WORKDIR /usr/src/canary
RUN ./scripts/update_packages.sh canary ../end-to-end/
RUN yarn && yarn build

FROM node:18-alpine
RUN apk update && apk add --no-cache udev ttf-freefont chromium curl jq bash
ENV CHROME_BIN="/usr/bin/chromium-browser" PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

COPY --from=builder /usr/src/ /usr/src/
WORKDIR /usr/src/yarn-project/canary

RUN apk update && apk add --no-cache udev ttf-freefont chromium curl jq bash
RUN apk update && apk add --no-cache udev ttf-freefont chromium bash
ENV CHROME_BIN="/usr/bin/chromium-browser" PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

# Copy web artifacts for browser test
WORKDIR /usr/src/yarn-project/aztec.js
RUN yarn build:web
WORKDIR /usr/src/yarn-project/canary
COPY --from=builder /usr/src/end-to-end /usr/src/end-to-end
COPY --from=builder /usr/src/canary /usr/src/canary

WORKDIR /usr/src/canary
# Copy browser script
RUN cp ../end-to-end/scripts/start_e2e_ci_browser.sh ./scripts/start_e2e_ci_browser.sh
RUN chmod +x scripts/start_e2e_ci_browser.sh

RUN cp ../aztec.js/dest/main.js src/web/
RUN cp ../circuits.js/resources/aztec3-circuits.wasm src/web/
RUN cp ./node_modules/@aztec/circuits.js/resources/aztec3-circuits.wasm src/web/
RUN cp ./node_modules/@aztec/aztec.js/dest/main.js src/web/

ENTRYPOINT ["yarn", "test"]
4 changes: 4 additions & 0 deletions yarn-project/canary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
},
"dependencies": {
"@aztec/aztec.js": "workspace:^",
"@aztec/cli": "workspace:^",
"@aztec/end-to-end": "workspace:^",
"@aztec/ethereum": "workspace:^",
"@aztec/l1-artifacts": "workspace:^",
"@aztec/noir-contracts": "workspace:^",
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/koa-static": "^4.0.2",
Expand Down
6 changes: 6 additions & 0 deletions yarn-project/canary/scripts/update_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -eu

DIST_TAG=$1
E2E_DIR=$2

if [ -z "$DIST_TAG" ]; then
echo "No dist tag provided."
Expand All @@ -11,8 +12,13 @@ fi
echo "Updating Aztec dependencies to tag $DIST_TAG"

TMP=$(mktemp)
# Update NPM dependencies to dist tag
for PKG in $(jq --raw-output ".dependencies | keys[] | select(contains(\"@aztec/\") and (. != \"@aztec/end-to-end\"))" package.json); do
jq --arg v $DIST_TAG ".dependencies[\"$PKG\"] = \$v" package.json >$TMP && mv $TMP package.json
done

# Update end-to-end to local dependency
TMP=$(mktemp)
jq --arg dir "file:$E2E_DIR" '.dependencies["@aztec/end-to-end"] = $dir' package.json >$TMP && mv $TMP package.json

jq ".references = []" tsconfig.json >$TMP && mv $TMP tsconfig.json
12 changes: 12 additions & 0 deletions yarn-project/canary/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@
{
"path": "../aztec.js"
},
{
"path": "../cli"
},
{
"path": "../end-to-end"
},
{
"path": "../ethereum"
},
{
"path": "../l1-artifacts"
},
{
"path": "../noir-contracts"
}
],
"include": ["src"]
Expand Down
15 changes: 10 additions & 5 deletions yarn-project/end-to-end/scripts/setup_canary.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
set -eu

DIST_TAG=$1
TARGET_PKGS_FILE=$2
TARGET_PKGS_FILE=$1

DIST_TAG=canary

# Check if file exists and read it into an array
if [ -f "$TARGET_PKGS_FILE" ]; then
Expand All @@ -26,14 +27,14 @@ cd "$TARGET_DIR"

# Loop through all files and folders in the directory
for item in $(ls -A); do
if [[ "$item" != "index.ts" && "$item" != "canary" ]]; then
if [[ "$item" != "index.ts" && "$item" != "shared" ]]; then
# Remove the item (either file or folder)
rm -rf "$item"
fi
done
cd ..

echo "Updating external Aztec dependencies to tag $DIST_TAG"
echo "Updating external Aztec dependencies to tag '$DIST_TAG'"
JSON_TARGET_PKGS=$(printf '%s\n' "${TARGET_PKGS[@]}" | jq -R -s -c 'split("\n") | map(select(. != ""))')

TMP=$(mktemp)
Expand All @@ -54,4 +55,8 @@ jq --arg v $DIST_TAG --argjson target_pkgs "$JSON_TARGET_PKGS" '
end
)' package.json >$TMP && mv $TMP package.json

jq ".references = []" tsconfig.json >$TMP && mv $TMP tsconfig.json
echo "Updating end-to-end tsconfig.json"
TMP=$(mktemp)
# Copy canary's tsconfig.json
cp ../canary/tsconfig.json tsconfig.json
jq 'del(.references)' tsconfig.json >$TMP && mv $TMP tsconfig.json
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Koa from 'koa';
import serve from 'koa-static';
import path, { dirname } from 'path';

import { browserTestSuite } from './canary/browser.js';
import { browserTestSuite } from './shared/browser.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { startHttpRpcServer } from '@aztec/aztec-sandbox';
import { PXE, createDebugLogger } from '@aztec/aztec.js';
import { createPXERpcServer } from '@aztec/pxe';

import { cliTestSuite } from './canary/cli.js';
import { setup as e2eSetup } from './fixtures/utils.js';
import { cliTestSuite } from './shared/cli.js';

const HTTP_PORT = 9009;
const RPC_URL = `http://localhost:${HTTP_PORT}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
} from '@aztec/aztec.js';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';

import { CrossChainTestHarness } from './fixtures/cross_chain_test_harness.js';
import { delay, setup } from './fixtures/utils.js';
import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';

describe('e2e_cross_chain_messaging', () => {
let logger: DebugLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { DebugLogger } from '@aztec/foundation/log';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';
import { TxStatus } from '@aztec/types';

import { CrossChainTestHarness } from './fixtures/cross_chain_test_harness.js';
import { delay, setup } from './fixtures/utils.js';
import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';

describe('e2e_public_cross_chain_messaging', () => {
let logger: DebugLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AztecAddress } from '@aztec/aztec.js';
import { EthAddress } from '@aztec/circuits.js';
import { DebugLogger } from '@aztec/foundation/log';

import { CrossChainTestHarness } from './fixtures/cross_chain_test_harness.js';
import { delay, setup } from './fixtures/utils.js';
import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';

describe('e2e_public_to_private_messaging', () => {
let logger: DebugLogger;
Expand Down
Loading