Skip to content

Commit

Permalink
chore: fix test + bump timeout in other test
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 6, 2024
1 parent e4fe06e commit 1857108
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
expectedBalancesAfterTransfer2[2] + transferAmount3,
];
await transfer(1, 2, transferAmount3, expectedBalancesAfterTransfer3);
});
}, 120_000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class L1Publisher implements L2BlockReceiver {
* @param block - L2 block to publish.
* @returns True once the tx has been confirmed and is successful, false on revert or interrupt, blocks otherwise.
*/
public async processL2Block(block: L2Block, attestations: Attestation[] | undefined = undefined): Promise<boolean> {
public async processL2Block(block: L2Block, attestations?: Attestation[]): Promise<boolean> {
const ctx = { blockNumber: block.number, blockHash: block.hash().toString() };
// TODO(#4148) Remove this block number check, it's here because we don't currently have proper genesis state on the contract
const lastArchive = block.header.lastArchive.root.toBuffer();
Expand Down
26 changes: 21 additions & 5 deletions yarn-project/sequencer-client/src/sequencer/sequencer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Fr,
GasFees,
GlobalVariables,
IS_DEV_NET,
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
makeEmptyProof,
} from '@aztec/circuits.js';
Expand Down Expand Up @@ -59,10 +60,25 @@ describe('sequencer', () => {
const feeRecipient = AztecAddress.random();
const gasFees = GasFees.empty();

// We mock an attestation
const mockedAttestation = {
isEmpty: false,
v: 27,
r: Fr.random().toString(),
s: Fr.random().toString(),
};

const getAttestations = () => (IS_DEV_NET ? undefined : [mockedAttestation]);

beforeEach(() => {
lastBlockNumber = 0;

publisher = mock<L1Publisher>();

publisher.attest.mockImplementation(_archive => {
return Promise.resolve(mockedAttestation);
});

publisher.isItMyTurnToSubmit.mockResolvedValue(true);

globalVariableBuilder = mock<GlobalVariableBuilder>();
Expand Down Expand Up @@ -158,7 +174,7 @@ describe('sequencer', () => {
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
);
expect(publisher.processL2Block).toHaveBeenCalledTimes(1);
expect(publisher.processL2Block).toHaveBeenCalledWith(block);
expect(publisher.processL2Block).toHaveBeenCalledWith(block, getAttestations());
expect(proverClient.cancelBlock).toHaveBeenCalledTimes(0);
});

Expand Down Expand Up @@ -206,7 +222,7 @@ describe('sequencer', () => {
mockedGlobalVariables,
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
);
expect(publisher.processL2Block).toHaveBeenCalledWith(block);
expect(publisher.processL2Block).toHaveBeenCalledWith(block, getAttestations());
expect(proverClient.cancelBlock).toHaveBeenCalledTimes(0);
});

Expand Down Expand Up @@ -259,7 +275,7 @@ describe('sequencer', () => {
mockedGlobalVariables,
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
);
expect(publisher.processL2Block).toHaveBeenCalledWith(block);
expect(publisher.processL2Block).toHaveBeenCalledWith(block, getAttestations());
expect(p2p.deleteTxs).toHaveBeenCalledWith([doubleSpendTx.getTxHash()]);
expect(proverClient.cancelBlock).toHaveBeenCalledTimes(0);
});
Expand Down Expand Up @@ -308,7 +324,7 @@ describe('sequencer', () => {
mockedGlobalVariables,
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
);
expect(publisher.processL2Block).toHaveBeenCalledWith(block);
expect(publisher.processL2Block).toHaveBeenCalledWith(block, getAttestations());
expect(p2p.deleteTxs).toHaveBeenCalledWith([invalidChainTx.getTxHash()]);
expect(proverClient.cancelBlock).toHaveBeenCalledTimes(0);
});
Expand Down Expand Up @@ -357,7 +373,7 @@ describe('sequencer', () => {
mockedGlobalVariables,
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(new Fr(0n)),
);
expect(publisher.processL2Block).toHaveBeenCalledWith(block);
expect(publisher.processL2Block).toHaveBeenCalledWith(block, getAttestations());
expect(proverClient.cancelBlock).toHaveBeenCalledTimes(0);
});

Expand Down
10 changes: 6 additions & 4 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ export class Sequencer {
...block.getStats(),
} satisfies L2BlockBuiltStats);

// @todo Should collect attestations here
// When in devnet, just have it empty.
const attestations = IS_DEV_NET ? undefined : await this.collectAttestations(block);
const attestations = await this.collectAttestations(block);

await this.publishL2Block(block, attestations);
this.log.info(
Expand All @@ -388,7 +386,7 @@ export class Sequencer {
}
}

protected async collectAttestations(block: L2Block): Promise<Attestation[]> {
protected async collectAttestations(block: L2Block): Promise<Attestation[] | undefined> {
// @todo This should collect attestations properly and fix the ordering of them to make sense
// the current implementation is a PLACEHOLDER and should be nuked from orbit.
// It is assuming that there will only be ONE (1) validator, so only one attestation
Expand All @@ -402,6 +400,10 @@ export class Sequencer {
// ; ;
// / \
// _____________/_ __ \_____________
if (IS_DEV_NET) {
return undefined;
}

const myAttestation = await this.publisher.attest(block.archive.root.toString());
return [myAttestation];
}
Expand Down

0 comments on commit 1857108

Please sign in to comment.