From 68ff09bb35d78fb49621d0511e9cbcb51a9058f5 Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 10:00:24 +0000 Subject: [PATCH 01/10] WIP refactoring canary tests to re-use e2e code --- build_manifest.json | 218 ++++++++++--- circuits/cpp/CMakePresets.json | 2 +- yarn-project/canary/Dockerfile | 10 +- yarn-project/canary/package.json | 1 - .../canary/scripts/update_packages.sh | 10 +- yarn-project/canary/tsconfig.json | 3 - yarn-project/end-to-end/src/e2e_cli.test.ts | 301 +++++++++--------- yarn-project/yarn.lock | 1 - 8 files changed, 334 insertions(+), 212 deletions(-) diff --git a/build_manifest.json b/build_manifest.json index 06f6299b0bb..6a626547159 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -41,20 +41,32 @@ }, "bb.js": { "buildDir": "circuits/cpp/barretenberg/ts", - "rebuildPatterns": ["^circuits/cpp/barretenberg/ts/"], - "dependencies": ["barretenberg-wasm-linux-clang"] + "rebuildPatterns": [ + "^circuits/cpp/barretenberg/ts/" + ], + "dependencies": [ + "barretenberg-wasm-linux-clang" + ] }, "barretenberg-acir-tests-bb": { "buildDir": "circuits/cpp/barretenberg/acir_tests", "dockerfile": "Dockerfile.bb", - "rebuildPatterns": ["^circuits/cpp/barretenberg/acir_tests/"], - "dependencies": ["barretenberg-x86_64-linux-clang-assert"] + "rebuildPatterns": [ + "^circuits/cpp/barretenberg/acir_tests/" + ], + "dependencies": [ + "barretenberg-x86_64-linux-clang-assert" + ] }, "barretenberg-acir-tests-bb.js": { "buildDir": "circuits/cpp/barretenberg/acir_tests", "dockerfile": "Dockerfile.bb.js", - "rebuildPatterns": ["^circuits/cpp/barretenberg/acir_tests/"], - "dependencies": ["bb.js"] + "rebuildPatterns": [ + "^circuits/cpp/barretenberg/acir_tests/" + ], + "dependencies": [ + "bb.js" + ] }, "circuits-wasm-linux-clang": { "buildDir": "circuits/cpp", @@ -107,20 +119,29 @@ "docs": { "buildDir": ".", "dockerfile": "docs/Dockerfile", - "rebuildPatterns": ["^docs/", "^.*.cpp$", "^.*.ts$"], + "rebuildPatterns": [ + "^docs/", + "^.*.cpp$", + "^.*.ts$" + ], "dependencies": [] }, "l1-contracts": { "buildDir": "l1-contracts", "dockerfile": "Dockerfile", - "rebuildPatterns": ["^l1-contracts/"], + "rebuildPatterns": [ + "^l1-contracts/" + ], "dependencies": [] }, "l1-artifacts": { "buildDir": "yarn-project", "projectDir": "yarn-project/l1-artifacts", "dockerfile": "l1-artifacts/Dockerfile", - "rebuildPatterns": ["^l1-contracts/", "^yarn-project/l1-artifacts/"], + "rebuildPatterns": [ + "^l1-contracts/", + "^yarn-project/l1-artifacts/" + ], "dependencies": [] }, "yarn-project-base": { @@ -136,13 +157,18 @@ "^yarn-project/yarn-project-base/", "^yarn-project/yarn.lock" ], - "dependencies": ["circuits-wasm-linux-clang", "l1-contracts"] + "dependencies": [ + "circuits-wasm-linux-clang", + "l1-contracts" + ] }, "acir-simulator": { "buildDir": "yarn-project", "projectDir": "yarn-project/acir-simulator", "dockerfile": "acir-simulator/Dockerfile", - "rebuildPatterns": ["^yarn-project/acir-simulator/"], + "rebuildPatterns": [ + "^yarn-project/acir-simulator/" + ], "dependencies": [ "circuits.js", "foundation", @@ -155,7 +181,9 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/archiver", "dockerfile": "archiver/Dockerfile", - "rebuildPatterns": ["^yarn-project/archiver/"], + "rebuildPatterns": [ + "^yarn-project/archiver/" + ], "dependencies": [ "circuits.js", "ethereum", @@ -168,7 +196,9 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/cli", "dockerfile": "cli/Dockerfile", - "rebuildPatterns": ["^yarn-project/cli/"], + "rebuildPatterns": [ + "^yarn-project/cli/" + ], "dependencies": [ "aztec.js", "ethereum", @@ -182,7 +212,9 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/aztec-rpc", "dockerfile": "aztec-rpc/Dockerfile", - "rebuildPatterns": ["^yarn-project/aztec-rpc/"], + "rebuildPatterns": [ + "^yarn-project/aztec-rpc/" + ], "dependencies": [ "acir-simulator", "circuits.js", @@ -195,7 +227,9 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/aztec-sandbox", "dockerfile": "aztec-sandbox/Dockerfile", - "rebuildPatterns": ["^yarn-project/aztec-sandbox/"], + "rebuildPatterns": [ + "^yarn-project/aztec-sandbox/" + ], "dependencies": [ "aztec-node", "aztec-rpc", @@ -212,14 +246,22 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/aztec.js", "dockerfile": "aztec.js/Dockerfile", - "rebuildPatterns": ["^yarn-project/aztec.js/"], - "dependencies": ["circuits.js", "foundation", "types"] + "rebuildPatterns": [ + "^yarn-project/aztec.js/" + ], + "dependencies": [ + "circuits.js", + "foundation", + "types" + ] }, "canary-build": { "buildDir": "yarn-project", "projectDir": "yarn-project/canary", "dockerfile": "canary/Dockerfile.build", - "rebuildPatterns": ["^yarn-project/canary/"], + "rebuildPatterns": [ + "^yarn-project/canary/" + ], "dependencies": [ "aztec.js", "l1-artifacts", @@ -231,8 +273,15 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/canary", "dockerfile": "canary/Dockerfile", - "rebuildPatterns": ["^yarn-project/canary/"], - "dependencies": ["aztec.js", "foundation", "l1-artifacts", "noir-contracts"] + "rebuildPatterns": [ + "^yarn-project/canary/" + ], + "dependencies": [ + "aztec.js", + "foundation", + "l1-artifacts", + "noir-contracts" + ] }, "circuits.js": { "buildDir": "yarn-project", @@ -242,13 +291,17 @@ "^circuits/", "^yarn-project/circuits.js/" ], - "dependencies": ["foundation"] + "dependencies": [ + "foundation" + ] }, "end-to-end": { "buildDir": "yarn-project", "projectDir": "yarn-project/end-to-end", "dockerfile": "end-to-end/Dockerfile", - "rebuildPatterns": ["^yarn-project/end-to-end/"], + "rebuildPatterns": [ + "^yarn-project/end-to-end/" + ], "dependencies": [ "archiver", "aztec-node", @@ -271,29 +324,48 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/ethereum", "dockerfile": "ethereum/Dockerfile", - "rebuildPatterns": ["^yarn-project/ethereum/"], - "dependencies": ["foundation", "l1-artifacts"] + "rebuildPatterns": [ + "^yarn-project/ethereum/" + ], + "dependencies": [ + "foundation", + "l1-artifacts" + ] }, "foundation": { "buildDir": "yarn-project", "projectDir": "yarn-project/foundation", "dockerfile": "foundation/Dockerfile", - "rebuildPatterns": ["^yarn-project/foundation/"], + "rebuildPatterns": [ + "^yarn-project/foundation/" + ], "dependencies": [] }, "key-store": { "buildDir": "yarn-project", "projectDir": "yarn-project/key-store", "dockerfile": "key-store/Dockerfile", - "rebuildPatterns": ["^yarn-project/key-store/"], - "dependencies": ["circuits.js", "foundation", "types"] + "rebuildPatterns": [ + "^yarn-project/key-store/" + ], + "dependencies": [ + "circuits.js", + "foundation", + "types" + ] }, "merkle-tree": { "buildDir": "yarn-project", "projectDir": "yarn-project/merkle-tree", "dockerfile": "merkle-tree/Dockerfile", - "rebuildPatterns": ["^yarn-project/merkle-tree/"], - "dependencies": ["circuits.js", "foundation", "types"] + "rebuildPatterns": [ + "^yarn-project/merkle-tree/" + ], + "dependencies": [ + "circuits.js", + "foundation", + "types" + ] }, "noir-contracts-build": { "buildDir": "yarn-project", @@ -303,7 +375,11 @@ "^yarn-project/noir-contracts/", "^yarn-project/noir-libs/" ], - "dependencies": ["aztec.js", "foundation", "noir-compiler"] + "dependencies": [ + "aztec.js", + "foundation", + "noir-compiler" + ] }, "noir-contracts": { "buildDir": "yarn-project", @@ -313,48 +389,80 @@ "^yarn-project/noir-contracts/", "^yarn-project/noir-libs/" ], - "dependencies": ["aztec.js", "foundation", "noir-compiler"] + "dependencies": [ + "aztec.js", + "foundation", + "noir-compiler" + ] }, "noir-compiler": { "buildDir": "yarn-project", "projectDir": "yarn-project/noir-compiler", "dockerfile": "noir-compiler/Dockerfile", - "rebuildPatterns": ["^yarn-project/noir-compiler/"], - "dependencies": ["foundation"] + "rebuildPatterns": [ + "^yarn-project/noir-compiler/" + ], + "dependencies": [ + "foundation" + ] }, "p2p": { "buildDir": "yarn-project", "projectDir": "yarn-project/p2p", "dockerfile": "p2p/Dockerfile", - "rebuildPatterns": ["^yarn-project/p2p/"], - "dependencies": ["circuits.js", "foundation", "types"] + "rebuildPatterns": [ + "^yarn-project/p2p/" + ], + "dependencies": [ + "circuits.js", + "foundation", + "types" + ] }, "p2p-bootstrap": { "buildDir": "yarn-project", "projectDir": "yarn-project/p2p-bootstrap", "dockerfile": "p2p/Dockerfile", - "rebuildPatterns": ["^yarn-project/p2p-bootstrap/"], - "dependencies": ["foundation", "p2p"] + "rebuildPatterns": [ + "^yarn-project/p2p-bootstrap/" + ], + "dependencies": [ + "foundation", + "p2p" + ] }, "prover-client": { "buildDir": "yarn-project", "projectDir": "yarn-project/prover-client", "dockerfile": "prover-client/Dockerfile", - "rebuildPatterns": ["^yarn-project/prover-client/"], - "dependencies": ["foundation"] + "rebuildPatterns": [ + "^yarn-project/prover-client/" + ], + "dependencies": [ + "foundation" + ] }, "rollup-provider": { "buildDir": "yarn-project", "projectDir": "yarn-project/rollup-provider", "dockerfile": "rollup-provider/Dockerfile", - "rebuildPatterns": ["^yarn-project/rollup-provider/"], - "dependencies": ["aztec-node", "circuits.js", "foundation", "types"] + "rebuildPatterns": [ + "^yarn-project/rollup-provider/" + ], + "dependencies": [ + "aztec-node", + "circuits.js", + "foundation", + "types" + ] }, "aztec-node": { "buildDir": "yarn-project", "projectDir": "yarn-project/aztec-node", "dockerfile": "aztec-node/Dockerfile", - "rebuildPatterns": ["^yarn-project/aztec-node/"], + "rebuildPatterns": [ + "^yarn-project/aztec-node/" + ], "dependencies": [ "archiver", "circuits.js", @@ -371,7 +479,9 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/sequencer-client", "dockerfile": "sequencer-client/Dockerfile", - "rebuildPatterns": ["^yarn-project/sequencer-client/"], + "rebuildPatterns": [ + "^yarn-project/sequencer-client/" + ], "dependencies": [ "acir-simulator", "circuits.js", @@ -388,14 +498,26 @@ "buildDir": "yarn-project", "projectDir": "yarn-project/types", "dockerfile": "types/Dockerfile", - "rebuildPatterns": ["^yarn-project/types/"], - "dependencies": ["circuits.js", "foundation"] + "rebuildPatterns": [ + "^yarn-project/types/" + ], + "dependencies": [ + "circuits.js", + "foundation" + ] }, "world-state": { "buildDir": "yarn-project", "projectDir": "yarn-project/world-state", "dockerfile": "world-state/Dockerfile", - "rebuildPatterns": ["^yarn-project/world-state/"], - "dependencies": ["circuits.js", "foundation", "merkle-tree", "types"] + "rebuildPatterns": [ + "^yarn-project/world-state/" + ], + "dependencies": [ + "circuits.js", + "foundation", + "merkle-tree", + "types" + ] } -} +} \ No newline at end of file diff --git a/circuits/cpp/CMakePresets.json b/circuits/cpp/CMakePresets.json index a97a84aa1ae..caea0952106 100644 --- a/circuits/cpp/CMakePresets.json +++ b/circuits/cpp/CMakePresets.json @@ -327,4 +327,4 @@ "inherits": "wasm" } ] -} +} \ No newline at end of file diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index fa9498350af..e30b0776ece 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,12 +1,14 @@ -FROM node:18-alpine +# FROM node:18-alpine +FROM 278380418400.dkr.ecr.us-east-1.amazonaws.com/yarn-project-base AS builder + 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" ARG COMMIT_TAG="" -#Build canary -WORKDIR /usr/src/ -COPY ./canary . +# Build canary with external @aztec deps +COPY . . +WORKDIR /usr/src/yarn-project/canary RUN ./scripts/update_packages.sh $COMMIT_TAG RUN yarn && yarn build diff --git a/yarn-project/canary/package.json b/yarn-project/canary/package.json index adf9534ab60..42e2d372d30 100644 --- a/yarn-project/canary/package.json +++ b/yarn-project/canary/package.json @@ -23,7 +23,6 @@ "dependencies": { "@aztec/aztec.js": "workspace:^", "@aztec/cli": "workspace:^", - "@aztec/foundation": "workspace:^", "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-contracts": "workspace:^", "@jest/globals": "^29.5.0", diff --git a/yarn-project/canary/scripts/update_packages.sh b/yarn-project/canary/scripts/update_packages.sh index 0b5a3c59b43..dac457c7248 100755 --- a/yarn-project/canary/scripts/update_packages.sh +++ b/yarn-project/canary/scripts/update_packages.sh @@ -2,21 +2,21 @@ set -eu COMMIT_TAG=$1 -if [ -z "$COMMIT_TAG" ]; then - echo "No commit tag provided." +if [ -z "$COMMIT_TAG" ]; then + echo "No commit tag provided." exit 0 fi VERSION=$(npx semver $COMMIT_TAG) -if [ -z "$VERSION" ]; then - echo "$COMMIT_TAG is not a semantic version." +if [ -z "$VERSION" ]; then + echo "$COMMIT_TAG is not a semantic version." exit 1 fi echo "Updating Aztec dependencies to version $VERSION" TMP=$(mktemp) -for PKG in $(jq --raw-output ".dependencies | keys[] | select(contains(\"@aztec/\"))" package.json); do +for PKG in $(jq --raw-output ".dependencies | keys[] | select(contains(\"@aztec/\") and (. != \"@aztec/end-to-end\"))" package.json); do jq --arg v $VERSION ".dependencies[\"$PKG\"] = \$v" package.json > $TMP && mv $TMP package.json done diff --git a/yarn-project/canary/tsconfig.json b/yarn-project/canary/tsconfig.json index 3e6bccafeb4..7b22ac6e52c 100644 --- a/yarn-project/canary/tsconfig.json +++ b/yarn-project/canary/tsconfig.json @@ -25,9 +25,6 @@ { "path": "../cli" }, - { - "path": "../foundation" - }, { "path": "../l1-artifacts" }, diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index 451e7f45e2b..04cda3646ba 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -28,7 +28,7 @@ const testSetup = async () => { return aztecRpcServer; }; -const cleanup = async () => { +const testCleanup = async () => { http.close(); await aztecNode?.stop(); await (aztecRpcServer as AztecRPCServer).stop(); @@ -37,158 +37,161 @@ const cleanup = async () => { const INITIAL_BALANCE = 33000; const TRANSFER_BALANCE = 3000; -describe('CLI e2e test', () => { - let cli: ReturnType; - let aztecRpcClient: AztecRPC; - let existingAccounts: CompleteAddress[]; - let contractAddress: AztecAddress; - let log: (...args: any[]) => void; - - // All logs emitted by the cli will be collected here, and reset between tests - const logs: string[] = []; - - beforeAll(async () => { - aztecRpcClient = await testSetup(); - log = (...args: any[]) => { - logs.push(format(...args)); - debug(...args); +export const testSuite = (setup: () => Promise, cleanup: () => Promise) => + describe('CLI e2e test', () => { + let cli: ReturnType; + let aztecRpcClient: AztecRPC; + let existingAccounts: CompleteAddress[]; + let contractAddress: AztecAddress; + let log: (...args: any[]) => void; + + // All logs emitted by the cli will be collected here, and reset between tests + const logs: string[] = []; + + beforeAll(async () => { + aztecRpcClient = await setup(); + log = (...args: any[]) => { + logs.push(format(...args)); + debug(...args); + }; + }); + + afterAll(async () => { + await cleanup(); + }); + + // in order to run the same command twice, we need to create a new CLI instance + const resetCli = () => { + cli = getProgram(log, debug); }; - }); - afterAll(async () => { - await cleanup(); - }); + beforeEach(() => { + logs.splice(0); + resetCli(); + }); + + // Run a command on the CLI + const run = (cmd: string, addRpcUrl = true) => { + const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); + if (addRpcUrl) { + args.push('--rpc-url', RPC_URL); + } + return cli.parseAsync(args); + }; + + // Returns first match across all logs collected so far + const findInLogs = (regex: RegExp) => { + for (const log of logs) { + const match = regex.exec(log); + if (match) return match; + } + }; - // in order to run the same command twice, we need to create a new CLI instance - const resetCli = () => { - cli = getProgram(log, debug); - }; + const findMultipleInLogs = (regex: RegExp) => { + const matches = []; + for (const log of logs) { + const match = regex.exec(log); + if (match) matches.push(match); + } + return matches; + }; - beforeEach(() => { - logs.splice(0); - resetCli(); - }); + const clearLogs = () => { + logs.splice(0); + }; - // Run a command on the CLI - const run = (cmd: string, addRpcUrl = true) => { - const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); - if (addRpcUrl) { - args.push('--rpc-url', RPC_URL); - } - return cli.parseAsync(args); - }; - - // Returns first match across all logs collected so far - const findInLogs = (regex: RegExp) => { - for (const log of logs) { - const match = regex.exec(log); - if (match) return match; - } - }; - - const findMultipleInLogs = (regex: RegExp) => { - const matches = []; - for (const log of logs) { - const match = regex.exec(log); - if (match) matches.push(match); - } - return matches; - }; - - const clearLogs = () => { - logs.splice(0); - }; - - it('creates & retrieves an account', async () => { - existingAccounts = await aztecRpcClient.getAccounts(); - debug('Create an account'); - await run(`create-account`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const newAddress = AztecAddress.fromString(foundAddress!); - - const accountsAfter = await aztecRpcClient.getAccounts(); - const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; - expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); - const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; - - // Test get-accounts - debug('Check that account was added to the list of accs in RPC'); - await run('get-accounts'); - const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); - const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); - expect(foundFetchedAddress).toBeDefined(); - - // Test get-account - debug('Check we can retrieve the specific account'); - clearLogs(); - await run(`get-account ${newAddress.toString()}`); - const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); + it('creates & retrieves an account', async () => { + existingAccounts = await aztecRpcClient.getAccounts(); + debug('Create an account'); + await run(`create-account`); + const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(foundAddress).toBeDefined(); + const newAddress = AztecAddress.fromString(foundAddress!); + + const accountsAfter = await aztecRpcClient.getAccounts(); + const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; + expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); + const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; + + // Test get-accounts + debug('Check that account was added to the list of accs in RPC'); + await run('get-accounts'); + const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); + const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); + expect(foundFetchedAddress).toBeDefined(); + + // Test get-account + debug('Check we can retrieve the specific account'); + clearLogs(); + await run(`get-account ${newAddress.toString()}`); + const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); + }); + + it('deploys a contract & sends transactions', async () => { + // generate a private key + debug('Create an account using a private key'); + await run('generate-private-key', false); + const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; + expect(privKey).toHaveLength(64); + await run(`create-account --private-key ${privKey}`); + const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(foundAddress).toBeDefined(); + const ownerAddress = AztecAddress.fromString(foundAddress!); + + debug('Deploy Private Token Contract using created account.'); + await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); + const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(loggedAddress).toBeDefined(); + contractAddress = AztecAddress.fromString(loggedAddress!); + + const deployedContract = await aztecRpcClient.getContractData(contractAddress); + expect(deployedContract?.contractAddress).toEqual(contractAddress); + + debug('Check contract can be found in returned address'); + await run(`check-deploy -ca ${loggedAddress}`); + const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); + + // clear logs + clearLogs(); + await run(`get-contract-data ${loggedAddress}`); + const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); + + debug("Check owner's balance"); + await run( + `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + ); + const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; + expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); + + debug('Transfer some tokens'); + const existingAccounts = await aztecRpcClient.getAccounts(); + // ensure we pick a different acc + const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); + + await run( + `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, + ); + const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; + + debug('Check the transfer receipt'); + await run(`get-tx-receipt ${txHash}`); + const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; + const parsedResult = JSON.parse(txResult!); + expect(parsedResult.txHash).toEqual(txHash); + expect(parsedResult.status).toEqual('mined'); + debug("Check Receiver's balance"); + // Reset CLI as we're calling getBalance again + resetCli(); + clearLogs(); + await run( + `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + ); + const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; + expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); + }, 30_000); }); - it('deploys a contract & sends transactions', async () => { - // generate a private key - debug('Create an account using a private key'); - await run('generate-private-key', false); - const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; - expect(privKey).toHaveLength(64); - await run(`create-account --private-key ${privKey}`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const ownerAddress = AztecAddress.fromString(foundAddress!); - - debug('Deploy Private Token Contract using created account.'); - await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); - const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(loggedAddress).toBeDefined(); - contractAddress = AztecAddress.fromString(loggedAddress!); - - const deployedContract = await aztecRpcClient.getContractData(contractAddress); - expect(deployedContract?.contractAddress).toEqual(contractAddress); - - debug('Check contract can be found in returned address'); - await run(`check-deploy -ca ${loggedAddress}`); - const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); - - // clear logs - clearLogs(); - await run(`get-contract-data ${loggedAddress}`); - const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); - - debug("Check owner's balance"); - await run( - `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); - - debug('Transfer some tokens'); - const existingAccounts = await aztecRpcClient.getAccounts(); - // ensure we pick a different acc - const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); - - await run( - `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, - ); - const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; - - debug('Check the transfer receipt'); - await run(`get-tx-receipt ${txHash}`); - const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; - const parsedResult = JSON.parse(txResult!); - expect(parsedResult.txHash).toEqual(txHash); - expect(parsedResult.status).toEqual('mined'); - debug("Check Receiver's balance"); - // Reset CLI as we're calling getBalance again - resetCli(); - clearLogs(); - await run( - `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); - }, 30_000); -}); +testSuite(testSetup, testCleanup); diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index a5d244830e3..01f5cc04ea9 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -259,7 +259,6 @@ __metadata: dependencies: "@aztec/aztec.js": "workspace:^" "@aztec/cli": "workspace:^" - "@aztec/foundation": "workspace:^" "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-contracts": "workspace:^" "@jest/globals": ^29.5.0 From 15db89b4066b8c6fa7a2cdcc1c4f5cb56de08660 Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 13:51:10 +0000 Subject: [PATCH 02/10] remove all non-canary files to build e2e --- .../dockerfiles/Dockerfile.wasm-linux-clang | 2 +- yarn-project/canary/Dockerfile | 15 +- yarn-project/canary/package.json | 1 + yarn-project/canary/src/cli.test.ts | 305 +++++++++--------- yarn-project/canary/tsconfig.json | 3 + .../end-to-end/scripts/setup_canary.sh | 41 +++ yarn-project/end-to-end/src/canary/cli.ts | 171 ++++++++++ yarn-project/end-to-end/src/e2e_cli.test.ts | 176 +--------- yarn-project/end-to-end/src/fixtures/utils.ts | 2 +- yarn-project/end-to-end/src/index.ts | 3 + yarn-project/yarn-project-base/Dockerfile | 6 +- yarn-project/yarn.lock | 3 +- 12 files changed, 398 insertions(+), 330 deletions(-) create mode 100755 yarn-project/end-to-end/scripts/setup_canary.sh create mode 100644 yarn-project/end-to-end/src/canary/cli.ts create mode 100644 yarn-project/end-to-end/src/index.ts diff --git a/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang index 1dc91d8ba1a..cdd423061f6 100644 --- a/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -1,4 +1,4 @@ -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/barretenberg-wasm-linux-clang as bb +FROM barretenberg-wasm-linux-clang as bb FROM ubuntu:lunar AS builder RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential wget git libssl-dev cmake ninja-build curl binaryen diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index e30b0776ece..3f7b5faa29a 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,17 +1,26 @@ # FROM node:18-alpine -FROM 278380418400.dkr.ecr.us-east-1.amazonaws.com/yarn-project-base AS builder +FROM yarn-project-base AS builder 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" -ARG COMMIT_TAG="" +ARG COMMIT_TAG="0.7.0" -# Build canary with external @aztec deps +# Update @aztec deps COPY . . + +# Build end-to-end package +WORKDIR /usr/src/yarn-project/end-to-end +RUN ./scripts/setup_canary.sh $COMMIT_TAG +RUN yarn && yarn build + +# Build canary package WORKDIR /usr/src/yarn-project/canary RUN ./scripts/update_packages.sh $COMMIT_TAG +RUN ls ../node_modules/@aztec/end-to-end RUN yarn && yarn build +# Copy web artifacts for browser test RUN cp node_modules/@aztec/aztec.js/dest/main.js src/web/ RUN cp node_modules/@aztec/circuits.js/resources/aztec3-circuits.wasm src/web/ diff --git a/yarn-project/canary/package.json b/yarn-project/canary/package.json index 42e2d372d30..a295024ce2f 100644 --- a/yarn-project/canary/package.json +++ b/yarn-project/canary/package.json @@ -23,6 +23,7 @@ "dependencies": { "@aztec/aztec.js": "workspace:^", "@aztec/cli": "workspace:^", + "@aztec/end-to-end": "workspace:^", "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-contracts": "workspace:^", "@jest/globals": "^29.5.0", diff --git a/yarn-project/canary/src/cli.test.ts b/yarn-project/canary/src/cli.test.ts index e9d43af33ea..0bd8628c180 100644 --- a/yarn-project/canary/src/cli.test.ts +++ b/yarn-project/canary/src/cli.test.ts @@ -8,6 +8,7 @@ import { waitForSandbox, } from '@aztec/aztec.js'; import { getProgram } from '@aztec/cli'; +import { testSuite } from '@aztec/end-to-end'; import stringArgv from 'string-argv'; import { format } from 'util'; @@ -25,154 +26,156 @@ const setupRPC = async () => { return aztecRpcClient; }; -describe('CLI canary', () => { - let cli: ReturnType; - let aztecRpcClient: AztecRPC; - let existingAccounts: CompleteAddress[]; - let contractAddress: AztecAddress; - let log: (...args: any[]) => void; - - // All logs emitted by the cli will be collected here, and reset between tests - const logs: string[] = []; - - beforeAll(async () => { - aztecRpcClient = await setupRPC(); - log = (...args: any[]) => { - logs.push(format(...args)); - debug(...args); - }; - }, 60_000); - - // in order to run the same command twice, we need to create a new CLI instance - const resetCli = () => { - cli = getProgram(log, debug); - }; - - beforeEach(() => { - logs.splice(0); - resetCli(); - }); - - // Run a command on the CLI - const run = (cmd: string, addRpcUrl = true) => { - const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); - if (addRpcUrl) { - args.push('--rpc-url', SANDBOX_URL); - } - return cli.parseAsync(args); - }; - - // Returns first match across all logs collected so far - const findInLogs = (regex: RegExp) => { - for (const log of logs) { - const match = regex.exec(log); - if (match) return match; - } - }; - - const findMultipleInLogs = (regex: RegExp) => { - const matches = []; - for (const log of logs) { - const match = regex.exec(log); - if (match) matches.push(match); - } - return matches; - }; - - const clearLogs = () => { - logs.splice(0); - }; - - it('creates & retrieves an account', async () => { - existingAccounts = await aztecRpcClient.getAccounts(); - debug('Create an account'); - await run(`create-account`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const newAddress = AztecAddress.fromString(foundAddress!); - - const accountsAfter = await aztecRpcClient.getAccounts(); - const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; - expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); - const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; - - // Test get-accounts - debug('Check that account was added to the list of accs in RPC'); - await run('get-accounts'); - const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); - const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); - expect(foundFetchedAddress).toBeDefined(); - - // Test get-account - debug('Check we can retrieve the specific account'); - clearLogs(); - await run(`get-account ${newAddress.toString()}`); - const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); - }, 30_000); - - it('deploys a contract & sends transactions', async () => { - // generate a private key - debug('Create an account using a private key'); - await run('generate-private-key', false); - const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; - expect(privKey).toHaveLength(64); - await run(`create-account --private-key ${privKey}`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const ownerAddress = AztecAddress.fromString(foundAddress!); - - debug('Deploy Private Token Contract using created account.'); - await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); - const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(loggedAddress).toBeDefined(); - contractAddress = AztecAddress.fromString(loggedAddress!); - - const deployedContract = await aztecRpcClient.getContractData(contractAddress); - expect(deployedContract?.contractAddress).toEqual(contractAddress); - - debug('Check contract can be found in returned address'); - await run(`check-deploy -ca ${loggedAddress}`); - const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); - - // clear logs - clearLogs(); - await run(`get-contract-data ${loggedAddress}`); - const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); - - debug("Check owner's balance"); - await run( - `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); - - debug('Transfer some tokens'); - const existingAccounts = await aztecRpcClient.getAccounts(); - // ensure we pick a different acc - const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); - - await run( - `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, - ); - const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; - - debug('Check the transfer receipt'); - await run(`get-tx-receipt ${txHash}`); - const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; - const parsedResult = JSON.parse(txResult!); - expect(parsedResult.txHash).toEqual(txHash); - expect(parsedResult.status).toEqual('mined'); - debug("Check Receiver's balance"); - // Reset CLI as we're calling getBalance again - resetCli(); - clearLogs(); - await run( - `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); - }, 60_000); -}); +testSuite(setupRPC, () => Promise.resolve()); + +// describe('CLI canary', () => { +// let cli: ReturnType; +// let aztecRpcClient: AztecRPC; +// let existingAccounts: CompleteAddress[]; +// let contractAddress: AztecAddress; +// let log: (...args: any[]) => void; + +// // All logs emitted by the cli will be collected here, and reset between tests +// const logs: string[] = []; + +// beforeAll(async () => { +// aztecRpcClient = await setupRPC(); +// log = (...args: any[]) => { +// logs.push(format(...args)); +// debug(...args); +// }; +// }, 60_000); + +// // in order to run the same command twice, we need to create a new CLI instance +// const resetCli = () => { +// cli = getProgram(log, debug); +// }; + +// beforeEach(() => { +// logs.splice(0); +// resetCli(); +// }); + +// // Run a command on the CLI +// const run = (cmd: string, addRpcUrl = true) => { +// const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); +// if (addRpcUrl) { +// args.push('--rpc-url', SANDBOX_URL); +// } +// return cli.parseAsync(args); +// }; + +// // Returns first match across all logs collected so far +// const findInLogs = (regex: RegExp) => { +// for (const log of logs) { +// const match = regex.exec(log); +// if (match) return match; +// } +// }; + +// const findMultipleInLogs = (regex: RegExp) => { +// const matches = []; +// for (const log of logs) { +// const match = regex.exec(log); +// if (match) matches.push(match); +// } +// return matches; +// }; + +// const clearLogs = () => { +// logs.splice(0); +// }; + +// it('creates & retrieves an account', async () => { +// existingAccounts = await aztecRpcClient.getAccounts(); +// debug('Create an account'); +// await run(`create-account`); +// const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(foundAddress).toBeDefined(); +// const newAddress = AztecAddress.fromString(foundAddress!); + +// const accountsAfter = await aztecRpcClient.getAccounts(); +// const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; +// expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); +// const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; + +// // Test get-accounts +// debug('Check that account was added to the list of accs in RPC'); +// await run('get-accounts'); +// const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); +// const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); +// expect(foundFetchedAddress).toBeDefined(); + +// // Test get-account +// debug('Check we can retrieve the specific account'); +// clearLogs(); +// await run(`get-account ${newAddress.toString()}`); +// const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); +// }, 30_000); + +// it('deploys a contract & sends transactions', async () => { +// // generate a private key +// debug('Create an account using a private key'); +// await run('generate-private-key', false); +// const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; +// expect(privKey).toHaveLength(64); +// await run(`create-account --private-key ${privKey}`); +// const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(foundAddress).toBeDefined(); +// const ownerAddress = AztecAddress.fromString(foundAddress!); + +// debug('Deploy Private Token Contract using created account.'); +// await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); +// const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(loggedAddress).toBeDefined(); +// contractAddress = AztecAddress.fromString(loggedAddress!); + +// const deployedContract = await aztecRpcClient.getContractData(contractAddress); +// expect(deployedContract?.contractAddress).toEqual(contractAddress); + +// debug('Check contract can be found in returned address'); +// await run(`check-deploy -ca ${loggedAddress}`); +// const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); + +// // clear logs +// clearLogs(); +// await run(`get-contract-data ${loggedAddress}`); +// const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; +// expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); + +// debug("Check owner's balance"); +// await run( +// `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, +// ); +// const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; +// expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); + +// debug('Transfer some tokens'); +// const existingAccounts = await aztecRpcClient.getAccounts(); +// // ensure we pick a different acc +// const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); + +// await run( +// `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, +// ); +// const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; + +// debug('Check the transfer receipt'); +// await run(`get-tx-receipt ${txHash}`); +// const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; +// const parsedResult = JSON.parse(txResult!); +// expect(parsedResult.txHash).toEqual(txHash); +// expect(parsedResult.status).toEqual('mined'); +// debug("Check Receiver's balance"); +// // Reset CLI as we're calling getBalance again +// resetCli(); +// clearLogs(); +// await run( +// `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, +// ); +// const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; +// expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); +// }, 60_000); +// }); diff --git a/yarn-project/canary/tsconfig.json b/yarn-project/canary/tsconfig.json index 7b22ac6e52c..36f2fd7fa21 100644 --- a/yarn-project/canary/tsconfig.json +++ b/yarn-project/canary/tsconfig.json @@ -25,6 +25,9 @@ { "path": "../cli" }, + { + "path": "../end-to-end" + }, { "path": "../l1-artifacts" }, diff --git a/yarn-project/end-to-end/scripts/setup_canary.sh b/yarn-project/end-to-end/scripts/setup_canary.sh new file mode 100755 index 00000000000..68722a83cd6 --- /dev/null +++ b/yarn-project/end-to-end/scripts/setup_canary.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -eu + +COMMIT_TAG=$1 + +if [ -z "$COMMIT_TAG" ]; then + echo "No commit tag provided." + exit 0 +fi + +VERSION=$(npx semver $COMMIT_TAG) +if [ -z "$VERSION" ]; then + echo "$COMMIT_TAG is not a semantic version." + exit 1 +fi + +echo "Removing all files & folders that aren't needed for canary tests" +TARGET_DIR="./src" +cd "$TARGET_DIR" + +ls -A + +# Loop through all files and folders in the directory +for item in $(ls -A); do + if [[ "$item" != "index.ts" && "$item" != "canary" ]]; then + # Remove the item (either file or folder) + rm -rf "$item" + fi +done + +echo "Updating external Aztec dependencies to version $VERSION" + +# Packages that are publically available in npm +TARGET_PKGS=("@aztec/aztec.js" "@aztec/cli" "@aztec/l1-artifacts" "@aztec/noir-contracts") + +TMP=$(mktemp) +for PKG in "${TARGET_PKGS[@]}"; do + jq --arg v $VERSION ".dependencies[\"$PKG\"] = \$v" package.json > $TMP && mv $TMP package.json +done + +jq ".references = []" tsconfig.json > $TMP && mv $TMP tsconfig.json diff --git a/yarn-project/end-to-end/src/canary/cli.ts b/yarn-project/end-to-end/src/canary/cli.ts new file mode 100644 index 00000000000..8e45469991d --- /dev/null +++ b/yarn-project/end-to-end/src/canary/cli.ts @@ -0,0 +1,171 @@ +import { AztecAddress, AztecRPC, CompleteAddress, createDebugLogger } from '@aztec/aztec.js'; +import { getProgram } from '@aztec/cli'; + +import stringArgv from 'string-argv'; +import { format } from 'util'; + +const debug = createDebugLogger('aztec:e2e_cli'); + +const INITIAL_BALANCE = 33000; +const TRANSFER_BALANCE = 3000; + +export const testSuite = ( + setup: () => Promise, + cleanup: () => Promise, + rpcUrl = 'http://localhost:8080', +) => + describe('CLI e2e test', () => { + let cli: ReturnType; + let aztecRpcClient: AztecRPC; + let existingAccounts: CompleteAddress[]; + let contractAddress: AztecAddress; + let log: (...args: any[]) => void; + + // All logs emitted by the cli will be collected here, and reset between tests + const logs: string[] = []; + + beforeAll(async () => { + aztecRpcClient = await setup(); + log = (...args: any[]) => { + logs.push(format(...args)); + debug(...args); + }; + }); + + afterAll(async () => { + await cleanup(); + }); + + // in order to run the same command twice, we need to create a new CLI instance + const resetCli = () => { + cli = getProgram(log, debug); + }; + + beforeEach(() => { + logs.splice(0); + resetCli(); + }); + + // Run a command on the CLI + const run = (cmd: string, addRpcUrl = true) => { + const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); + if (addRpcUrl) { + args.push('--rpc-url', rpcUrl); + } + return cli.parseAsync(args); + }; + + // Returns first match across all logs collected so far + const findInLogs = (regex: RegExp) => { + for (const log of logs) { + const match = regex.exec(log); + if (match) return match; + } + }; + + const findMultipleInLogs = (regex: RegExp) => { + const matches = []; + for (const log of logs) { + const match = regex.exec(log); + if (match) matches.push(match); + } + return matches; + }; + + const clearLogs = () => { + logs.splice(0); + }; + + it('creates & retrieves an account', async () => { + existingAccounts = await aztecRpcClient.getAccounts(); + debug('Create an account'); + await run(`create-account`); + const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(foundAddress).toBeDefined(); + const newAddress = AztecAddress.fromString(foundAddress!); + + const accountsAfter = await aztecRpcClient.getAccounts(); + const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; + expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); + const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; + + // Test get-accounts + debug('Check that account was added to the list of accs in RPC'); + await run('get-accounts'); + const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); + const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); + expect(foundFetchedAddress).toBeDefined(); + + // Test get-account + debug('Check we can retrieve the specific account'); + clearLogs(); + await run(`get-account ${newAddress.toString()}`); + const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); + }); + + it('deploys a contract & sends transactions', async () => { + // generate a private key + debug('Create an account using a private key'); + await run('generate-private-key', false); + const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; + expect(privKey).toHaveLength(64); + await run(`create-account --private-key ${privKey}`); + const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(foundAddress).toBeDefined(); + const ownerAddress = AztecAddress.fromString(foundAddress!); + + debug('Deploy Private Token Contract using created account.'); + await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); + const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(loggedAddress).toBeDefined(); + contractAddress = AztecAddress.fromString(loggedAddress!); + + const deployedContract = await aztecRpcClient.getContractData(contractAddress); + expect(deployedContract?.contractAddress).toEqual(contractAddress); + + debug('Check contract can be found in returned address'); + await run(`check-deploy -ca ${loggedAddress}`); + const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); + + // clear logs + clearLogs(); + await run(`get-contract-data ${loggedAddress}`); + const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); + + debug("Check owner's balance"); + await run( + `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + ); + const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; + expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); + + debug('Transfer some tokens'); + const existingAccounts = await aztecRpcClient.getAccounts(); + // ensure we pick a different acc + const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); + + await run( + `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, + ); + const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; + + debug('Check the transfer receipt'); + await run(`get-tx-receipt ${txHash}`); + const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; + const parsedResult = JSON.parse(txResult!); + expect(parsedResult.txHash).toEqual(txHash); + expect(parsedResult.status).toEqual('mined'); + debug("Check Receiver's balance"); + // Reset CLI as we're calling getBalance again + resetCli(); + clearLogs(); + await run( + `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, + ); + const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; + expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); + }, 30_000); + }); diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index 04cda3646ba..fd8a78c3786 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -1,14 +1,10 @@ import { AztecNodeService } from '@aztec/aztec-node'; -import { AztecAddress, AztecRPCServer } from '@aztec/aztec-rpc'; +import { AztecRPCServer } from '@aztec/aztec-rpc'; import { startHttpRpcServer } from '@aztec/aztec-sandbox'; -import { createDebugLogger } from '@aztec/aztec.js'; -import { getProgram } from '@aztec/cli'; -import { AztecRPC, CompleteAddress } from '@aztec/types'; +import { AztecRPC, createDebugLogger } from '@aztec/aztec.js'; -import stringArgv from 'string-argv'; -import { format } from 'util'; - -import { setup } from './fixtures/utils.js'; +import { testSuite } from './canary/cli.js'; +import { setup as e2eSetup } from './fixtures/utils.js'; const HTTP_PORT = 9009; const RPC_URL = `http://localhost:${HTTP_PORT}`; @@ -19,7 +15,7 @@ let aztecNode: AztecNodeService | undefined; let aztecRpcServer: AztecRPC; const testSetup = async () => { - const context = await setup(2); + const context = await e2eSetup(2); debug(`Environment set up`); const { deployL1ContractsValues } = context; ({ aztecNode, aztecRpcServer } = context); @@ -34,164 +30,4 @@ const testCleanup = async () => { await (aztecRpcServer as AztecRPCServer).stop(); }; -const INITIAL_BALANCE = 33000; -const TRANSFER_BALANCE = 3000; - -export const testSuite = (setup: () => Promise, cleanup: () => Promise) => - describe('CLI e2e test', () => { - let cli: ReturnType; - let aztecRpcClient: AztecRPC; - let existingAccounts: CompleteAddress[]; - let contractAddress: AztecAddress; - let log: (...args: any[]) => void; - - // All logs emitted by the cli will be collected here, and reset between tests - const logs: string[] = []; - - beforeAll(async () => { - aztecRpcClient = await setup(); - log = (...args: any[]) => { - logs.push(format(...args)); - debug(...args); - }; - }); - - afterAll(async () => { - await cleanup(); - }); - - // in order to run the same command twice, we need to create a new CLI instance - const resetCli = () => { - cli = getProgram(log, debug); - }; - - beforeEach(() => { - logs.splice(0); - resetCli(); - }); - - // Run a command on the CLI - const run = (cmd: string, addRpcUrl = true) => { - const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); - if (addRpcUrl) { - args.push('--rpc-url', RPC_URL); - } - return cli.parseAsync(args); - }; - - // Returns first match across all logs collected so far - const findInLogs = (regex: RegExp) => { - for (const log of logs) { - const match = regex.exec(log); - if (match) return match; - } - }; - - const findMultipleInLogs = (regex: RegExp) => { - const matches = []; - for (const log of logs) { - const match = regex.exec(log); - if (match) matches.push(match); - } - return matches; - }; - - const clearLogs = () => { - logs.splice(0); - }; - - it('creates & retrieves an account', async () => { - existingAccounts = await aztecRpcClient.getAccounts(); - debug('Create an account'); - await run(`create-account`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const newAddress = AztecAddress.fromString(foundAddress!); - - const accountsAfter = await aztecRpcClient.getAccounts(); - const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; - expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); - const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; - - // Test get-accounts - debug('Check that account was added to the list of accs in RPC'); - await run('get-accounts'); - const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); - const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); - expect(foundFetchedAddress).toBeDefined(); - - // Test get-account - debug('Check we can retrieve the specific account'); - clearLogs(); - await run(`get-account ${newAddress.toString()}`); - const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); - }); - - it('deploys a contract & sends transactions', async () => { - // generate a private key - debug('Create an account using a private key'); - await run('generate-private-key', false); - const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; - expect(privKey).toHaveLength(64); - await run(`create-account --private-key ${privKey}`); - const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(foundAddress).toBeDefined(); - const ownerAddress = AztecAddress.fromString(foundAddress!); - - debug('Deploy Private Token Contract using created account.'); - await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); - const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(loggedAddress).toBeDefined(); - contractAddress = AztecAddress.fromString(loggedAddress!); - - const deployedContract = await aztecRpcClient.getContractData(contractAddress); - expect(deployedContract?.contractAddress).toEqual(contractAddress); - - debug('Check contract can be found in returned address'); - await run(`check-deploy -ca ${loggedAddress}`); - const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); - - // clear logs - clearLogs(); - await run(`get-contract-data ${loggedAddress}`); - const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); - - debug("Check owner's balance"); - await run( - `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); - - debug('Transfer some tokens'); - const existingAccounts = await aztecRpcClient.getAccounts(); - // ensure we pick a different acc - const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); - - await run( - `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, - ); - const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; - - debug('Check the transfer receipt'); - await run(`get-tx-receipt ${txHash}`); - const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; - const parsedResult = JSON.parse(txResult!); - expect(parsedResult.txHash).toEqual(txHash); - expect(parsedResult.status).toEqual('mined'); - debug("Check Receiver's balance"); - // Reset CLI as we're calling getBalance again - resetCli(); - clearLogs(); - await run( - `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, - ); - const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; - expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); - }, 30_000); - }); - -testSuite(testSetup, testCleanup); +testSuite(testSetup, testCleanup, RPC_URL); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index e5333ff9b0d..b08788cf1f9 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -4,6 +4,7 @@ import { AccountWallet, AztecAddress, CheatCodes, + CompleteAddress, EthAddress, EthCheatCodes, Wallet, @@ -13,7 +14,6 @@ import { getSandboxAccountsWallets, makeFetch, } from '@aztec/aztec.js'; -import { CompleteAddress } from '@aztec/circuits.js'; import { DeployL1Contracts, deployL1Contract, deployL1Contracts } from '@aztec/ethereum'; import { Fr } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/index.ts b/yarn-project/end-to-end/src/index.ts new file mode 100644 index 00000000000..954d291b95b --- /dev/null +++ b/yarn-project/end-to-end/src/index.ts @@ -0,0 +1,3 @@ +// Should only export tests from the canary directory + +export { testSuite as cliTestSuite } from './canary/cli.js'; diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index dca9635efdc..71de4538133 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -1,7 +1,7 @@ # Update this counter to trigger a rebuild when needed: 1 -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/circuits-wasm-linux-clang as circuits -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/l1-contracts as contracts -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/noir-contracts-build as noir +FROM circuits-wasm-linux-clang as circuits +FROM l1-contracts as contracts +FROM noir-contracts-build as noir FROM node:18-alpine AS builder_ RUN apk update && apk add --no-cache build-base git python3 curl bash jq sed diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index f0736b637ee..b64172d3444 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -259,6 +259,7 @@ __metadata: dependencies: "@aztec/aztec.js": "workspace:^" "@aztec/cli": "workspace:^" + "@aztec/end-to-end": "workspace:^" "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-contracts": "workspace:^" "@jest/globals": ^29.5.0 @@ -350,7 +351,7 @@ __metadata: languageName: unknown linkType: soft -"@aztec/end-to-end@workspace:end-to-end": +"@aztec/end-to-end@workspace:^, @aztec/end-to-end@workspace:end-to-end": version: 0.0.0-use.local resolution: "@aztec/end-to-end@workspace:end-to-end" dependencies: From 18d2c05f50cd311231b6f81797e295beb4560762 Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 14:17:49 +0000 Subject: [PATCH 03/10] working CLI e2e & canary test --- yarn-project/canary/Dockerfile | 7 +- yarn-project/canary/package.json | 1 - yarn-project/canary/src/cli.test.ts | 173 +----------------- .../end-to-end/scripts/setup_canary.sh | 3 +- yarn-project/end-to-end/src/canary/cli.ts | 8 +- yarn-project/yarn-project-base/Dockerfile | 6 +- yarn-project/yarn.lock | 1 - 7 files changed, 14 insertions(+), 185 deletions(-) diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index 3f7b5faa29a..5afa27153d9 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,5 +1,5 @@ # FROM node:18-alpine -FROM yarn-project-base AS builder +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder 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" @@ -17,11 +17,10 @@ RUN yarn && yarn build # Build canary package WORKDIR /usr/src/yarn-project/canary RUN ./scripts/update_packages.sh $COMMIT_TAG -RUN ls ../node_modules/@aztec/end-to-end RUN yarn && yarn build # Copy web artifacts for browser test -RUN cp node_modules/@aztec/aztec.js/dest/main.js 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/ +RUN cp ../node_modules/@aztec/circuits.js/resources/aztec3-circuits.wasm src/web/ ENTRYPOINT ["yarn", "test"] \ No newline at end of file diff --git a/yarn-project/canary/package.json b/yarn-project/canary/package.json index a295024ce2f..3cca8dad560 100644 --- a/yarn-project/canary/package.json +++ b/yarn-project/canary/package.json @@ -34,7 +34,6 @@ "koa": "^2.14.2", "koa-static": "^5.0.0", "puppeteer": "^21.1.0", - "string-argv": "^0.3.2", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", "tslib": "^2.4.0", diff --git a/yarn-project/canary/src/cli.test.ts b/yarn-project/canary/src/cli.test.ts index 0bd8628c180..08c05683743 100644 --- a/yarn-project/canary/src/cli.test.ts +++ b/yarn-project/canary/src/cli.test.ts @@ -1,181 +1,14 @@ -import { - AztecAddress, - AztecRPC, - CompleteAddress, - createAztecRpcClient, - createDebugLogger, - makeFetch, - waitForSandbox, -} from '@aztec/aztec.js'; -import { getProgram } from '@aztec/cli'; -import { testSuite } from '@aztec/end-to-end'; - -import stringArgv from 'string-argv'; -import { format } from 'util'; +import { createAztecRpcClient, createDebugLogger, makeFetch, waitForSandbox } from '@aztec/aztec.js'; +import { cliTestSuite } from '@aztec/end-to-end'; const { SANDBOX_URL = 'http://localhost:8080' } = process.env; const debug = createDebugLogger('aztec:e2e_cli'); -const INITIAL_BALANCE = 33000; -const TRANSFER_BALANCE = 3000; - const setupRPC = async () => { const aztecRpcClient = createAztecRpcClient(SANDBOX_URL, makeFetch([1, 2, 3, 4, 5], true)); await waitForSandbox(aztecRpcClient); return aztecRpcClient; }; -testSuite(setupRPC, () => Promise.resolve()); - -// describe('CLI canary', () => { -// let cli: ReturnType; -// let aztecRpcClient: AztecRPC; -// let existingAccounts: CompleteAddress[]; -// let contractAddress: AztecAddress; -// let log: (...args: any[]) => void; - -// // All logs emitted by the cli will be collected here, and reset between tests -// const logs: string[] = []; - -// beforeAll(async () => { -// aztecRpcClient = await setupRPC(); -// log = (...args: any[]) => { -// logs.push(format(...args)); -// debug(...args); -// }; -// }, 60_000); - -// // in order to run the same command twice, we need to create a new CLI instance -// const resetCli = () => { -// cli = getProgram(log, debug); -// }; - -// beforeEach(() => { -// logs.splice(0); -// resetCli(); -// }); - -// // Run a command on the CLI -// const run = (cmd: string, addRpcUrl = true) => { -// const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); -// if (addRpcUrl) { -// args.push('--rpc-url', SANDBOX_URL); -// } -// return cli.parseAsync(args); -// }; - -// // Returns first match across all logs collected so far -// const findInLogs = (regex: RegExp) => { -// for (const log of logs) { -// const match = regex.exec(log); -// if (match) return match; -// } -// }; - -// const findMultipleInLogs = (regex: RegExp) => { -// const matches = []; -// for (const log of logs) { -// const match = regex.exec(log); -// if (match) matches.push(match); -// } -// return matches; -// }; - -// const clearLogs = () => { -// logs.splice(0); -// }; - -// it('creates & retrieves an account', async () => { -// existingAccounts = await aztecRpcClient.getAccounts(); -// debug('Create an account'); -// await run(`create-account`); -// const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(foundAddress).toBeDefined(); -// const newAddress = AztecAddress.fromString(foundAddress!); - -// const accountsAfter = await aztecRpcClient.getAccounts(); -// const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress]; -// expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts); -// const newCompleteAddress = accountsAfter[accountsAfter.length - 1]; - -// // Test get-accounts -// debug('Check that account was added to the list of accs in RPC'); -// await run('get-accounts'); -// const fetchedAddresses = findMultipleInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/); -// const foundFetchedAddress = fetchedAddresses.find(match => match.groups?.address === newAddress.toString()); -// expect(foundFetchedAddress).toBeDefined(); - -// // Test get-account -// debug('Check we can retrieve the specific account'); -// clearLogs(); -// await run(`get-account ${newAddress.toString()}`); -// const fetchedAddress = findInLogs(/Public Key:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(fetchedAddress).toEqual(newCompleteAddress.publicKey.toString()); -// }, 30_000); - -// it('deploys a contract & sends transactions', async () => { -// // generate a private key -// debug('Create an account using a private key'); -// await run('generate-private-key', false); -// const privKey = findInLogs(/Private\sKey:\s+0x(?[a-fA-F0-9]+)/)?.groups?.privKey; -// expect(privKey).toHaveLength(64); -// await run(`create-account --private-key ${privKey}`); -// const foundAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(foundAddress).toBeDefined(); -// const ownerAddress = AztecAddress.fromString(foundAddress!); - -// debug('Deploy Private Token Contract using created account.'); -// await run(`deploy PrivateTokenContractAbi --args ${INITIAL_BALANCE} ${ownerAddress} --salt 0`); -// const loggedAddress = findInLogs(/Contract\sdeployed\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(loggedAddress).toBeDefined(); -// contractAddress = AztecAddress.fromString(loggedAddress!); - -// const deployedContract = await aztecRpcClient.getContractData(contractAddress); -// expect(deployedContract?.contractAddress).toEqual(contractAddress); - -// debug('Check contract can be found in returned address'); -// await run(`check-deploy -ca ${loggedAddress}`); -// const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); - -// // clear logs -// clearLogs(); -// await run(`get-contract-data ${loggedAddress}`); -// const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; -// expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); - -// debug("Check owner's balance"); -// await run( -// `call getBalance --args ${ownerAddress} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, -// ); -// const balance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; -// expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`); - -// debug('Transfer some tokens'); -// const existingAccounts = await aztecRpcClient.getAccounts(); -// // ensure we pick a different acc -// const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString()); - -// await run( -// `send transfer --args ${TRANSFER_BALANCE} ${receiver?.address.toString()} --contract-address ${contractAddress.toString()} --contract-abi PrivateTokenContractAbi --private-key ${privKey}`, -// ); -// const txHash = findInLogs(/Transaction\shash:\s+(?\S+)/)?.groups?.txHash; - -// debug('Check the transfer receipt'); -// await run(`get-tx-receipt ${txHash}`); -// const txResult = findInLogs(/Transaction receipt:\s*(?[\s\S]*?\})/)?.groups?.txHash; -// const parsedResult = JSON.parse(txResult!); -// expect(parsedResult.txHash).toEqual(txHash); -// expect(parsedResult.status).toEqual('mined'); -// debug("Check Receiver's balance"); -// // Reset CLI as we're calling getBalance again -// resetCli(); -// clearLogs(); -// await run( -// `call getBalance --args ${receiver?.address.toString()} --contract-abi PrivateTokenContractAbi --contract-address ${contractAddress.toString()}`, -// ); -// const receiverBalance = findInLogs(/View\sresult:\s+(?\S+)/)?.groups?.data; -// expect(receiverBalance).toEqual(`${BigInt(TRANSFER_BALANCE).toString()}n`); -// }, 60_000); -// }); +cliTestSuite('CLI Canary', setupRPC, () => Promise.resolve(), debug, SANDBOX_URL); diff --git a/yarn-project/end-to-end/scripts/setup_canary.sh b/yarn-project/end-to-end/scripts/setup_canary.sh index 68722a83cd6..121d45b4571 100755 --- a/yarn-project/end-to-end/scripts/setup_canary.sh +++ b/yarn-project/end-to-end/scripts/setup_canary.sh @@ -18,8 +18,6 @@ echo "Removing all files & folders that aren't needed for canary tests" TARGET_DIR="./src" cd "$TARGET_DIR" -ls -A - # Loop through all files and folders in the directory for item in $(ls -A); do if [[ "$item" != "index.ts" && "$item" != "canary" ]]; then @@ -27,6 +25,7 @@ for item in $(ls -A); do rm -rf "$item" fi done +cd .. echo "Updating external Aztec dependencies to version $VERSION" diff --git a/yarn-project/end-to-end/src/canary/cli.ts b/yarn-project/end-to-end/src/canary/cli.ts index 8e45469991d..8ffe6cb849d 100644 --- a/yarn-project/end-to-end/src/canary/cli.ts +++ b/yarn-project/end-to-end/src/canary/cli.ts @@ -1,20 +1,20 @@ -import { AztecAddress, AztecRPC, CompleteAddress, createDebugLogger } from '@aztec/aztec.js'; +import { AztecAddress, AztecRPC, CompleteAddress, DebugLogger } from '@aztec/aztec.js'; import { getProgram } from '@aztec/cli'; import stringArgv from 'string-argv'; import { format } from 'util'; -const debug = createDebugLogger('aztec:e2e_cli'); - const INITIAL_BALANCE = 33000; const TRANSFER_BALANCE = 3000; export const testSuite = ( + name: string, setup: () => Promise, cleanup: () => Promise, + debug: DebugLogger, rpcUrl = 'http://localhost:8080', ) => - describe('CLI e2e test', () => { + describe(name, () => { let cli: ReturnType; let aztecRpcClient: AztecRPC; let existingAccounts: CompleteAddress[]; diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 71de4538133..dca9635efdc 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -1,7 +1,7 @@ # Update this counter to trigger a rebuild when needed: 1 -FROM circuits-wasm-linux-clang as circuits -FROM l1-contracts as contracts -FROM noir-contracts-build as noir +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/circuits-wasm-linux-clang as circuits +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/l1-contracts as contracts +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/noir-contracts-build as noir FROM node:18-alpine AS builder_ RUN apk update && apk add --no-cache build-base git python3 curl bash jq sed diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index b64172d3444..2b60072981a 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -271,7 +271,6 @@ __metadata: koa: ^2.14.2 koa-static: ^5.0.0 puppeteer: ^21.1.0 - string-argv: ^0.3.2 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0 From 00cf5e98991d93f9cbaad0b3a158aee918fd2a80 Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 14:20:24 +0000 Subject: [PATCH 04/10] remove ARG value --- yarn-project/canary/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index 5afa27153d9..d1935e99431 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -4,18 +4,18 @@ FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder 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" -ARG COMMIT_TAG="0.7.0" +ARG COMMIT_TAG="" -# Update @aztec deps COPY . . -# Build end-to-end package +# Setup & Build end-to-end package WORKDIR /usr/src/yarn-project/end-to-end RUN ./scripts/setup_canary.sh $COMMIT_TAG RUN yarn && yarn build # Build canary package WORKDIR /usr/src/yarn-project/canary +# Update @aztec deps RUN ./scripts/update_packages.sh $COMMIT_TAG RUN yarn && yarn build From 16baa93c0153c20e23015780a424b7b980f94f4c Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 15:45:14 +0000 Subject: [PATCH 05/10] browser test shared code --- yarn-project/canary/package.json | 1 - .../canary/src/aztec_js_browser.test.ts | 222 ++---------------- yarn-project/canary/src/cli.test.ts | 2 +- yarn-project/end-to-end/src/canary/browser.ts | 218 +++++++++++++++++ yarn-project/end-to-end/src/canary/cli.ts | 2 +- .../src/e2e_aztec_js_browser.test.ts | 214 +---------------- yarn-project/end-to-end/src/e2e_cli.test.ts | 4 +- yarn-project/end-to-end/src/index.ts | 3 +- yarn-project/yarn.lock | 68 ------ 9 files changed, 250 insertions(+), 484 deletions(-) create mode 100644 yarn-project/end-to-end/src/canary/browser.ts diff --git a/yarn-project/canary/package.json b/yarn-project/canary/package.json index 3cca8dad560..0a792977fb4 100644 --- a/yarn-project/canary/package.json +++ b/yarn-project/canary/package.json @@ -33,7 +33,6 @@ "jest": "^29.5.0", "koa": "^2.14.2", "koa-static": "^5.0.0", - "puppeteer": "^21.1.0", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", "tslib": "^2.4.0", diff --git a/yarn-project/canary/src/aztec_js_browser.test.ts b/yarn-project/canary/src/aztec_js_browser.test.ts index b2c70ade731..3db3febdb67 100644 --- a/yarn-project/canary/src/aztec_js_browser.test.ts +++ b/yarn-project/canary/src/aztec_js_browser.test.ts @@ -1,219 +1,25 @@ -/* eslint-disable no-console */ -import * as AztecJs from '@aztec/aztec.js'; -import { PrivateTokenContractAbi } from '@aztec/noir-contracts/artifacts'; +import { createDebugLogger, fileURLToPath } from '@aztec/aztec.js'; +import { browserTestSuite } from '@aztec/end-to-end'; -import { Server } from 'http'; import Koa from 'koa'; import serve from 'koa-static'; import path, { dirname } from 'path'; -import { Browser, Page, launch } from 'puppeteer'; -declare global { - interface Window { - AztecJs: typeof AztecJs; - } -} - -const __filename = AztecJs.fileURLToPath(import.meta.url); +const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +const PORT = 3000; -const PORT = 3033; - -const { SANDBOX_URL } = process.env; - -const conditionalDescribe = () => (SANDBOX_URL ? describe : describe.skip); -const privKey = AztecJs.GrumpkinScalar.random(); - -/** - * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. - * To run the test, do the following: - * 1) Build the whole repository, - * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, - * 3) start anvil: `anvil`, - * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, - * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, - * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, - * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` - * - * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage - * unexpectedly running in the background. Kill it with `killall chrome` - */ -conditionalDescribe()('e2e_aztec.js_browser', () => { - const initialBalance = 33n; - const transferAmount = 3n; - - let contractAddress: AztecJs.AztecAddress; - - let logger: AztecJs.DebugLogger; - let pageLogger: AztecJs.DebugLogger; - let app: Koa; - let testClient: AztecJs.AztecRPC; - let server: Server; - - let browser: Browser; - let page: Page; - - beforeAll(async () => { - testClient = AztecJs.createAztecRpcClient(SANDBOX_URL!, AztecJs.makeFetch([1, 2, 3], true)); - await AztecJs.waitForSandbox(testClient); - const pathRes = path.resolve(__dirname, './web'); - app = new Koa(); - app.use(serve(pathRes)); - server = app.listen(PORT, () => { - logger(`Server started at http://localhost:${PORT}`); - }); - - logger = AztecJs.createDebugLogger('aztec:aztec.js:web'); - pageLogger = AztecJs.createDebugLogger('aztec:aztec.js:web:page'); +const logger = createDebugLogger('aztec:canary_aztec.js:web'); +const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); - browser = await launch({ - executablePath: process.env.CHROME_BIN, - headless: 'new', - args: [ - '--allow-file-access-from-files', - '--no-sandbox', - '--headless', - '--disable-web-security', - '--disable-features=IsolateOrigins', - '--disable-site-isolation-trials', - '--disable-gpu', - '--disable-dev-shm-usage', - '--disk-cache-dir=/dev/null', - ], - }); - page = await browser.newPage(); - page.on('console', msg => { - pageLogger('PAGE MSG', msg.text()); - }); - page.on('pageerror', err => { - pageLogger.error('PAGE ERROR', err.toString()); - }); - await page.goto(`http://localhost:${PORT}`); - }, 120_000); - - afterAll(async () => { - await browser.close(); - server.close(); - }); - - it('Loads Aztec.js in the browser', async () => { - const generatePublicKeyExists = await page.evaluate(() => { - const { generatePublicKey } = window.AztecJs; - return typeof generatePublicKey === 'function'; - }); - expect(generatePublicKeyExists).toBe(true); +const setupApp = () => { + const app = new Koa(); + app.use(serve(path.resolve(__dirname, './web'))); + const server = app.listen(PORT, () => { + logger(`Server started at http://localhost:${PORT}`); }); - it('Creates an account', async () => { - const result = await page.evaluate( - async (rpcUrl, privateKeyString) => { - const { GrumpkinScalar, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const privateKey = GrumpkinScalar.fromString(privateKeyString); - const account = getUnsafeSchnorrAccount(client, privateKey); - await account.waitDeploy(); - const completeAddress = await account.getCompleteAddress(); - const addressString = completeAddress.address.toString(); - console.log(`Created Account: ${addressString}`); - return addressString; - }, - SANDBOX_URL, - privKey.toString(), - ); - const accounts = await testClient.getAccounts(); - const stringAccounts = accounts.map(acc => acc.address.toString()); - expect(stringAccounts.includes(result)).toBeTruthy(); - }, 15_000); - - it('Deploys Private Token contract', async () => { - await deployPrivateTokenContract(); - }, 30_000); - - it("Gets the owner's balance", async () => { - const result = await page.evaluate( - async (rpcUrl, contractAddress, PrivateTokenContractAbi) => { - const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const owner = (await client.getAccounts())[0].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(client); - const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - const balance = await contract.methods.getBalance(owner).view({ from: owner }); - console.log(`Owner's balance: ${balance}`); - return balance; - }, - SANDBOX_URL, - (await getPrivateTokenAddress()).toString(), - PrivateTokenContractAbi, - ); - logger('Owner balance:', result); - expect(result).toEqual(initialBalance); - }); - - it('Sends a transfer TX', async () => { - const result = await page.evaluate( - async (rpcUrl, contractAddress, transferAmount, PrivateTokenContractAbi) => { - console.log(`Starting transfer tx`); - const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const accounts = await client.getAccounts(); - const owner = accounts[0].address; - const receiver = accounts[1].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(client); - const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - await contract.methods.transfer(transferAmount, receiver).send().wait(); - console.log(`Transferred ${transferAmount} tokens to new Account`); - const receiverBalance = await contract.methods.getBalance(receiver).view({ from: receiver }); - console.log(`Receiver's balance is now: ${receiverBalance}`); - const senderBalance = await contract.methods.getBalance(owner).view({ from: owner }); - console.log(`Updated sender balance: ${senderBalance}`); - return receiverBalance; - }, - SANDBOX_URL, - (await getPrivateTokenAddress()).toString(), - transferAmount, - PrivateTokenContractAbi, - ); - expect(result).toEqual(transferAmount); - }, 60_000); - - const deployPrivateTokenContract = async () => { - const txHash = await page.evaluate( - async (rpcUrl, privateKeyString, initialBalance, PrivateTokenContractAbi) => { - const { GrumpkinScalar, DeployMethod, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = - window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - let accounts = await client.getAccounts(); - if (accounts.length === 0) { - // This test needs an account for deployment. We create one in case there is none available in the RPC server. - const privateKey = GrumpkinScalar.fromString(privateKeyString); - await getUnsafeSchnorrAccount(client, privateKey).waitDeploy(); - accounts = await client.getAccounts(); - } - const owner = accounts[0]; - const tx = new DeployMethod(owner.publicKey, client, PrivateTokenContractAbi, [ - initialBalance, - owner.address, - ]).send(); - await tx.wait(); - const receipt = await tx.getReceipt(); - console.log(`Contract Deployed: ${receipt.contractAddress}`); - return receipt.txHash.toString(); - }, - SANDBOX_URL, - privKey.toString(), - initialBalance, - PrivateTokenContractAbi, - ); - - const txResult = await testClient.getTxReceipt(AztecJs.TxHash.fromString(txHash)); - expect(txResult.status).toEqual(AztecJs.TxStatus.MINED); - contractAddress = txResult.contractAddress!; - }; + return server; +}; - const getPrivateTokenAddress = async () => { - if (!contractAddress) { - await deployPrivateTokenContract(); - } - return contractAddress; - }; -}); +browserTestSuite(setupApp, pageLogger); diff --git a/yarn-project/canary/src/cli.test.ts b/yarn-project/canary/src/cli.test.ts index 08c05683743..309dddca662 100644 --- a/yarn-project/canary/src/cli.test.ts +++ b/yarn-project/canary/src/cli.test.ts @@ -3,7 +3,7 @@ import { cliTestSuite } from '@aztec/end-to-end'; const { SANDBOX_URL = 'http://localhost:8080' } = process.env; -const debug = createDebugLogger('aztec:e2e_cli'); +const debug = createDebugLogger('aztec:canary_cli'); const setupRPC = async () => { const aztecRpcClient = createAztecRpcClient(SANDBOX_URL, makeFetch([1, 2, 3, 4, 5], true)); diff --git a/yarn-project/end-to-end/src/canary/browser.ts b/yarn-project/end-to-end/src/canary/browser.ts new file mode 100644 index 00000000000..a60b2d3e9ea --- /dev/null +++ b/yarn-project/end-to-end/src/canary/browser.ts @@ -0,0 +1,218 @@ +/* eslint-disable no-console */ +import * as AztecJs from '@aztec/aztec.js'; +import { PrivateTokenContractAbi } from '@aztec/noir-contracts/artifacts'; + +import { Server } from 'http'; +import Koa from 'koa'; +import serve from 'koa-static'; +import path, { dirname } from 'path'; +import { Browser, Page, launch } from 'puppeteer'; + +declare global { + /** + * Helper interface to declare aztec.js within browser context. + */ + interface Window { + /** + * The aztec.js library. + */ + AztecJs: typeof AztecJs; + } +} + +const __filename = AztecJs.fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const PORT = 3000; + +const { SANDBOX_URL } = process.env; + +const conditionalDescribe = () => (SANDBOX_URL ? describe : describe.skip); +const privKey = AztecJs.GrumpkinScalar.random(); + +/** + * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. + * To run the test, do the following: + * 1) Build the whole repository, + * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, + * 3) start anvil: `anvil`, + * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, + * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, + * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, + * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` + * + * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage + * unexpectedly running in the background. Kill it with `killall chrome` + */ +export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugLogger) => + conditionalDescribe()('e2e_aztec.js_browser', () => { + const initialBalance = 33n; + const transferAmount = 3n; + + let contractAddress: AztecJs.AztecAddress; + + let app: Koa; + let testClient: AztecJs.AztecRPC; + let server: Server; + + let browser: Browser; + let page: Page; + + beforeAll(async () => { + server = setup(); + testClient = AztecJs.createAztecRpcClient(SANDBOX_URL!, AztecJs.makeFetch([1, 2, 3], true)); + await AztecJs.waitForSandbox(testClient); + + app = new Koa(); + app.use(serve(path.resolve(__dirname, './web'))); + + browser = await launch({ + executablePath: process.env.CHROME_BIN, + headless: 'new', + args: [ + '--allow-file-access-from-files', + '--no-sandbox', + '--headless', + '--disable-web-security', + '--disable-features=IsolateOrigins', + '--disable-site-isolation-trials', + '--disable-gpu', + '--disable-dev-shm-usage', + '--disk-cache-dir=/dev/null', + ], + }); + page = await browser.newPage(); + page.on('console', msg => { + pageLogger(msg.text()); + }); + page.on('pageerror', err => { + pageLogger.error(err.toString()); + }); + await page.goto(`http://localhost:${PORT}/index.html`); + }, 120_000); + + afterAll(async () => { + await browser.close(); + server.close(); + }); + + it('Loads Aztec.js in the browser', async () => { + const generatePublicKeyExists = await page.evaluate(() => { + const { generatePublicKey } = window.AztecJs; + return typeof generatePublicKey === 'function'; + }); + expect(generatePublicKeyExists).toBe(true); + }); + + it('Creates an account', async () => { + const result = await page.evaluate( + async (rpcUrl, privateKeyString) => { + const { GrumpkinScalar, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = window.AztecJs; + const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); + const privateKey = GrumpkinScalar.fromString(privateKeyString); + const account = getUnsafeSchnorrAccount(client, privateKey); + await account.waitDeploy(); + const completeAddress = await account.getCompleteAddress(); + const addressString = completeAddress.address.toString(); + console.log(`Created Account: ${addressString}`); + return addressString; + }, + SANDBOX_URL, + privKey.toString(), + ); + const accounts = await testClient.getAccounts(); + const stringAccounts = accounts.map(acc => acc.address.toString()); + expect(stringAccounts.includes(result)).toBeTruthy(); + }, 15_000); + + it('Deploys Private Token contract', async () => { + await deployPrivateTokenContract(); + }, 30_000); + + it("Gets the owner's balance", async () => { + const result = await page.evaluate( + async (rpcUrl, contractAddress, PrivateTokenContractAbi) => { + const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs; + const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); + const owner = (await client.getAccounts())[0].address; + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); + const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); + const balance = await contract.methods.getBalance(owner).view({ from: owner }); + console.log(`Owner's balance: ${balance}`); + return balance; + }, + SANDBOX_URL, + (await getPrivateTokenAddress()).toString(), + PrivateTokenContractAbi, + ); + expect(result).toEqual(initialBalance); + }); + + it('Sends a transfer TX', async () => { + const result = await page.evaluate( + async (rpcUrl, contractAddress, transferAmount, PrivateTokenContractAbi) => { + console.log(`Starting transfer tx`); + const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs; + const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); + const accounts = await client.getAccounts(); + const owner = accounts[0].address; + const receiver = accounts[1].address; + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); + const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); + await contract.methods.transfer(transferAmount, receiver).send().wait(); + console.log(`Transferred ${transferAmount} tokens to new Account`); + const receiverBalance = await contract.methods.getBalance(receiver).view({ from: receiver }); + console.log(`Receiver's balance is now: ${receiverBalance}`); + const senderBalance = await contract.methods.getBalance(owner).view({ from: owner }); + console.log(`Updated sender balance: ${senderBalance}`); + return receiverBalance; + }, + SANDBOX_URL, + (await getPrivateTokenAddress()).toString(), + transferAmount, + PrivateTokenContractAbi, + ); + expect(result).toEqual(transferAmount); + }, 60_000); + + const deployPrivateTokenContract = async () => { + const txHash = await page.evaluate( + async (rpcUrl, privateKeyString, initialBalance, PrivateTokenContractAbi) => { + const { GrumpkinScalar, DeployMethod, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = + window.AztecJs; + const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); + let accounts = await client.getAccounts(); + if (accounts.length === 0) { + // This test needs an account for deployment. We create one in case there is none available in the RPC server. + const privateKey = GrumpkinScalar.fromString(privateKeyString); + await getUnsafeSchnorrAccount(client, privateKey).waitDeploy(); + accounts = await client.getAccounts(); + } + const owner = accounts[0]; + const tx = new DeployMethod(owner.publicKey, client, PrivateTokenContractAbi, [ + initialBalance, + owner.address, + ]).send(); + await tx.wait(); + const receipt = await tx.getReceipt(); + console.log(`Contract Deployed: ${receipt.contractAddress}`); + return receipt.txHash.toString(); + }, + SANDBOX_URL, + privKey.toString(), + initialBalance, + PrivateTokenContractAbi, + ); + + const txResult = await testClient.getTxReceipt(AztecJs.TxHash.fromString(txHash)); + expect(txResult.status).toEqual(AztecJs.TxStatus.MINED); + contractAddress = txResult.contractAddress!; + }; + + const getPrivateTokenAddress = async () => { + if (!contractAddress) { + await deployPrivateTokenContract(); + } + return contractAddress; + }; + }); diff --git a/yarn-project/end-to-end/src/canary/cli.ts b/yarn-project/end-to-end/src/canary/cli.ts index 8ffe6cb849d..3d53408a154 100644 --- a/yarn-project/end-to-end/src/canary/cli.ts +++ b/yarn-project/end-to-end/src/canary/cli.ts @@ -7,7 +7,7 @@ import { format } from 'util'; const INITIAL_BALANCE = 33000; const TRANSFER_BALANCE = 3000; -export const testSuite = ( +export const cliTestSuite = ( name: string, setup: () => Promise, cleanup: () => Promise, diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index 906a1bb1cd0..f973eed75f0 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -1,216 +1,26 @@ -/* eslint-disable no-console */ -import * as AztecJs from '@aztec/aztec.js'; -import { AztecAddress, GrumpkinScalar } from '@aztec/circuits.js'; -import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; -import { fileURLToPath } from '@aztec/foundation/url'; -import { PrivateTokenContractAbi } from '@aztec/noir-contracts/artifacts'; +import { createDebugLogger, fileURLToPath } from '@aztec/aztec.js'; -import { Server } from 'http'; import Koa from 'koa'; import serve from 'koa-static'; import path, { dirname } from 'path'; -import { Browser, Page, launch } from 'puppeteer'; -declare global { - interface Window { - AztecJs: typeof AztecJs; - } -} +import { browserTestSuite } from './canary/browser.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); - const PORT = 3000; -const { SANDBOX_URL } = process.env; - -const conditionalDescribe = () => (SANDBOX_URL ? describe : describe.skip); -const privKey = GrumpkinScalar.random(); - -/** - * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. - * To run the test, do the following: - * 1) Build the whole repository, - * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, - * 3) start anvil: `anvil`, - * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, - * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, - * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, - * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` - * - * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage - * unexpectedly running in the background. Kill it with `killall chrome` - */ -conditionalDescribe()('e2e_aztec.js_browser', () => { - const initialBalance = 33n; - const transferAmount = 3n; - - let contractAddress: AztecAddress; - - let logger: DebugLogger; - let pageLogger: DebugLogger; - let app: Koa; - let testClient: AztecJs.AztecRPC; - let server: Server; - - let browser: Browser; - let page: Page; - - beforeAll(async () => { - testClient = AztecJs.createAztecRpcClient(SANDBOX_URL!, AztecJs.makeFetch([1, 2, 3], true)); - await AztecJs.waitForSandbox(testClient); - - app = new Koa(); - app.use(serve(path.resolve(__dirname, './web'))); - server = app.listen(PORT, () => { - logger(`Server started at http://localhost:${PORT}`); - }); - - logger = createDebugLogger('aztec:aztec.js:web'); - pageLogger = createDebugLogger('aztec:aztec.js:web:page'); +const logger = createDebugLogger('aztec:canary_aztec.js:web'); +const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); - browser = await launch({ - executablePath: process.env.CHROME_BIN, - headless: 'new', - args: [ - '--allow-file-access-from-files', - '--no-sandbox', - '--headless', - '--disable-web-security', - '--disable-features=IsolateOrigins', - '--disable-site-isolation-trials', - '--disable-gpu', - '--disable-dev-shm-usage', - '--disk-cache-dir=/dev/null', - ], - }); - page = await browser.newPage(); - page.on('console', msg => { - pageLogger(msg.text()); - }); - page.on('pageerror', err => { - pageLogger.error(err.toString()); - }); - await page.goto(`http://localhost:${PORT}/index.html`); - }, 120_000); - - afterAll(async () => { - await browser.close(); - server.close(); - }); - - it('Loads Aztec.js in the browser', async () => { - const generatePublicKeyExists = await page.evaluate(() => { - const { generatePublicKey } = window.AztecJs; - return typeof generatePublicKey === 'function'; - }); - expect(generatePublicKeyExists).toBe(true); +const setupApp = () => { + const app = new Koa(); + app.use(serve(path.resolve(__dirname, './web'))); + const server = app.listen(PORT, () => { + logger(`Server started at http://localhost:${PORT}`); }); - it('Creates an account', async () => { - const result = await page.evaluate( - async (rpcUrl, privateKeyString) => { - const { GrumpkinScalar, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const privateKey = GrumpkinScalar.fromString(privateKeyString); - const account = getUnsafeSchnorrAccount(client, privateKey); - await account.waitDeploy(); - const completeAddress = await account.getCompleteAddress(); - const addressString = completeAddress.address.toString(); - console.log(`Created Account: ${addressString}`); - return addressString; - }, - SANDBOX_URL, - privKey.toString(), - ); - const accounts = await testClient.getAccounts(); - const stringAccounts = accounts.map(acc => acc.address.toString()); - expect(stringAccounts.includes(result)).toBeTruthy(); - }, 15_000); - - it('Deploys Private Token contract', async () => { - await deployPrivateTokenContract(); - }, 30_000); - - it("Gets the owner's balance", async () => { - const result = await page.evaluate( - async (rpcUrl, contractAddress, PrivateTokenContractAbi) => { - const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const owner = (await client.getAccounts())[0].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(client); - const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - const balance = await contract.methods.getBalance(owner).view({ from: owner }); - return balance; - }, - SANDBOX_URL, - (await getPrivateTokenAddress()).toString(), - PrivateTokenContractAbi, - ); - logger('Owner balance:', result); - expect(result).toEqual(initialBalance); - }); - - it('Sends a transfer TX', async () => { - const result = await page.evaluate( - async (rpcUrl, contractAddress, transferAmount, PrivateTokenContractAbi) => { - console.log(`Starting transfer tx`); - const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - const accounts = await client.getAccounts(); - const receiver = accounts[1].address; - const [wallet] = await AztecJs.getSandboxAccountsWallets(client); - const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - await contract.methods.transfer(transferAmount, receiver).send().wait(); - console.log(`Transferred ${transferAmount} tokens to new Account`); - return await contract.methods.getBalance(receiver).view({ from: receiver }); - }, - SANDBOX_URL, - (await getPrivateTokenAddress()).toString(), - transferAmount, - PrivateTokenContractAbi, - ); - expect(result).toEqual(transferAmount); - }, 60_000); - - const deployPrivateTokenContract = async () => { - const txHash = await page.evaluate( - async (rpcUrl, privateKeyString, initialBalance, PrivateTokenContractAbi) => { - const { GrumpkinScalar, DeployMethod, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } = - window.AztecJs; - const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); - let accounts = await client.getAccounts(); - if (accounts.length === 0) { - // This test needs an account for deployment. We create one in case there is none available in the RPC server. - const privateKey = GrumpkinScalar.fromString(privateKeyString); - await getUnsafeSchnorrAccount(client, privateKey).waitDeploy(); - accounts = await client.getAccounts(); - } - const owner = accounts[0]; - const tx = new DeployMethod(owner.publicKey, client, PrivateTokenContractAbi, [ - initialBalance, - owner.address, - ]).send(); - await tx.wait(); - const receipt = await tx.getReceipt(); - console.log(`Contract Deployed: ${receipt.contractAddress}`); - return receipt.txHash.toString(); - }, - SANDBOX_URL, - privKey.toString(), - initialBalance, - PrivateTokenContractAbi, - ); - - const txResult = await testClient.getTxReceipt(AztecJs.TxHash.fromString(txHash)); - expect(txResult.status).toEqual(AztecJs.TxStatus.MINED); - contractAddress = txResult.contractAddress!; - }; + return server; +}; - const getPrivateTokenAddress = async () => { - if (!contractAddress) { - await deployPrivateTokenContract(); - } - return contractAddress; - }; -}); +browserTestSuite(setupApp, pageLogger); diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index fd8a78c3786..112748fe75b 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -3,7 +3,7 @@ import { AztecRPCServer } from '@aztec/aztec-rpc'; import { startHttpRpcServer } from '@aztec/aztec-sandbox'; import { AztecRPC, createDebugLogger } from '@aztec/aztec.js'; -import { testSuite } from './canary/cli.js'; +import { cliTestSuite } from './canary/cli.js'; import { setup as e2eSetup } from './fixtures/utils.js'; const HTTP_PORT = 9009; @@ -30,4 +30,4 @@ const testCleanup = async () => { await (aztecRpcServer as AztecRPCServer).stop(); }; -testSuite(testSetup, testCleanup, RPC_URL); +cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL); diff --git a/yarn-project/end-to-end/src/index.ts b/yarn-project/end-to-end/src/index.ts index 954d291b95b..dd9005c49c9 100644 --- a/yarn-project/end-to-end/src/index.ts +++ b/yarn-project/end-to-end/src/index.ts @@ -1,3 +1,4 @@ // Should only export tests from the canary directory -export { testSuite as cliTestSuite } from './canary/cli.js'; +export { cliTestSuite } from './canary/cli.js'; +export { browserTestSuite } from './canary/browser.js'; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 2b60072981a..1b34b2f77ed 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -270,7 +270,6 @@ __metadata: jest: ^29.5.0 koa: ^2.14.2 koa-static: ^5.0.0 - puppeteer: ^21.1.0 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0 @@ -2640,23 +2639,6 @@ __metadata: languageName: node linkType: hard -"@puppeteer/browsers@npm:1.7.0": - version: 1.7.0 - resolution: "@puppeteer/browsers@npm:1.7.0" - dependencies: - debug: 4.3.4 - extract-zip: 2.0.1 - progress: 2.0.3 - proxy-agent: 6.3.0 - tar-fs: 3.0.4 - unbzip2-stream: 1.4.3 - yargs: 17.7.1 - bin: - browsers: lib/cjs/main-cli.js - checksum: 0a2aecc72fb94a8d94246188f94cfaad730d1d372b34df94ca51ff8a94596bf475a0fee162c317a768fa4b2a707bfa8afd582d594958f49e1019effadfe744b6 - languageName: node - linkType: hard - "@rushstack/eslint-patch@npm:^1.1.4, @rushstack/eslint-patch@npm:^1.2.0": version: 1.3.2 resolution: "@rushstack/eslint-patch@npm:1.3.2" @@ -4780,17 +4762,6 @@ __metadata: languageName: node linkType: hard -"chromium-bidi@npm:0.4.20": - version: 0.4.20 - resolution: "chromium-bidi@npm:0.4.20" - dependencies: - mitt: 3.0.1 - peerDependencies: - devtools-protocol: "*" - checksum: 397145b3728948d403dbf087af97b7112988ed3c4cf43286754452a4b88f087f2088e1b3f18fa5974ceecc8200ca004ed258e18b784ecb4c6ab1ed78c1b280b0 - languageName: node - linkType: hard - "ci-info@npm:^3.2.0": version: 3.8.0 resolution: "ci-info@npm:3.8.0" @@ -5510,13 +5481,6 @@ __metadata: languageName: node linkType: hard -"devtools-protocol@npm:0.0.1159816": - version: 0.0.1159816 - resolution: "devtools-protocol@npm:0.0.1159816" - checksum: 24aa985a34a093a7418c955d0398e8a0829bc1f482eb1db55eca0cf09789de8344d0f36177d3e394fc63ec9bf08cf4114fadf3a7f2ab64f95a17ccc53bcf1aea - languageName: node - linkType: hard - "dezalgo@npm:^1.0.4": version: 1.0.4 resolution: "dezalgo@npm:1.0.4" @@ -9457,13 +9421,6 @@ __metadata: languageName: node linkType: hard -"mitt@npm:3.0.1": - version: 3.0.1 - resolution: "mitt@npm:3.0.1" - checksum: b55a489ac9c2949ab166b7f060601d3b6d893a852515ae9eca4e11df01c013876df777ea109317622b5c1c60e8aae252558e33c8c94e14124db38f64a39614b1 - languageName: node - linkType: hard - "mkdirp-classic@npm:^0.5.2": version: 0.5.3 resolution: "mkdirp-classic@npm:0.5.3" @@ -10400,20 +10357,6 @@ __metadata: languageName: node linkType: hard -"puppeteer-core@npm:21.1.0": - version: 21.1.0 - resolution: "puppeteer-core@npm:21.1.0" - dependencies: - "@puppeteer/browsers": 1.7.0 - chromium-bidi: 0.4.20 - cross-fetch: 4.0.0 - debug: 4.3.4 - devtools-protocol: 0.0.1159816 - ws: 8.13.0 - checksum: 1c3f2a2bb6de3ec90808f06f0c3ef769f0854e7df610c16080c1dd5434cedf865f48d5059c5406fa84227aab8bfae7dec789e5701adb800895c7a7ec888cfb04 - languageName: node - linkType: hard - "puppeteer@npm:^20.9.0": version: 20.9.0 resolution: "puppeteer@npm:20.9.0" @@ -10425,17 +10368,6 @@ __metadata: languageName: node linkType: hard -"puppeteer@npm:^21.1.0": - version: 21.1.0 - resolution: "puppeteer@npm:21.1.0" - dependencies: - "@puppeteer/browsers": 1.7.0 - cosmiconfig: 8.2.0 - puppeteer-core: 21.1.0 - checksum: 15e343dd1c048a0ef228aa52a2df2240dc76d543c379fc9246c41a87f226a2e820c957a911d5fed9e0394c5dd56da5fc163b6626e1219a857268e88cc2544163 - languageName: node - linkType: hard - "pure-rand@npm:^6.0.0": version: 6.0.2 resolution: "pure-rand@npm:6.0.2" From aa9fe7e001df5566f10c51fa6cb8408963b79af7 Mon Sep 17 00:00:00 2001 From: spypsy Date: Thu, 14 Sep 2023 16:12:20 +0000 Subject: [PATCH 06/10] revert dockerfile dev change --- circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang | 2 +- yarn-project/canary/Dockerfile | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang index cdd423061f6..1dc91d8ba1a 100644 --- a/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/circuits/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -1,4 +1,4 @@ -FROM barretenberg-wasm-linux-clang as bb +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/barretenberg-wasm-linux-clang as bb FROM ubuntu:lunar AS builder RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential wget git libssl-dev cmake ninja-build curl binaryen diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index d1935e99431..600f4df7124 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,4 +1,3 @@ -# FROM node:18-alpine FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder RUN apk update && apk add --no-cache udev ttf-freefont chromium curl jq bash From d621a0b37cf82fc78d87eb389a318b8712af6ed2 Mon Sep 17 00:00:00 2001 From: spypsy Date: Fri, 15 Sep 2023 12:38:09 +0000 Subject: [PATCH 07/10] move comment to test location --- yarn-project/end-to-end/src/canary/browser.ts | 14 -------------- .../end-to-end/src/e2e_aztec_js_browser.test.ts | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/yarn-project/end-to-end/src/canary/browser.ts b/yarn-project/end-to-end/src/canary/browser.ts index a60b2d3e9ea..83a40577566 100644 --- a/yarn-project/end-to-end/src/canary/browser.ts +++ b/yarn-project/end-to-end/src/canary/browser.ts @@ -30,20 +30,6 @@ const { SANDBOX_URL } = process.env; const conditionalDescribe = () => (SANDBOX_URL ? describe : describe.skip); const privKey = AztecJs.GrumpkinScalar.random(); -/** - * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. - * To run the test, do the following: - * 1) Build the whole repository, - * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, - * 3) start anvil: `anvil`, - * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, - * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, - * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, - * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` - * - * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage - * unexpectedly running in the background. Kill it with `killall chrome` - */ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugLogger) => conditionalDescribe()('e2e_aztec.js_browser', () => { const initialBalance = 33n; diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index f973eed75f0..bb4a246251e 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -12,7 +12,20 @@ const PORT = 3000; const logger = createDebugLogger('aztec:canary_aztec.js:web'); const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); - +/** + * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. + * To run the test, do the following: + * 1) Build the whole repository, + * 2) go to `yarn-project/aztec.js` and build the web packed package with `yarn build:web`, + * 3) start anvil: `anvil`, + * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, + * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, + * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, + * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` + * + * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage + * unexpectedly running in the background. Kill it with `killall chrome` + */ const setupApp = () => { const app = new Koa(); app.use(serve(path.resolve(__dirname, './web'))); From f8c500d4e5e1763a4541a92d3ed772cf18f3918d Mon Sep 17 00:00:00 2001 From: spypsy Date: Sat, 16 Sep 2023 11:06:54 +0100 Subject: [PATCH 08/10] WIP get canary @aztec packages programmatically --- yarn-project/canary/Dockerfile | 8 +++++--- yarn-project/canary/scripts/extract_packages.sh | 6 ++++++ yarn-project/end-to-end/scripts/setup_canary.sh | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 yarn-project/canary/scripts/extract_packages.sh diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index 600f4df7124..9f7a6457b34 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,15 +1,17 @@ -FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder +FROM 278380418400.dkr.ecr.us-east-2.amazonaws.com/yarn-project-base:cache-bac67d29a415980ebfdada76c76fbd4509313973 AS builder 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" -ARG COMMIT_TAG="" +ARG COMMIT_TAG="0.7.5" COPY . . # Setup & Build end-to-end package WORKDIR /usr/src/yarn-project/end-to-end -RUN ./scripts/setup_canary.sh $COMMIT_TAG +RUN ./scripts/setup_canary.sh $COMMIT_TAG ../canary/scripts/extract_packages.sh +RUN ls +RUN cat package.json RUN yarn && yarn build # Build canary package diff --git a/yarn-project/canary/scripts/extract_packages.sh b/yarn-project/canary/scripts/extract_packages.sh new file mode 100644 index 00000000000..414dc8a3318 --- /dev/null +++ b/yarn-project/canary/scripts/extract_packages.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Extract keys from package.json +TARGET_PKGS=$(jq -r '.dependencies | to_entries[] | select(.key | startswith("@aztec/") and .key != "@aztec/end-to-end") | .key' package.json) + +echo $TARGET_PKGS diff --git a/yarn-project/end-to-end/scripts/setup_canary.sh b/yarn-project/end-to-end/scripts/setup_canary.sh index 121d45b4571..f1a47ab1079 100755 --- a/yarn-project/end-to-end/scripts/setup_canary.sh +++ b/yarn-project/end-to-end/scripts/setup_canary.sh @@ -2,6 +2,7 @@ set -eu COMMIT_TAG=$1 +TARGET_PKGS=$2 if [ -z "$COMMIT_TAG" ]; then echo "No commit tag provided." @@ -30,7 +31,7 @@ cd .. echo "Updating external Aztec dependencies to version $VERSION" # Packages that are publically available in npm -TARGET_PKGS=("@aztec/aztec.js" "@aztec/cli" "@aztec/l1-artifacts" "@aztec/noir-contracts") +# TARGET_PKGS=("@aztec/aztec.js" "@aztec/cli" "@aztec/l1-artifacts" "@aztec/noir-contracts") TMP=$(mktemp) for PKG in "${TARGET_PKGS[@]}"; do From 230d68f303393075674b6b32fd888d09e791f3f4 Mon Sep 17 00:00:00 2001 From: spypsy Date: Sat, 16 Sep 2023 13:28:14 +0000 Subject: [PATCH 09/10] programmatically get canary packages --- yarn-project/canary/Dockerfile | 12 +++++++----- yarn-project/canary/scripts/extract_packages.sh | 11 ++++++++--- yarn-project/end-to-end/scripts/setup_canary.sh | 13 ++++++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) mode change 100644 => 100755 yarn-project/canary/scripts/extract_packages.sh diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index 9f7a6457b34..1832a0076f7 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -1,4 +1,4 @@ -FROM 278380418400.dkr.ecr.us-east-2.amazonaws.com/yarn-project-base:cache-bac67d29a415980ebfdada76c76fbd4509313973 AS builder +FROM 278380418400.dkr.ecr.us-east-2.amazonaws.com/yarn-project-base AS builder 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" @@ -9,14 +9,16 @@ COPY . . # Setup & Build end-to-end package WORKDIR /usr/src/yarn-project/end-to-end -RUN ./scripts/setup_canary.sh $COMMIT_TAG ../canary/scripts/extract_packages.sh -RUN ls -RUN cat package.json + +# 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 rm ./target_pkgs.txt RUN yarn && yarn build # Build canary package WORKDIR /usr/src/yarn-project/canary -# Update @aztec deps RUN ./scripts/update_packages.sh $COMMIT_TAG RUN yarn && yarn build diff --git a/yarn-project/canary/scripts/extract_packages.sh b/yarn-project/canary/scripts/extract_packages.sh old mode 100644 new mode 100755 index 414dc8a3318..24499e23375 --- a/yarn-project/canary/scripts/extract_packages.sh +++ b/yarn-project/canary/scripts/extract_packages.sh @@ -1,6 +1,11 @@ #!/bin/bash -# Extract keys from package.json -TARGET_PKGS=$(jq -r '.dependencies | to_entries[] | select(.key | startswith("@aztec/") and .key != "@aztec/end-to-end") | .key' package.json) +FILE=$1 -echo $TARGET_PKGS +# Capture the output of the jq command in a Bash array +mapfile -t TARGET_PKGS < <(jq -r '.dependencies | keys[] | select(startswith("@aztec/") and . != "@aztec/end-to-end")' $FILE) + +# Loop through the array and print each element on a new line +for pkg in "${TARGET_PKGS[@]}"; do + echo "$pkg" +done \ No newline at end of file diff --git a/yarn-project/end-to-end/scripts/setup_canary.sh b/yarn-project/end-to-end/scripts/setup_canary.sh index f1a47ab1079..2f519f6405f 100755 --- a/yarn-project/end-to-end/scripts/setup_canary.sh +++ b/yarn-project/end-to-end/scripts/setup_canary.sh @@ -2,7 +2,18 @@ set -eu COMMIT_TAG=$1 -TARGET_PKGS=$2 +TARGET_PKGS_FILE=$2 + +# Check if file exists and read it into an array +if [ -f "$TARGET_PKGS_FILE" ]; then + mapfile -t TARGET_PKGS < <(cat "$TARGET_PKGS_FILE") + echo "Loaded array:" + for i in "${TARGET_PKGS[@]}"; do + echo "$i" + done +else + echo "File $TARGET_PKGS_FILE does not exist." +fi if [ -z "$COMMIT_TAG" ]; then echo "No commit tag provided." From 33b08945f456cdd652e7606baa2bd85b014e5b09 Mon Sep 17 00:00:00 2001 From: spypsy Date: Sat, 16 Sep 2023 14:39:54 +0000 Subject: [PATCH 10/10] Fix node_modules reference --- yarn-project/canary/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/canary/Dockerfile b/yarn-project/canary/Dockerfile index 1832a0076f7..3411ed2ca0a 100644 --- a/yarn-project/canary/Dockerfile +++ b/yarn-project/canary/Dockerfile @@ -23,7 +23,7 @@ RUN ./scripts/update_packages.sh $COMMIT_TAG RUN yarn && yarn build # Copy web artifacts for browser test -RUN cp ../node_modules/@aztec/aztec.js/dest/main.js 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/ +RUN cp ./node_modules/@aztec/circuits.js/resources/aztec3-circuits.wasm src/web/ ENTRYPOINT ["yarn", "test"] \ No newline at end of file