Skip to content

Commit

Permalink
feat: checking whether contract exists when getting storage (#1296)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
benesjan authored Jul 31, 2023
1 parent 31d290a commit 7688457
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 7688457

Please sign in to comment.