diff --git a/.github/workflows/spartan-test.yml b/.github/workflows/spartan-test.yml index 6ed63e39900..901dbebdb5a 100644 --- a/.github/workflows/spartan-test.yml +++ b/.github/workflows/spartan-test.yml @@ -136,11 +136,10 @@ jobs: tester_ttl: 40 run: | set -eux - cd ./yarn-project/end-to-end/ - ./scripts/setup_local_k8s.sh + ./spartan/scripts/setup_local_k8s.sh export FORCE_COLOR=1 export EARTHLY_BUILD_ARGS="${{ env.EARTHLY_BUILD_ARGS }}" - ../../scripts/earthly-ci --exec-stats -P --no-output ./+network-transfer --values-file=${{ matrix.values_file }} + ./scripts/earthly-ci --exec-stats -P --no-output ./yarn-project/end-to-end/+network-transfer --values-file=${{ matrix.values_file }} success-check: runs-on: ubuntu-20.04 diff --git a/.gitignore b/.gitignore index 71f1e37b5e2..9a2dd48b704 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ build/ .idea cmake-build-debug .terraform* +terraform.tfstate* .bootstrapped .tsbuildinfo diff --git a/spartan/.gitignore b/spartan/.gitignore new file mode 100644 index 00000000000..aa1ec1ea061 --- /dev/null +++ b/spartan/.gitignore @@ -0,0 +1 @@ +*.tgz diff --git a/helm-charts/aztec-network/.helmignore b/spartan/aztec-network/.helmignore similarity index 100% rename from helm-charts/aztec-network/.helmignore rename to spartan/aztec-network/.helmignore diff --git a/helm-charts/aztec-network/Chart.yaml b/spartan/aztec-network/Chart.yaml similarity index 100% rename from helm-charts/aztec-network/Chart.yaml rename to spartan/aztec-network/Chart.yaml diff --git a/helm-charts/aztec-network/files/config/config-prover-env.sh b/spartan/aztec-network/files/config/config-prover-env.sh similarity index 100% rename from helm-charts/aztec-network/files/config/config-prover-env.sh rename to spartan/aztec-network/files/config/config-prover-env.sh diff --git a/helm-charts/aztec-network/files/config/config-validator-env.sh b/spartan/aztec-network/files/config/config-validator-env.sh similarity index 100% rename from helm-charts/aztec-network/files/config/config-validator-env.sh rename to spartan/aztec-network/files/config/config-validator-env.sh diff --git a/helm-charts/aztec-network/files/grafana_dashboards/aztec/aztec-dashboard-all-in-one.json b/spartan/aztec-network/files/grafana_dashboards/aztec/aztec-dashboard-all-in-one.json similarity index 100% rename from helm-charts/aztec-network/files/grafana_dashboards/aztec/aztec-dashboard-all-in-one.json rename to spartan/aztec-network/files/grafana_dashboards/aztec/aztec-dashboard-all-in-one.json diff --git a/helm-charts/aztec-network/files/grafana_dashboards/default.yml b/spartan/aztec-network/files/grafana_dashboards/default.yml similarity index 100% rename from helm-charts/aztec-network/files/grafana_dashboards/default.yml rename to spartan/aztec-network/files/grafana_dashboards/default.yml diff --git a/helm-charts/aztec-network/templates/_helpers.tpl b/spartan/aztec-network/templates/_helpers.tpl similarity index 100% rename from helm-charts/aztec-network/templates/_helpers.tpl rename to spartan/aztec-network/templates/_helpers.tpl diff --git a/helm-charts/aztec-network/templates/anvil.deployment.yaml b/spartan/aztec-network/templates/anvil.deployment.yaml similarity index 100% rename from helm-charts/aztec-network/templates/anvil.deployment.yaml rename to spartan/aztec-network/templates/anvil.deployment.yaml diff --git a/helm-charts/aztec-network/templates/anvil.service.yaml b/spartan/aztec-network/templates/anvil.service.yaml similarity index 100% rename from helm-charts/aztec-network/templates/anvil.service.yaml rename to spartan/aztec-network/templates/anvil.service.yaml diff --git a/helm-charts/aztec-network/templates/boot-node.service.yaml b/spartan/aztec-network/templates/boot-node.service.yaml similarity index 100% rename from helm-charts/aztec-network/templates/boot-node.service.yaml rename to spartan/aztec-network/templates/boot-node.service.yaml diff --git a/helm-charts/aztec-network/templates/boot-node.stateful-set.yaml b/spartan/aztec-network/templates/boot-node.stateful-set.yaml similarity index 92% rename from helm-charts/aztec-network/templates/boot-node.stateful-set.yaml rename to spartan/aztec-network/templates/boot-node.stateful-set.yaml index 3e5456c9d2c..d40c9969f2b 100644 --- a/helm-charts/aztec-network/templates/boot-node.stateful-set.yaml +++ b/spartan/aztec-network/templates/boot-node.stateful-set.yaml @@ -61,6 +61,16 @@ spec: "-c", "source /shared/contracts.env && env && node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js start --node --archiver --sequencer --pxe", ] + livenessProbe: + exec: + command: + - /bin/sh + - -c + - curl -fSs http://127.0.0.1:{{ .Values.bootNode.service.nodePort }}/status + initialDelaySeconds: 30 + periodSeconds: 5 + timeoutSeconds: 30 + failureThreshold: 3 volumeMounts: - name: shared-volume mountPath: /shared @@ -79,6 +89,8 @@ spec: value: "{{ .Values.bootNode.service.nodePort }}" - name: LOG_LEVEL value: "{{ .Values.bootNode.logLevel }}" + - name: LOG_JSON + value: "1" - name: DEBUG value: "{{ .Values.bootNode.debug }}" - name: ETHEREUM_HOST diff --git a/helm-charts/aztec-network/templates/deploy-contracts.config-map.yaml b/spartan/aztec-network/templates/deploy-contracts.config-map.yaml similarity index 100% rename from helm-charts/aztec-network/templates/deploy-contracts.config-map.yaml rename to spartan/aztec-network/templates/deploy-contracts.config-map.yaml diff --git a/helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml b/spartan/aztec-network/templates/deploy-l2-contracts.job.yaml similarity index 100% rename from helm-charts/aztec-network/templates/deploy-l2-contracts.job.yaml rename to spartan/aztec-network/templates/deploy-l2-contracts.job.yaml diff --git a/helm-charts/aztec-network/templates/metrics.yaml b/spartan/aztec-network/templates/metrics.yaml similarity index 100% rename from helm-charts/aztec-network/templates/metrics.yaml rename to spartan/aztec-network/templates/metrics.yaml diff --git a/helm-charts/aztec-network/templates/prover-node.service.yaml b/spartan/aztec-network/templates/prover-node.service.yaml similarity index 100% rename from helm-charts/aztec-network/templates/prover-node.service.yaml rename to spartan/aztec-network/templates/prover-node.service.yaml diff --git a/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml b/spartan/aztec-network/templates/prover-node.stateful-set.yaml similarity index 98% rename from helm-charts/aztec-network/templates/prover-node.stateful-set.yaml rename to spartan/aztec-network/templates/prover-node.stateful-set.yaml index a1804ac40d9..cee694e36b2 100644 --- a/helm-charts/aztec-network/templates/prover-node.stateful-set.yaml +++ b/spartan/aztec-network/templates/prover-node.stateful-set.yaml @@ -59,6 +59,8 @@ spec: value: "{{ .Values.proverNode.service.nodePort }}" - name: LOG_LEVEL value: "{{ .Values.proverNode.logLevel }}" + - name: LOG_JSON + value: "1" - name: DEBUG value: "{{ .Values.proverNode.debug }}" - name: ETHEREUM_HOST diff --git a/helm-charts/aztec-network/templates/pxe.deployment.yaml b/spartan/aztec-network/templates/pxe.deployment.yaml similarity index 90% rename from helm-charts/aztec-network/templates/pxe.deployment.yaml rename to spartan/aztec-network/templates/pxe.deployment.yaml index fefe94987c4..f664837fbd1 100644 --- a/helm-charts/aztec-network/templates/pxe.deployment.yaml +++ b/spartan/aztec-network/templates/pxe.deployment.yaml @@ -29,6 +29,12 @@ spec: value: {{ include "aztec-network.ethereumHost" . | quote }} - name: AZTEC_NODE_URL value: {{ include "aztec-network.bootNodeUrl" . | quote }} + - name: LOG_JSON + value: "1" + - name: LOG_LEVEL + value: "{{ .Values.pxe.logLevel }}" + - name: DEBUG + value: "{{ .Values.pxe.debug }}" ports: - name: http containerPort: {{ .Values.pxe.service.port }} diff --git a/helm-charts/aztec-network/templates/pxe.service.yaml b/spartan/aztec-network/templates/pxe.service.yaml similarity index 100% rename from helm-charts/aztec-network/templates/pxe.service.yaml rename to spartan/aztec-network/templates/pxe.service.yaml diff --git a/helm-charts/aztec-network/templates/tests/run-tests.yaml b/spartan/aztec-network/templates/tests/run-tests.yaml similarity index 76% rename from helm-charts/aztec-network/templates/tests/run-tests.yaml rename to spartan/aztec-network/templates/tests/run-tests.yaml index 2608b24ffbe..bc32cfd7b00 100644 --- a/helm-charts/aztec-network/templates/tests/run-tests.yaml +++ b/spartan/aztec-network/templates/tests/run-tests.yaml @@ -17,3 +17,9 @@ spec: value: {{ .Values.scenario }} - name: PXE_URL value: {{ include "aztec-network.pxeUrl" . | quote }} + - name: DEBUG + value: "aztec:*" + - name: LOG_LEVEL + value: "debug" + - name: LOG_JSON + value: "1" diff --git a/helm-charts/aztec-network/templates/validator.service.yaml b/spartan/aztec-network/templates/validator.service.yaml similarity index 100% rename from helm-charts/aztec-network/templates/validator.service.yaml rename to spartan/aztec-network/templates/validator.service.yaml diff --git a/helm-charts/aztec-network/templates/validator.stateful-set.yaml b/spartan/aztec-network/templates/validator.stateful-set.yaml similarity index 98% rename from helm-charts/aztec-network/templates/validator.stateful-set.yaml rename to spartan/aztec-network/templates/validator.stateful-set.yaml index fec535503c3..864b42daae9 100644 --- a/helm-charts/aztec-network/templates/validator.stateful-set.yaml +++ b/spartan/aztec-network/templates/validator.stateful-set.yaml @@ -59,6 +59,8 @@ spec: value: "{{ .Values.validator.service.nodePort }}" - name: LOG_LEVEL value: "{{ .Values.validator.logLevel }}" + - name: LOG_JSON + value: "1" - name: DEBUG value: "{{ .Values.validator.debug }}" - name: ETHEREUM_HOST diff --git a/helm-charts/aztec-network/values.yaml b/spartan/aztec-network/values.yaml similarity index 98% rename from helm-charts/aztec-network/values.yaml rename to spartan/aztec-network/values.yaml index 13acf19ddbe..1d2650fdf73 100644 --- a/helm-charts/aztec-network/values.yaml +++ b/spartan/aztec-network/values.yaml @@ -67,6 +67,8 @@ proverNode: resources: {} pxe: + logLevel: "debug" + debug: "aztec:*" replicas: 1 service: type: ClusterIP diff --git a/helm-charts/aztec-network/values/3-validators.yaml b/spartan/aztec-network/values/3-validators.yaml similarity index 100% rename from helm-charts/aztec-network/values/3-validators.yaml rename to spartan/aztec-network/values/3-validators.yaml diff --git a/helm-charts/aztec-network/values/default.yaml b/spartan/aztec-network/values/default.yaml similarity index 100% rename from helm-charts/aztec-network/values/default.yaml rename to spartan/aztec-network/values/default.yaml diff --git a/spartan/metrics/.helmignore b/spartan/metrics/.helmignore new file mode 100644 index 00000000000..0e8a0eb36f4 --- /dev/null +++ b/spartan/metrics/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/spartan/metrics/Chart.lock b/spartan/metrics/Chart.lock new file mode 100644 index 00000000000..85b5ec4e110 --- /dev/null +++ b/spartan/metrics/Chart.lock @@ -0,0 +1,9 @@ +dependencies: +- name: opentelemetry-collector + repository: https://open-telemetry.github.io/opentelemetry-helm-charts + version: 0.104.0 +- name: eck-stack + repository: https://helm.elastic.co + version: 0.12.1 +digest: sha256:e95083de14387953eb4093eb2c6b98cf889e532cd097b21b15b1896cfa117e7c +generated: "2024-09-06T19:31:29.086654335-04:00" diff --git a/spartan/metrics/Chart.yaml b/spartan/metrics/Chart.yaml new file mode 100644 index 00000000000..04a896c0fce --- /dev/null +++ b/spartan/metrics/Chart.yaml @@ -0,0 +1,32 @@ +apiVersion: v2 +name: metrics +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" + +dependencies: + - name: opentelemetry-collector + version: 0.104.0 + repository: https://open-telemetry.github.io/opentelemetry-helm-charts + - name: eck-stack + version: 0.12.1 + repository: https://helm.elastic.co diff --git a/spartan/metrics/values.yaml b/spartan/metrics/values.yaml new file mode 100644 index 00000000000..d792b7d9fee --- /dev/null +++ b/spartan/metrics/values.yaml @@ -0,0 +1,76 @@ +opentelemetry-collector: + extraEnvs: + - name: ELASTICSEARCH_PASSWORD + valueFrom: + secretKeyRef: + name: elasticsearch-es-elastic-user + key: elastic + + mode: daemonset + + image: + repository: "otel/opentelemetry-collector-contrib" + + presets: + logsCollection: + enabled: true + includeCollectorLogs: true + kubernetesAttributes: + enabled: true + config: + exporters: + debug: {} + elasticsearch: + endpoint: "https://elasticsearch-es-http.metrics.svc:9200/" + tls: + insecure_skip_verify: true + auth: + authenticator: basicauth + extensions: + basicauth: + client_auth: + username: elastic + password: ${ELASTICSEARCH_PASSWORD} + # The health_check extension is mandatory for this chart. + # Without the health_check extension the collector will fail the readiness and liveliness probes. + # The health_check extension can be modified, but should never be removed. + health_check: + endpoint: ${env:MY_POD_IP}:13133 + processors: + batch: {} + transform: + error_mode: ignore + log_statements: + - context: log + statements: + - merge_maps(attributes, ParseJSON(body), "upsert") where IsMatch(body, "^\\{") + # https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllog + - set(severity_number, 1) where attributes["level"] == "trace" + - set(severity_number, 5) where attributes["level"] == "debug" + - set(severity_number, 9) where attributes["level"] == "info" + - set(severity_number, 13) where attributes["level"] == "warn" + - set(severity_number, 17) where attributes["level"] == "error" + - set(severity_number, 21) where attributes["level"] == "fatal" + - set(body, attributes["message"]) + - set(attributes["level"], nil) + - set(attributes["message"], nil) + receivers: + otlp: + protocols: + http: + endpoint: ${env:MY_POD_IP}:4318 + service: + extensions: [basicauth, health_check] + telemetry: + metrics: + address: ${env:MY_POD_IP}:8888 + pipelines: + logs: + exporters: + - elasticsearch + - debug + processors: + - transform + - batch + receivers: + - otlp diff --git a/yarn-project/end-to-end/scripts/create_k8s_dashboard.sh b/spartan/scripts/create_k8s_dashboard.sh similarity index 100% rename from yarn-project/end-to-end/scripts/create_k8s_dashboard.sh rename to spartan/scripts/create_k8s_dashboard.sh diff --git a/yarn-project/end-to-end/scripts/forward_k8s_dashboard.sh b/spartan/scripts/forward_k8s_dashboard.sh similarity index 100% rename from yarn-project/end-to-end/scripts/forward_k8s_dashboard.sh rename to spartan/scripts/forward_k8s_dashboard.sh diff --git a/spartan/scripts/install_eck_operator.sh b/spartan/scripts/install_eck_operator.sh new file mode 100755 index 00000000000..5923893ea61 --- /dev/null +++ b/spartan/scripts/install_eck_operator.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -ex + +version=2.14.0 + +kubectl create -f https://download.elastic.co/downloads/eck/$version/crds.yaml +kubectl apply -f https://download.elastic.co/downloads/eck/$version/operator.yaml diff --git a/yarn-project/end-to-end/scripts/setup_local_k8s.sh b/spartan/scripts/setup_local_k8s.sh similarity index 100% rename from yarn-project/end-to-end/scripts/setup_local_k8s.sh rename to spartan/scripts/setup_local_k8s.sh diff --git a/spartan/terraform/main.tf b/spartan/terraform/main.tf new file mode 100644 index 00000000000..8174abc71be --- /dev/null +++ b/spartan/terraform/main.tf @@ -0,0 +1,125 @@ +# Configure the AWS Provider +provider "aws" { + region = "us-east-2" # Change this to your preferred region +} + +# Create VPC for EKS +resource "aws_vpc" "spartan_vpc" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "spartan-vpc" + } +} + +# Create an internet gateway +resource "aws_internet_gateway" "spartan_igw" { + vpc_id = aws_vpc.spartan_vpc.id + + tags = { + Name = "spartan-igw" + } +} + +# Create a subnet +resource "aws_subnet" "spartan_subnet" { + vpc_id = aws_vpc.spartan_vpc.id + cidr_block = "10.0.1.0/24" + availability_zone = "us-east-2a" # Change this to match your region + + tags = { + Name = "spartan-subnet" + } +} + +# Create EKS Cluster +resource "aws_eks_cluster" "spartan_cluster" { + name = "spartan-cluster" + role_arn = aws_iam_role.spartan_cluster_role.arn + + vpc_config { + subnet_ids = [aws_subnet.spartan_subnet.id] + } + + depends_on = [aws_iam_role_policy_attachment.spartan_cluster_policy] +} + +# Create IAM role for EKS Cluster +resource "aws_iam_role" "spartan_cluster_role" { + name = "spartan-cluster-role" + + assume_role_policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = "sts:AssumeRole" + Effect = "Allow" + Principal = { + Service = "eks.amazonaws.com" + } + } + ] + }) +} + +# Attach necessary policies to the EKS Cluster role +resource "aws_iam_role_policy_attachment" "spartan_cluster_policy" { + policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" + role = aws_iam_role.spartan_cluster_role.name +} + +# Create EKS Node Group +resource "aws_eks_node_group" "spartan_node_group" { + cluster_name = aws_eks_cluster.spartan_cluster.name + node_group_name = "spartan-node-group" + node_role_arn = aws_iam_role.spartan_node_role.arn + subnet_ids = [aws_subnet.spartan_subnet.id] + + scaling_config { + desired_size = 1 + max_size = 1 + min_size = 1 + } + + instance_types = ["t4g.2xlarge"] + + depends_on = [ + aws_iam_role_policy_attachment.spartan_worker_node_policy, + aws_iam_role_policy_attachment.spartan_cni_policy, + aws_iam_role_policy_attachment.spartan_ecr_policy, + ] +} + +# Create IAM role for EKS Node Group +resource "aws_iam_role" "spartan_node_role" { + name = "spartan-node-role" + + assume_role_policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = "sts:AssumeRole" + Effect = "Allow" + Principal = { + Service = "ec2.amazonaws.com" + } + } + ] + }) +} + +# Attach necessary policies to the EKS Node role +resource "aws_iam_role_policy_attachment" "spartan_worker_node_policy" { + policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy" + role = aws_iam_role.spartan_node_role.name +} + +resource "aws_iam_role_policy_attachment" "spartan_cni_policy" { + policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" + role = aws_iam_role.spartan_node_role.name +} + +resource "aws_iam_role_policy_attachment" "spartan_ecr_policy" { + policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly" + role = aws_iam_role.spartan_node_role.name +} \ No newline at end of file diff --git a/yarn-project/end-to-end/Earthfile b/yarn-project/end-to-end/Earthfile index b59dbd47986..8e8c05c9377 100644 --- a/yarn-project/end-to-end/Earthfile +++ b/yarn-project/end-to-end/Earthfile @@ -92,10 +92,10 @@ NETWORK_TEST: RUN kubectl delete namespace $namespace --ignore-not-found=true --wait=true --now --timeout=10m END - RUN helm install spartan ../../helm-charts/aztec-network \ + RUN helm install spartan ../../spartan/aztec-network/ \ --namespace $namespace \ --create-namespace \ - --values ../../helm-charts/aztec-network/values/$values_file \ + --values ../../spartan/aztec-network/values/$values_file \ --set images.test.image="aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG" \ --set images.aztec.image="aztecprotocol/aztec:$AZTEC_DOCKER_TAG" \ --set test="$test" \ diff --git a/yarn-project/end-to-end/src/spartan/transfer.test.ts b/yarn-project/end-to-end/src/spartan/transfer.test.ts index c47a4e8876e..704b333d5eb 100644 --- a/yarn-project/end-to-end/src/spartan/transfer.test.ts +++ b/yarn-project/end-to-end/src/spartan/transfer.test.ts @@ -1,13 +1,11 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; import { - type AccountWallet, type AccountWalletWithSecretKey, type AztecAddress, ExtendedNote, Fr, Note, type PXE, - type TxHash, computeSecretHash, createCompatibleClient, } from '@aztec/aztec.js'; @@ -35,29 +33,8 @@ const toString = ({ value }: { value: bigint }) => { return str; }; -const addPendingShieldNoteToPXE = async (args: { - amount: bigint; - secretHash: Fr; - txHash: TxHash; - accountAddress: AztecAddress; - assetAddress: AztecAddress; - wallet: AccountWallet; -}) => { - const { accountAddress, assetAddress, amount, secretHash, txHash, wallet } = args; - const note = new Note([new Fr(amount), secretHash]); - const extendedNote = new ExtendedNote( - note, - accountAddress, - assetAddress, - TokenContract.storage.pending_shields.slot, - TokenContract.notes.TransparentNote.id, - txHash, - ); - await wallet.addNote(extendedNote); -}; - describe('token transfer test', () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(10 * 60 * 2000); // 20 minutes const logger = createDebugLogger(`aztec:spartan-test:transfer`); const TOKEN_NAME = 'USDC'; @@ -65,20 +42,20 @@ describe('token transfer test', () => { const TOKEN_DECIMALS = 18n; const MINT_AMOUNT = 20n; - const WALLET_COUNT = 1; + const WALLET_COUNT = 16; const ROUNDS = 5n; let pxe: PXE; let wallets: AccountWalletWithSecretKey[]; let recipientWallet: AccountWalletWithSecretKey; let tokenAddress: AztecAddress; - let tokenAtWallet0: TokenContract; + let tokenAdminWallet: TokenContract; beforeAll(async () => { expect(ROUNDS).toBeLessThanOrEqual(MINT_AMOUNT); - // My guess is that is never proven so if we are waiting for it to prove we wait forever? pxe = await createCompatibleClient(PXE_URL, logger); + { const { accountKeys } = await addAccounts(1, logger, false)({ pxe }); const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], 1)); @@ -89,7 +66,7 @@ describe('token transfer test', () => { logger.verbose(`Recipient Wallet address: ${recipientWallet.getAddress()} registered`); } - const { accountKeys } = await addAccounts(Number(WALLET_COUNT), logger, false)({ pxe }); + const { accountKeys } = await addAccounts(WALLET_COUNT, logger, true)({ pxe }); const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], 1)); wallets = await Promise.all( @@ -114,48 +91,56 @@ describe('token transfer test', () => { .deployed({ timeout: 600 }); tokenAddress = tokenContract.address; - tokenAtWallet0 = await TokenContract.at(tokenAddress, wallets[0]); + tokenAdminWallet = await TokenContract.at(tokenAddress, wallets[0]); logger.verbose(`Minting ${MINT_AMOUNT} public assets to the ${wallets.length} wallets...`); await Promise.all( - wallets.map(w => tokenAtWallet0.methods.mint_public(w.getAddress(), MINT_AMOUNT).send().wait({ timeout: 600 })), + wallets.map(w => tokenAdminWallet.methods.mint_public(w.getAddress(), MINT_AMOUNT).send().wait({ timeout: 600 })), ); logger.verbose(`Minting ${MINT_AMOUNT} private assets to the ${wallets.length} wallets...`); - const secrets: Fr[] = wallets.map(() => Fr.random()); + + const mintSecrets = Array.from({ length: WALLET_COUNT }) + .map(() => Fr.random()) + .map(secret => ({ + secret, + hash: computeSecretHash(secret), + })); const txs = await Promise.all( - wallets.map((w, i) => - tokenAtWallet0.methods.mint_private(MINT_AMOUNT, computeSecretHash(secrets[i])).send().wait({ timeout: 600 }), + mintSecrets.map(({ hash }) => + tokenAdminWallet.methods.mint_private(MINT_AMOUNT, hash).send().wait({ timeout: 600 }), ), ); - wallets.forEach(async (wallet, i) => { - await addPendingShieldNoteToPXE({ - amount: MINT_AMOUNT, - secretHash: computeSecretHash(secrets[i]), - txHash: txs[i].txHash, - accountAddress: wallet.getAddress(), - assetAddress: tokenAddress, - wallet: wallet, - }); - }); + logger.verbose(`Redeeming private assets...`); await Promise.all( - wallets.map(async (w, i) => - (await TokenContract.at(tokenAddress, w)).methods - .redeem_shield(w.getAddress(), MINT_AMOUNT, secrets[i]) - .send() - .wait({ timeout: 600 }), - ), + mintSecrets.map(async ({ secret, hash }, i) => { + const wallet = wallets[i]; + const walletAddress = wallet.getAddress(); + const note = new Note([new Fr(MINT_AMOUNT), hash]); + const extendedNote = new ExtendedNote( + note, + walletAddress, + tokenAddress, + TokenContract.storage.pending_shields.slot, + TokenContract.notes.TransparentNote.id, + txs[i].txHash, + ); + + await pxe.addNote(extendedNote, walletAddress); + const token = await TokenContract.at(tokenAddress, wallet); + await token.methods.redeem_shield(walletAddress, MINT_AMOUNT, secret).send().wait({ timeout: 600 }); + }), ); logger.verbose(`Minting complete.`); }); it('can get info', async () => { - const name = toString(await tokenAtWallet0.methods.private_get_name().simulate()); + const name = toString(await tokenAdminWallet.methods.private_get_name().simulate()); expect(name).toBe(TOKEN_NAME); }); @@ -167,13 +152,13 @@ describe('token transfer test', () => { expect(MINT_AMOUNT).toBe( await (await TokenContract.at(tokenAddress, w)).methods.balance_of_private(w.getAddress()).simulate(), ); - expect(MINT_AMOUNT).toBe(await tokenAtWallet0.methods.balance_of_public(w.getAddress()).simulate()); + expect(MINT_AMOUNT).toBe(await tokenAdminWallet.methods.balance_of_public(w.getAddress()).simulate()); }); expect(0n).toBe( await (await TokenContract.at(tokenAddress, recipientWallet)).methods.balance_of_private(recipient).simulate(), ); - expect(0n).toBe(await tokenAtWallet0.methods.balance_of_public(recipient).simulate()); + expect(0n).toBe(await tokenAdminWallet.methods.balance_of_public(recipient).simulate()); // For each round, make both private and public transfers for (let i = 1n; i <= ROUNDS; i++) { @@ -198,7 +183,7 @@ describe('token transfer test', () => { await (await TokenContract.at(tokenAddress, w)).methods.balance_of_private(w.getAddress()).simulate(), ); expect(MINT_AMOUNT - ROUNDS * transferAmount).toBe( - await tokenAtWallet0.methods.balance_of_public(w.getAddress()).simulate(), + await tokenAdminWallet.methods.balance_of_public(w.getAddress()).simulate(), ); }); @@ -206,7 +191,7 @@ describe('token transfer test', () => { await (await TokenContract.at(tokenAddress, recipientWallet)).methods.balance_of_private(recipient).simulate(), ); expect(ROUNDS * transferAmount * BigInt(wallets.length)).toBe( - await tokenAtWallet0.methods.balance_of_public(recipient).simulate(), + await tokenAdminWallet.methods.balance_of_public(recipient).simulate(), ); }); });