Skip to content

Commit

Permalink
test fix + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 30, 2024
1 parent 50969bf commit 34904d6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { type ContractInstanceWithAddress, SerializableContractInstance } from '

import { DeferredNoteDao } from './deferred_note_dao.js';
import { IncomingNoteDao } from './incoming_note_dao.js';
import { type PxeDatabase } from './pxe_database.js';
import { type OutgoingNoteDao } from './outgoing_note_dao.js';
import { type PxeDatabase } from './pxe_database.js';

/**
* A PXE database backed by LMDB.
Expand Down
71 changes: 44 additions & 27 deletions yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Note Processor', () => {
let ownerIvskM: GrumpkinPrivateKey;
let ownerIvpkM: PublicKey;
let ownerOvKeys: KeyValidationRequest;
let account: AztecAddress;
let account: CompleteAddress;

const app = AztecAddress.random();

Expand Down Expand Up @@ -133,7 +133,7 @@ describe('Note Processor', () => {
const ownerSk = Fr.random();
const allOwnerKeys = deriveKeys(ownerSk);
const partialAddress = Fr.random();
account = CompleteAddress.fromSecretKeyAndPartialAddress(ownerSk, partialAddress).address;
account = CompleteAddress.fromSecretKeyAndPartialAddress(ownerSk, partialAddress);

ownerIvskM = allOwnerKeys.masterIncomingViewingSecretKey;
ownerIvpkM = allOwnerKeys.publicKeys.masterIncomingViewingPublicKey;
Expand All @@ -150,8 +150,19 @@ describe('Note Processor', () => {
aztecNode = mock<AztecNode>();
keyStore = mock<KeyStore>();
simulator = mock<AcirSimulator>();

keyStore.getMasterSecretKey.mockResolvedValue(ownerIvskM);
noteProcessor = await NoteProcessor.create(account, keyStore, database, aztecNode, INITIAL_L2_BLOCK_NUM, simulator);
keyStore.getMasterIncomingViewingPublicKey.mockResolvedValue(account.publicKeys.masterIncomingViewingPublicKey);
keyStore.getMasterOutgoingViewingPublicKey.mockResolvedValue(account.publicKeys.masterOutgoingViewingPublicKey);

noteProcessor = await NoteProcessor.create(
account.address,
keyStore,
database,
aztecNode,
INITIAL_L2_BLOCK_NUM,
simulator,
);

simulator.computeNoteHashAndNullifier.mockImplementation((...args) =>
Promise.resolve({
Expand All @@ -172,12 +183,15 @@ describe('Note Processor', () => {
await noteProcessor.process(blocks, encryptedLogsArr);

expect(addNotesSpy).toHaveBeenCalledTimes(1);
expect(addNotesSpy).toHaveBeenCalledWith([
expect.objectContaining({
...ownedL1NotePayloads[0],
index: BigInt(firstBlockDataStartIndex + 2),
}),
]);
expect(addNotesSpy).toHaveBeenCalledWith(
[
expect.objectContaining({
...ownedL1NotePayloads[0],
index: BigInt(firstBlockDataStartIndex + 2),
}),
],
[],
);
}, 25_000);

it('should store multiple notes that belong to us', async () => {
Expand All @@ -193,23 +207,26 @@ describe('Note Processor', () => {
await noteProcessor.process(blocks, encryptedLogsArr);

expect(addNotesSpy).toHaveBeenCalledTimes(1);
expect(addNotesSpy).toHaveBeenCalledWith([
expect.objectContaining({
...ownedL1NotePayloads[0],
// Index 1 log in the 2nd tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (2 - 1) + 1),
}),
expect.objectContaining({
...ownedL1NotePayloads[1],
// Index 0 log in the 4th tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 0),
}),
expect.objectContaining({
...ownedL1NotePayloads[2],
// Index 2 log in the 4th tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 2),
}),
]);
expect(addNotesSpy).toHaveBeenCalledWith(
[
expect.objectContaining({
...ownedL1NotePayloads[0],
// Index 1 log in the 2nd tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (2 - 1) + 1),
}),
expect.objectContaining({
...ownedL1NotePayloads[1],
// Index 0 log in the 4th tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 0),
}),
expect.objectContaining({
...ownedL1NotePayloads[2],
// Index 2 log in the 4th tx.
index: BigInt(thisBlockDataStartIndex + MAX_NEW_NOTE_HASHES_PER_TX * (4 - 1) + 2),
}),
],
[],
);
}, 30_000);

it('should not store notes that do not belong to us', async () => {
Expand Down Expand Up @@ -255,7 +272,7 @@ describe('Note Processor', () => {
await noteProcessor.process(blocks, encryptedLogsArr);

const newNoteProcessor = await NoteProcessor.create(
account,
account.address,
keyStore,
database,
aztecNode,
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { type Fr } from '@aztec/foundation/fields';
import { type Logger, createDebugLogger } from '@aztec/foundation/log';
import { Timer } from '@aztec/foundation/timer';
import { type KeyStore } from '@aztec/key-store';
import { type AcirSimulator } from '@aztec/simulator';

import { type DeferredNoteDao } from '../database/deferred_note_dao.js';
import { type IncomingNoteDao } from '../database/incoming_note_dao.js';
import { type PxeDatabase } from '../database/index.js';
import { type OutgoingNoteDao } from '../database/outgoing_note_dao.js';
import { getAcirSimulator } from '../simulator/index.js';
import { produceNoteDaos } from './produce_note_dao.js';
import { type AcirSimulator } from '@aztec/simulator';

/**
* Contains all the decrypted data in this array so that we can later batch insert it all into the database.
Expand Down Expand Up @@ -157,7 +157,11 @@ export class NoteProcessor {
const outgoingTaggedNote = TaggedNote.decryptAsOutgoing(log.data, ovskM)!;

if (incomingTaggedNote || outgoingTaggedNote) {
if (incomingTaggedNote && outgoingTaggedNote && !incomingTaggedNote.notePayload.equals(outgoingTaggedNote.notePayload)) {
if (
incomingTaggedNote &&
outgoingTaggedNote &&
!incomingTaggedNote.notePayload.equals(outgoingTaggedNote.notePayload)
) {
throw new Error('Incoming and outgoing note payloads do not match.');
}

Expand Down

0 comments on commit 34904d6

Please sign in to comment.