Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ describe('Utility Execution test suite', () => {

capsuleStore.getCapsule.mockResolvedValueOnce(capsule);

utilityExecutionOracle.setCapsule(contractAddress, slot, capsule, scope);
await utilityExecutionOracle.setCapsule(contractAddress, slot, capsule, scope);
await utilityExecutionOracle.getCapsule(contractAddress, slot, capsule.length, scope);
utilityExecutionOracle.deleteCapsule(contractAddress, slot, scope);
await utilityExecutionOracle.deleteCapsule(contractAddress, slot, scope);
await utilityExecutionOracle.copyCapsule(contractAddress, srcSlot, dstSlot, 1, scope);

expect(capsuleStore.setCapsule).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
);
}

public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): void {
public setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], scope: AztecAddress): Promise<void> {
this.#assertOwnContract(contractAddress);
this.capsuleService.setCapsule(contractAddress, slot, capsule, this.changeSetId, scope);
return this.capsuleService.setCapsule(contractAddress, slot, capsule, this.changeSetId, scope);
}

public async getCapsule(
Expand All @@ -741,9 +741,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
return values ? Option.some(values) : Option.none({ length: tSize });
}

public deleteCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): void {
public deleteCapsule(contractAddress: AztecAddress, slot: Fr, scope: AztecAddress): Promise<void> {
this.#assertOwnContract(contractAddress);
this.capsuleService.deleteCapsule(contractAddress, slot, this.changeSetId, scope);
return this.capsuleService.deleteCapsule(contractAddress, slot, this.changeSetId, scope);
}

public copyCapsule(
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class PXE {
readCachedNode,
store,
anchorBlockStore,
[noteStore, privateEventStore, factStore],
[noteStore, privateEventStore, factStore, capsuleStore, recipientTaggingStore],
l2TipsStore,
contractSyncService,
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
const capsuleStore = new CapsuleStore(kvStore);

const changeSetId = 'fixture-change-set';
capsuleStore.beginChangeSet(changeSetId);

const contractAddress = AztecAddress.fromBigIntUnsafe(2n);
const scope = AztecAddress.fromBigIntUnsafe(3n);

// Three setCapsule calls (2-element, 1-element, 0-element value vector) pin every value-encoding length case.
capsuleStore.setCapsule(contractAddress, new Fr(5n), [new Fr(7n), new Fr(11n)], changeSetId, scope);
capsuleStore.setCapsule(contractAddress, new Fr(13n), [new Fr(17n)], changeSetId, scope);
capsuleStore.setCapsule(contractAddress, new Fr(19n), [], changeSetId, scope);
await capsuleStore.setCapsule(contractAddress, new Fr(5n), [new Fr(7n), new Fr(11n)], changeSetId, scope);
await capsuleStore.setCapsule(contractAddress, new Fr(13n), [new Fr(17n)], changeSetId, scope);
await capsuleStore.setCapsule(contractAddress, new Fr(19n), [], changeSetId, scope);
await kvStore.transactionAsync(() => capsuleStore.commitChangeSet(changeSetId));
},
snapshotStore: async kvStore => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('CapsuleService', () => {
disallowedScope = await AztecAddress.random();
capsuleStore = new CapsuleStore(await openTmpStore('capsule_service_test'));
capsuleService = new CapsuleService(capsuleStore, [allowedScope]);
capsuleStore.beginChangeSet(changeSetId);
});

describe('scope enforcement', () => {
Expand Down Expand Up @@ -72,15 +73,15 @@ describe('CapsuleService', () => {
const scope = allowedScope;

// setCapsule + getCapsule
capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, slot, changeSetId, scope)).toEqual(capsule);

// deleteCapsule
capsuleService.deleteCapsule(contract, slot, changeSetId, scope);
await capsuleService.deleteCapsule(contract, slot, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, slot, changeSetId, scope)).toBeNull();

// copyCapsule
capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.copyCapsule(contract, slot, new Fr(5), 1, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, new Fr(5), changeSetId, scope)).toEqual(capsule);

Expand All @@ -99,15 +100,15 @@ describe('CapsuleService', () => {
const scope = AztecAddress.ZERO;

// setCapsule + getCapsule
capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, slot, changeSetId, scope)).toEqual(capsule);

// deleteCapsule
capsuleService.deleteCapsule(contract, slot, changeSetId, scope);
await capsuleService.deleteCapsule(contract, slot, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, slot, changeSetId, scope)).toBeNull();

// copyCapsule
capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.setCapsule(contract, slot, capsule, changeSetId, scope);
await capsuleService.copyCapsule(contract, slot, new Fr(5), 1, changeSetId, scope);
expect(await capsuleService.getCapsule(contract, new Fr(5), changeSetId, scope)).toEqual(capsule);

Expand Down
14 changes: 10 additions & 4 deletions yarn-project/pxe/src/storage/capsule_store/capsule_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ export class CapsuleService {
this.allowedScopes = [...allowedScopes, AztecAddress.ZERO];
}

setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], changeSetId: ChangeSetId, scope: AztecAddress) {
setCapsule(
contractAddress: AztecAddress,
slot: Fr,
capsule: Fr[],
changeSetId: ChangeSetId,
scope: AztecAddress,
): Promise<void> {
assertAllowedScope(scope, this.allowedScopes);
this.capsuleStore.setCapsule(contractAddress, slot, capsule, changeSetId, scope);
return this.capsuleStore.setCapsule(contractAddress, slot, capsule, changeSetId, scope);
}

async getCapsule(
Expand All @@ -46,9 +52,9 @@ export class CapsuleService {
return maybeTransientCapsule ?? (await this.capsuleStore.getCapsule(contractAddress, slot, changeSetId, scope));
}

deleteCapsule(contractAddress: AztecAddress, slot: Fr, changeSetId: ChangeSetId, scope: AztecAddress) {
deleteCapsule(contractAddress: AztecAddress, slot: Fr, changeSetId: ChangeSetId, scope: AztecAddress): Promise<void> {
assertAllowedScope(scope, this.allowedScopes);
this.capsuleStore.deleteCapsule(contractAddress, slot, changeSetId, scope);
return this.capsuleStore.deleteCapsule(contractAddress, slot, changeSetId, scope);
}

copyCapsule(
Expand Down
Loading
Loading