Skip to content

Commit

Permalink
refactor: update function names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 21, 2023
1 parent 78f9d31 commit 2ea847c
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export const localAnvil = foundry;

/**
* Wraps an instance of the Aztec RPC Server implementation to a JSON RPC HTTP interface.
*
* TODO rename this as part of #2451
*
* @returns A new instance of the HTTP server.
*/
export function getHttpRpcServer(aztecRpcServer: AztecRPC): JsonRpcServer {
export function createAztecRpcRpcServer(aztecRpcServer: AztecRPC): JsonRpcServer {
const generatedRpcServer = new JsonRpcServer(
aztecRpcServer,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
AztecAddress,
Contract,
GrumpkinScalar,
createAztecRpcClient,
createAztecRpcRpcClient,
createRecipient,
getUnsafeSchnorrAccount,
} from '@aztec/aztec.js';
Expand All @@ -16,7 +16,7 @@ export const privateKey = GrumpkinScalar.fromString('ac0974bec39a17e36ba4a6b4d23

const url = 'http://localhost:8080';

const aztecRpcClient = createAztecRpcClient(url);
const aztecRpcClient = createAztecRpcRpcClient(url);
let wallet: AccountWallet;

const INITIAL_BALANCE = 333n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
EthAddress,
Fr,
computeMessageSecretHash,
createAztecRpcClient,
createAztecRpcRpcClient,
createRecipient,
getL1ContractAddresses,
getUnsafeSchnorrAccount,
Expand Down Expand Up @@ -55,7 +55,7 @@ if (Number(await publicClient.getBlockNumber()) < EXPECTED_FORKED_BLOCK) {

const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]);

const aztecRpcClient = createAztecRpcClient(aztecRpcUrl);
const aztecRpcClient = createAztecRpcRpcClient(aztecRpcUrl);
let wallet: AccountWallet;

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-sandbox/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHttpRpcServer } from '@aztec/aztec-rpc';
import { createAztecRpcRpcServer } from '@aztec/aztec-rpc';
import { DeployL1Contracts } from '@aztec/ethereum';
import { AztecRPC } from '@aztec/types';

Expand All @@ -18,7 +18,7 @@ export function startHttpRpcServer(
deployedL1Contracts: DeployL1Contracts,
port: string | number,
): http.Server {
const rpcServer = getHttpRpcServer(aztecRpcServer);
const rpcServer = createAztecRpcRpcServer(aztecRpcServer);

const app = rpcServer.getApp();
const apiRouter = createApiRouter(deployedL1Contracts);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec.js/src/aztec_rpc_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {

export { makeFetch } from '@aztec/foundation/json-rpc/client';

export const createAztecRpcClient = (url: string, fetch = makeFetch([1, 2, 3], true)): AztecRPC =>
// TODO rename this as part of #2451
export const createAztecRpcRpcClient = (url: string, fetch = makeFetch([1, 2, 3], true)): AztecRPC =>
createJsonRpcClient<AztecRPC>(
url,
{
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sleep } from '@aztec/foundation/sleep';
import zip from 'lodash.zip';

import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' };
import { AccountWallet, AztecRPC, createAztecRpcClient, getSchnorrAccount } from '../index.js';
import { AccountWallet, AztecRPC, createAztecRpcRpcClient, getSchnorrAccount } from '../index.js';

export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
Expand Down Expand Up @@ -73,7 +73,7 @@ export async function deployInitialSandboxAccounts(aztecRpc: AztecRPC) {
* @param rpc - The rpc client connected to the sandbox.
*/
export async function waitForSandbox(rpc?: AztecRPC) {
rpc = rpc ?? createAztecRpcClient(SANDBOX_URL);
rpc = rpc ?? createAztecRpcRpcClient(SANDBOX_URL);
while (true) {
try {
await rpc.getNodeInfo();
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/canary/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createAztecRpcClient, createDebugLogger, makeFetch, waitForSandbox } from '@aztec/aztec.js';
import { createAztecRpcRpcClient, 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:canary_cli');

const setupRPC = async () => {
const aztecRpcClient = createAztecRpcClient(SANDBOX_URL, makeFetch([1, 2, 3, 4, 5], true));
const aztecRpcClient = createAztecRpcRpcClient(SANDBOX_URL, makeFetch([1, 2, 3, 4, 5], true));
await waitForSandbox(aztecRpcClient);
return aztecRpcClient;
};
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TxStatus,
Wallet,
computeMessageSecretHash,
createAztecRpcClient,
createAztecRpcRpcClient,
createDebugLogger,
getL1ContractAddresses,
getSandboxAccountsWallets,
Expand Down Expand Up @@ -50,7 +50,7 @@ const ethRpcUrl = ETHEREUM_HOST;

const hdAccount = mnemonicToAccount(MNEMONIC);

const aztecRpcClient = createAztecRpcClient(aztecRpcUrl);
const aztecRpcClient = createAztecRpcRpcClient(aztecRpcUrl);
let wallet: Wallet;

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/cli/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AztecRPC, createAztecRpcClient } from '@aztec/aztec.js';
import { AztecRPC, createAztecRpcRpcClient } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { fileURLToPath } from '@aztec/foundation/url';

Expand All @@ -12,7 +12,7 @@ import { gtr, ltr, satisfies, valid } from 'semver';
* @returns An RPC client.
*/
export function createClient(rpcUrl: string) {
return createAztecRpcClient(rpcUrl);
return createAztecRpcRpcClient(rpcUrl);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/aztec_rpc_sandbox.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { aztecRpcTestSuite } from '@aztec/aztec-rpc';
import { createAztecRpcClient, waitForSandbox } from '@aztec/aztec.js';
import { createAztecRpcRpcClient, waitForSandbox } from '@aztec/aztec.js';

const { SANDBOX_URL = 'http://localhost:8080' } = process.env;

const setup = async () => {
const aztecRpc = createAztecRpcClient(SANDBOX_URL);
const aztecRpc = createAztecRpcRpcClient(SANDBOX_URL);
await waitForSandbox(aztecRpc);
return aztecRpc;
};
Expand Down
14 changes: 9 additions & 5 deletions yarn-project/end-to-end/src/canary/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL

beforeAll(async () => {
server = setup();
testClient = AztecJs.createAztecRpcClient(SANDBOX_URL!);
testClient = AztecJs.createAztecRpcRpcClient(SANDBOX_URL!);
await AztecJs.waitForSandbox(testClient);

app = new Koa();
Expand Down Expand Up @@ -93,7 +93,11 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL
it('Creates an account', async () => {
const result = await page.evaluate(
async (rpcUrl, privateKeyString) => {
const { GrumpkinScalar, createAztecRpcClient, getUnsafeSchnorrAccount } = window.AztecJs;
const {
GrumpkinScalar,
createAztecRpcRpcClient: createAztecRpcClient,
getUnsafeSchnorrAccount,
} = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!);
const privateKey = GrumpkinScalar.fromString(privateKeyString);
const account = getUnsafeSchnorrAccount(client, privateKey);
Expand All @@ -118,7 +122,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL
it("Gets the owner's balance", async () => {
const result = await page.evaluate(
async (rpcUrl, contractAddress, TokenContractAbi) => {
const { Contract, AztecAddress, createAztecRpcClient } = window.AztecJs;
const { Contract, AztecAddress, createAztecRpcRpcClient: createAztecRpcClient } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!);
const owner = (await client.getRegisteredAccounts())[0].address;
const [wallet] = await AztecJs.getSandboxAccountsWallets(client);
Expand All @@ -137,7 +141,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL
const result = await page.evaluate(
async (rpcUrl, contractAddress, transferAmount, TokenContractAbi) => {
console.log(`Starting transfer tx`);
const { AztecAddress, Contract, createAztecRpcClient } = window.AztecJs;
const { AztecAddress, Contract, createAztecRpcRpcClient: createAztecRpcClient } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!);
const accounts = await client.getRegisteredAccounts();
const receiver = accounts[1].address;
Expand All @@ -161,7 +165,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL
const {
GrumpkinScalar,
DeployMethod,
createAztecRpcClient,
createAztecRpcRpcClient: createAztecRpcClient,
getUnsafeSchnorrAccount,
Contract,
Fr,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
AztecRPC,
Fr,
computeMessageSecretHash,
createAztecRpcClient,
createAztecRpcRpcClient,
createDebugLogger,
getSchnorrAccount,
waitForSandbox,
Expand All @@ -21,7 +21,7 @@ describe('e2e_sandbox_example', () => {
const logger = createDebugLogger('token');

// We create AztecRPC client connected to the sandbox URL
const aztecRpc = createAztecRpcClient(SANDBOX_URL);
const aztecRpc = createAztecRpcRpcClient(SANDBOX_URL);
// Wait for sandbox to be ready
await waitForSandbox(aztecRpc);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EthCheatCodes,
Wallet,
createAccounts,
createAztecRpcClient as createJsonRpcClient,
createAztecRpcRpcClient as createJsonRpcClient,
getL1ContractAddresses,
getSandboxAccountsWallets,
} from '@aztec/aztec.js';
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
L2BlockL2Logs,
computeMessageSecretHash,
createAccount,
createAztecRpcClient,
createAztecRpcRpcClient,
getSandboxAccountsWallets,
waitForSandbox,
} from '@aztec/aztec.js';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('guides/dapp/testing', () => {

describe('on local sandbox', () => {
beforeAll(async () => {
const rpc = createAztecRpcClient(SANDBOX_URL);
const rpc = createAztecRpcRpcClient(SANDBOX_URL);
await waitForSandbox(rpc);
});

Expand All @@ -64,7 +64,7 @@ describe('guides/dapp/testing', () => {
let token: TokenContract;

beforeEach(async () => {
rpc = createAztecRpcClient(SANDBOX_URL);
rpc = createAztecRpcRpcClient(SANDBOX_URL);
owner = await createAccount(rpc);
recipient = await createAccount(rpc);
token = await TokenContract.deploy(owner).send().deployed();
Expand All @@ -90,7 +90,7 @@ describe('guides/dapp/testing', () => {

beforeEach(async () => {
// docs:start:use-existing-wallets
rpc = createAztecRpcClient(SANDBOX_URL);
rpc = createAztecRpcRpcClient(SANDBOX_URL);
[owner, recipient] = await getSandboxAccountsWallets(rpc);
token = await TokenContract.deploy(owner).send().deployed();
await token.methods._initialize(owner.getAddress()).send().wait();
Expand All @@ -114,7 +114,7 @@ describe('guides/dapp/testing', () => {
let cheats: CheatCodes;

beforeAll(async () => {
rpc = createAztecRpcClient(SANDBOX_URL);
rpc = createAztecRpcRpcClient(SANDBOX_URL);
owner = await createAccount(rpc);
testContract = await TestContract.deploy(owner).send().deployed();
cheats = await CheatCodes.create(ETHEREUM_HOST, rpc);
Expand All @@ -139,7 +139,7 @@ describe('guides/dapp/testing', () => {
let ownerSlot: Fr;

beforeAll(async () => {
rpc = createAztecRpcClient(SANDBOX_URL);
rpc = createAztecRpcRpcClient(SANDBOX_URL);
owner = await createAccount(rpc);
recipient = await createAccount(rpc);
testContract = await TestContract.deploy(owner).send().deployed();
Expand Down

0 comments on commit 2ea847c

Please sign in to comment.