Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix the transfer test we run in kind clusters #8796

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run spartan network tests
name: KIND network tests
on:
workflow_dispatch:
schedule:
Expand Down
19 changes: 14 additions & 5 deletions yarn-project/aztec.js/src/rpc_clients/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type PXE } from '@aztec/circuit-types';
import { type DebugLogger } from '@aztec/foundation/log';
import { NoRetryError } from '@aztec/foundation/retry';
import { NoRetryError, makeBackoff, retry } from '@aztec/foundation/retry';

import axios, { type AxiosError, type AxiosResponse } from 'axios';

Expand All @@ -12,10 +12,9 @@ import { createPXEClient } from '../pxe_client.js';
* @param rpcMethod - The RPC method to call.
* @param body - The body of the request.
* @param useApiEndpoints - Whether to use the API endpoints or inject the method in the body.
* @param _noRetry - Whether to retry on non-server errors.
* @returns The response data.
*/
async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean, _noRetry = true) {
async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) {
let resp: AxiosResponse;
if (useApiEndpoints) {
resp = await axios
Expand Down Expand Up @@ -62,8 +61,18 @@ async function axiosFetch(host: string, rpcMethod: string, body: any, useApiEndp
* @param _logger - Debug logger to warn version incompatibilities.
* @returns A PXE client.
*/
export function createCompatibleClient(rpcUrl: string, _logger: DebugLogger): Promise<PXE> {
export function createCompatibleClient(rpcUrl: string, logger: DebugLogger): Promise<PXE> {
// Use axios due to timeout issues with fetch when proving TXs.
const pxe = createPXEClient(rpcUrl, axiosFetch);
const fetch = async (host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) => {
return await retry(
() => axiosFetch(host, rpcMethod, body, useApiEndpoints),
`JsonRpcClient request ${rpcMethod} to ${host}`,
makeBackoff([1, 2, 3]),
logger,
false,
);
};
const pxe = createPXEClient(rpcUrl, fetch);

return Promise.resolve(pxe);
}
4 changes: 3 additions & 1 deletion yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {

let watcher: AnvilTestWatcher | undefined = undefined;
if (!aztecNodeConfig.p2pEnabled) {
const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount);
const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount, undefined, {
assumeProvenThroughBlockNumber: Number.MAX_SAFE_INTEGER,
});

const chain = aztecNodeConfig.l1RpcUrl
? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/end-to-end/scripts/network_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

set -eu

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Main positional parameter
TEST="$1"

Expand All @@ -28,7 +30,7 @@ fi

if ! docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q "aztecprotocol/aztec:$AZTEC_DOCKER_TAG" || \
! docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q "aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG"; then
echo "Docker images not found. They need to be built with 'earthly ./yarn-project/+export-test-images' or otherwise tagged with aztecprotocol/aztec:$AZTEC_DOCKER_TAG and aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG."
echo "Docker images not found. They need to be built with 'earthly ./yarn-project/+export-e2e-test-images' or otherwise tagged with aztecprotocol/aztec:$AZTEC_DOCKER_TAG and aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG."
exit 1
fi

Expand All @@ -42,7 +44,7 @@ if [ "$FRESH_INSTALL" = "true" ]; then
fi

# Install the Helm chart
helm install spartan spartan/aztec-network/ \
helm install spartan "$(git rev-parse --show-toplevel)/spartan/aztec-network/" \
--namespace "$NAMESPACE" \
--create-namespace \
--values "$(git rev-parse --show-toplevel)/spartan/aztec-network/values/$VALUES_FILE" \
Expand Down
57 changes: 1 addition & 56 deletions yarn-project/end-to-end/src/spartan/transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import {
type AccountWalletWithSecretKey,
type AztecAddress,
ExtendedNote,
Fr,
Note,
type PXE,
computeSecretHash,
createCompatibleClient,
} from '@aztec/aztec.js';
import { createDebugLogger } from '@aztec/foundation/log';
Expand Down Expand Up @@ -66,7 +63,7 @@ describe('token transfer test', () => {
logger.verbose(`Recipient Wallet address: ${recipientWallet.getAddress()} registered`);
}

const { accountKeys } = await addAccounts(WALLET_COUNT, logger, true)({ pxe });
const { accountKeys } = await addAccounts(WALLET_COUNT, logger, false)({ pxe });
const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], 1));

wallets = await Promise.all(
Expand Down Expand Up @@ -99,43 +96,6 @@ describe('token transfer test', () => {
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...`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels odd to not run the private transfers at all, but it satisfies the criteria for the test, and makes it simpler to run because you avoid some of your issues 🤷


const mintSecrets = Array.from({ length: WALLET_COUNT })
.map(() => Fr.random())
.map(secret => ({
secret,
hash: computeSecretHash(secret),
}));

const txs = await Promise.all(
mintSecrets.map(({ hash }) =>
tokenAdminWallet.methods.mint_private(MINT_AMOUNT, hash).send().wait({ timeout: 600 }),
),
);

logger.verbose(`Redeeming private assets...`);

await Promise.all(
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.`);
});

Expand All @@ -149,23 +109,14 @@ describe('token transfer test', () => {
const transferAmount = 1n;

wallets.forEach(async w => {
expect(MINT_AMOUNT).toBe(
await (await TokenContract.at(tokenAddress, w)).methods.balance_of_private(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 tokenAdminWallet.methods.balance_of_public(recipient).simulate());

// For each round, make both private and public transfers
for (let i = 1n; i <= ROUNDS; i++) {
const txs = await Promise.all([
...wallets.map(async w =>
(await TokenContract.at(tokenAddress, w)).methods.transfer(recipient, transferAmount),
),
...wallets.map(async w =>
(
await TokenContract.at(tokenAddress, w)
Expand All @@ -179,17 +130,11 @@ describe('token transfer test', () => {
}

wallets.forEach(async w => {
expect(MINT_AMOUNT - ROUNDS * transferAmount).toBe(
await (await TokenContract.at(tokenAddress, w)).methods.balance_of_private(w.getAddress()).simulate(),
);
expect(MINT_AMOUNT - ROUNDS * transferAmount).toBe(
await tokenAdminWallet.methods.balance_of_public(w.getAddress()).simulate(),
);
});

expect(ROUNDS * transferAmount * BigInt(wallets.length)).toBe(
await (await TokenContract.at(tokenAddress, recipientWallet)).methods.balance_of_private(recipient).simulate(),
);
expect(ROUNDS * transferAmount * BigInt(wallets.length)).toBe(
await tokenAdminWallet.methods.balance_of_public(recipient).simulate(),
);
Expand Down
Loading