Skip to content

Commit

Permalink
chore: fix the transfer test we run in kind clusters (#8796)
Browse files Browse the repository at this point in the history
allow retry in connection to pxe
rename the nightly job to correct nomenclature
update sandbox to assume every block is proven
  • Loading branch information
just-mitch authored and Rumata888 committed Sep 27, 2024
1 parent bd3f92b commit 3997a57
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 65 deletions.
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...`);

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

0 comments on commit 3997a57

Please sign in to comment.