From 7688457560b7be2d915444ad0b5e92f992a42d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Mon, 31 Jul 2023 14:58:11 +0200 Subject: [PATCH] feat: checking whether contract exists when getting storage (#1296) # Description Fixes #1228 # Checklist: - [ ] I have reviewed my diff in github, line by line. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to the issue(s) that it resolves. - [ ] There are no unexpected formatting changes, superfluous debug logs, or commented-out code. - [ ] The branch has been merged or rebased against the head of its merge target. - [ ] I'm happy for the PR to be merged at the reviewer's next convenience. --- .../src/aztec_rpc_server/aztec_rpc_server.test.ts | 7 +++++++ .../aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts | 3 +++ 2 files changed, 10 insertions(+) diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.test.ts index a10be617261..1a4b11657bd 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.test.ts @@ -58,4 +58,11 @@ describe('AztecRpcServer', function () { rpcServer.addAccount(await keyPair.getPrivateKey(), address, partialAddress), ).rejects.toThrow(`Account ${address} already exists`); }); + + it('throws when getting public storage for non-existent contract', async () => { + const contract = AztecAddress.random(); + await expect(async () => await rpcServer.getPublicStorageAt(contract, new Fr(0n))).rejects.toThrow( + `Contract ${contract.toString()} is not deployed`, + ); + }); }); diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index b42f7806586..488b25eb683 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -206,6 +206,9 @@ export class AztecRPCServer implements AztecRPC { * @returns A promise that resolves to an array of note preimage items, each containing its value. */ public async getPublicStorageAt(contract: AztecAddress, storageSlot: Fr) { + if (!(await this.isContractDeployed(contract))) { + throw new Error(`Contract ${contract.toString()} is not deployed`); + } return await this.node.getStorageAt(contract, storageSlot.value); }