Skip to content

Commit

Permalink
refactor: removed isContractDeployed from aztec RPC interface
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 10, 2023
1 parent 123b146 commit 0bbc78a
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async function main() {
.action(async options => {
const client = createAztecRpcClient(options.rpcUrl);
const address = AztecAddress.fromString(options.contractAddress);
const isDeployed = await client.isContractDeployed(address);
const isDeployed = (await client.getContractData(address)) !== undefined;
log(`\n${isDeployed.toString()}\n`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class AztecRPCServer implements AztecRPC {
}

public async getPublicStorageAt(contract: AztecAddress, storageSlot: Fr) {
if (!(await this.isContractDeployed(contract))) {
if ((await this.getContractData(contract)) === undefined) {
throw new Error(`Contract ${contract.toString()} is not deployed`);
}
return await this.node.getPublicStorageAt(contract, storageSlot.value);
Expand All @@ -156,10 +156,6 @@ export class AztecRPCServer implements AztecRPC {
return await this.node.getBlock(blockNumber);
}

public async isContractDeployed(contractAddress: AztecAddress): Promise<boolean> {
return !!(await this.node.getContractData(contractAddress));
}

public async simulateTx(txRequest: TxExecutionRequest) {
if (!txRequest.functionData.isPrivate) {
throw new Error(`Public entrypoints are not allowed`);
Expand Down
3 changes: 0 additions & 3 deletions yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export abstract class BaseWallet implements Wallet {
addContracts(contracts: DeployedContract[]): Promise<void> {
return this.rpc.addContracts(contracts);
}
isContractDeployed(contract: AztecAddress): Promise<boolean> {
return this.rpc.isContractDeployed(contract);
}
simulateTx(txRequest: TxExecutionRequest): Promise<Tx> {
return this.rpc.simulateTx(txRequest);
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AztecAddress, EthAddress } from '@aztec/circuits.js';
import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi';
import { randomBytes } from '@aztec/foundation/crypto';
import { DeployedContract, NodeInfo, Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/types';
import { ContractData, DeployedContract, NodeInfo, Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/types';

import { MockProxy, mock } from 'jest-mock-extended';

Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Contract Class', () => {
beforeEach(() => {
wallet = mock<Wallet>();
wallet.createTxExecutionRequest.mockResolvedValue(mockTxRequest);
wallet.isContractDeployed.mockResolvedValue(true);
wallet.getContractData.mockResolvedValue(ContractData.random());
wallet.sendTx.mockResolvedValue(mockTxHash);
wallet.viewTx.mockResolvedValue(mockViewResultValue);
wallet.getTxReceipt.mockResolvedValue(mockTxReceipt);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Contract extends ContractBase {
* @returns A promise that resolves to a new Contract instance.
*/
public static async create(address: AztecAddress, abi: ContractAbi, wallet: Wallet): Promise<Contract> {
if (!(await wallet.isContractDeployed(address))) {
if ((await wallet.getContractData(address)) === undefined) {
throw new Error('Contract ' + address.toString() + ' is not deployed');
}
return new Contract(address, abi, wallet);
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ describe('e2e_block_building', () => {
expect(receipts.map(r => r.blockNumber)).toEqual(times(TX_COUNT, () => receipts[0].blockNumber));

// Assert all contracts got deployed
const areDeployed = await Promise.all(receipts.map(r => aztecRpcServer.isContractDeployed(r.contractAddress!)));
const areDeployed = await Promise.all(
receipts.map(async r => (await aztecRpcServer.getContractData(r.contractAddress!)) !== undefined),
);
expect(areDeployed).toEqual(times(TX_COUNT, () => true));
}, 60_000);
});
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('e2e_deploy_contract', () => {
expect(isMined).toBe(true);
expect(receiptAfterMined.status).toBe(TxStatus.MINED);
const contractAddress = receipt.contractAddress!;
expect(await aztecRpcServer.isContractDeployed(contractAddress)).toBe(true);
expect(await aztecRpcServer.isContractDeployed(AztecAddress.random())).toBe(false);
expect(await aztecRpcServer.getContractData(contractAddress)).toBeTruthy();
expect(await aztecRpcServer.getContractData(AztecAddress.random())).toBeFalsy();
}, 30_000);

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ describe('e2e_p2p_network', () => {
expect(isMined).toBe(true);
expect(receiptAfterMined.status).toBe(TxStatus.MINED);
const contractAddress = receiptAfterMined.contractAddress!;
expect(await context.rpcServer.isContractDeployed(contractAddress)).toBe(true);
expect(await context.rpcServer.isContractDeployed(AztecAddress.random())).toBe(false);
expect(await context.rpcServer.getContractData(contractAddress)).toBeTruthy();
expect(await context.rpcServer.getContractData(AztecAddress.random())).toBeFalsy();
}
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-compiler/src/typegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function generateConstructor(name: string) {
* Generates the create method for this contract.
* @param name - Name of the contract to derive the ABI name from.
* @returns A create method.
* @remarks We don't use constructor directly because of the async `wallet.isContractDeployed` check.
* @remarks We don't use constructor directly because of the async `wallet.getContractData` call.
*/
function generateCreate(name: string) {
return `
Expand All @@ -86,7 +86,7 @@ function generateCreate(name: string) {
/** The wallet. */
wallet: Wallet,
) {
if (!(await wallet.isContractDeployed(address))) {
if ((await wallet.getContractData(address)) === undefined) {
throw new Error('Contract ' + address.toString() + ' is not deployed');
}
return new ${name}Contract(address, wallet);
Expand Down
7 changes: 0 additions & 7 deletions yarn-project/types/src/interfaces/aztec_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ export interface AztecRPC {
*/
addContracts(contracts: DeployedContract[]): Promise<void>;

/**
* Is an L2 contract deployed at this address?
* @param contract - The contract data address.
* @returns Whether the contract was deployed.
*/
isContractDeployed(contract: AztecAddress): Promise<boolean>;

/**
* Create a transaction for a contract function call with the provided arguments.
* Throws an error if the contract or function is unknown.
Expand Down

0 comments on commit 0bbc78a

Please sign in to comment.