Skip to content

Commit

Permalink
Publicly deploy accounts as needed in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 27, 2024
1 parent 2612a41 commit 13967c3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SlowTreeContract, TokenBlacklistContract, TokenContract } from '@aztec/
import { jest } from '@jest/globals';

import { BITSIZE_TOO_BIG_ERROR, U128_OVERFLOW_ERROR, U128_UNDERFLOW_ERROR } from './fixtures/fixtures.js';
import { setup } from './fixtures/utils.js';
import { publicDeployAccounts, setup } from './fixtures/utils.js';
import { TokenSimulator } from './simulators/token_simulator.js';

const TIMEOUT = 90_000;
Expand Down Expand Up @@ -109,6 +109,7 @@ describe('e2e_blacklist_token_contract', () => {

beforeAll(async () => {
({ teardown, logger, wallets, accounts, cheatCodes } = await setup(4));
await publicDeployAccounts(wallets[0], accounts.slice(0, 3));

slowTree = await SlowTreeContract.deploy(wallets[0]).send().deployed();

Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { LendingContract, PriceFeedContract, TokenContract } from '@aztec/noir-c

import { jest } from '@jest/globals';

import { setup } from './fixtures/utils.js';
import { publicDeployAccounts, setup } from './fixtures/utils.js';
import { LendingAccount, LendingSimulator, TokenSimulator } from './simulators/index.js';

describe('e2e_lending_contract', () => {
Expand Down Expand Up @@ -72,6 +72,7 @@ describe('e2e_lending_contract', () => {
beforeAll(async () => {
({ teardown, logger, cheatCodes: cc, wallet, accounts } = await setup(1));
({ lendingContract, priceFeedContract, collateralAsset, stableCoin } = await deployContracts());
await publicDeployAccounts(wallet, accounts);

lendingAccount = new LendingAccount(accounts[0].address, new Fr(42));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
import { Hex } from 'viem';
import { getAbiItem, getAddress } from 'viem/utils';

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

describe('e2e_public_cross_chain_messaging', () => {
Expand All @@ -36,7 +36,8 @@ describe('e2e_public_cross_chain_messaging', () => {
let outbox: any;

beforeEach(async () => {
const { pxe, deployL1ContractsValues, wallets, logger: logger_, teardown: teardown_ } = await setup(2);
const { pxe, deployL1ContractsValues, wallets, accounts, logger: logger_, teardown: teardown_ } = await setup(2);
await publicDeployAccounts(wallets[0], accounts.slice(0, 2));
crossChainTestHarness = await CrossChainTestHarness.new(
pxe,
deployL1ContractsValues.publicClient,
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { jest } from '@jest/globals';

import { BITSIZE_TOO_BIG_ERROR, U128_OVERFLOW_ERROR, U128_UNDERFLOW_ERROR } from './fixtures/fixtures.js';
import { setup } from './fixtures/utils.js';
import { publicDeployAccounts, setup } from './fixtures/utils.js';
import { TokenSimulator } from './simulators/token_simulator.js';

const TIMEOUT = 90_000;
Expand Down Expand Up @@ -66,6 +66,7 @@ describe('e2e_token_contract', () => {

beforeAll(async () => {
({ teardown, logger, wallets, accounts } = await setup(3));
await publicDeployAccounts(wallets[0], accounts.slice(0, 2));

TokenContract.artifact.functions.forEach(fn => {
const sig = decodeFunctionSignature(fn.name, fn.parameters);
Expand Down
20 changes: 20 additions & 0 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
import { createAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
import {
AccountWalletWithPrivateKey,
AztecAddress,
AztecNode,
BatchCall,
CheatCodes,
CompleteAddress,
Contract,
Expand All @@ -15,13 +17,15 @@ import {
LogType,
PXE,
SentTx,
Wallet,
createAztecNodeClient,
createDebugLogger,
createPXEClient,
deployL1Contracts,
makeFetch,
waitForPXE,
} from '@aztec/aztec.js';
import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
import {
AvailabilityOracleAbi,
AvailabilityOracleBytecode,
Expand Down Expand Up @@ -317,6 +321,22 @@ export async function setup(
};
}

/**
* Registers the contract class used for test accounts and publicly deploys the instances requested.
* Use this when you need to make a public call to an account contract, such as for requesting a public authwit.
* @param sender - Wallet to send the deployment tx.
* @param accountsToDeploy - Which accounts to publicly deploy.
*/
export async function publicDeployAccounts(sender: Wallet, accountsToDeploy: (CompleteAddress | AztecAddress)[]) {
const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a));
const instances = await Promise.all(accountAddressesToDeploy.map(account => sender.getContractInstance(account)));
const batch = new BatchCall(sender, [
(await registerContractClass(sender, SchnorrAccountContractArtifact)).request(),
...instances.map(instance => deployInstance(sender, instance!).request()),
]);
await batch.send().wait();
}

/**
* Sets the timestamp of the next block.
* @param rpcUrl - rpc url of the blockchain instance to connect to
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
import { jest } from '@jest/globals';
import { Chain, HttpTransport, PublicClient, getContract, parseEther } from 'viem';

import { publicDeployAccounts } from '../fixtures/utils.js';
import { CrossChainTestHarness } from './cross_chain_test_harness.js';

// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
Expand Down Expand Up @@ -96,6 +97,8 @@ export const uniswapL1L2TestSuite = (
sponsorAddress = sponsorWallet.getAddress();
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);

await publicDeployAccounts(walletClient, [ownerAddress, sponsorAddress]);

logger('Deploying DAI Portal, initializing and deploying l2 contract...');
daiCrossChainHarness = await CrossChainTestHarness.new(
pxe,
Expand Down

0 comments on commit 13967c3

Please sign in to comment.