Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(p2p): reenable reqresp integration tests #9343

Merged
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
3 changes: 2 additions & 1 deletion yarn-project/p2p/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ export async function createTestLibP2PService(
mempools: MemPools,
telemetry: TelemetryClient,
port: number = 0,
peerId?: PeerId,
) {
const peerId = await createLibP2PPeerId();
peerId = peerId ?? (await createLibP2PPeerId());
const config = {
tcpAnnounceAddress: `127.0.0.1:${port}`,
udpAnnounceAddress: `127.0.0.1:${port}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// An integration test for the p2p client to test req resp protocols
import { MockL2BlockSource } from '@aztec/archiver/test';
import { type ClientProtocolCircuitVerifier, type WorldStateSynchronizer, mockTx } from '@aztec/circuit-types';
import { EthAddress } from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { sleep } from '@aztec/foundation/sleep';
import { getRandomPort } from '@aztec/foundation/testing';
import { type AztecKVStore } from '@aztec/kv-store';
import { type DataStoreConfig, openTmpStore } from '@aztec/kv-store/utils';

import { SignableENR } from '@chainsafe/enr';
import { describe, expect, it, jest } from '@jest/globals';
import { multiaddr } from '@multiformats/multiaddr';
import getPort from 'get-port';
import { generatePrivateKey } from 'viem/accounts';

import { createP2PClient } from '../../client/index.js';
Expand Down Expand Up @@ -45,25 +44,49 @@ function generatePeerIdPrivateKeys(numberOfPeers: number): string[] {

const NUMBER_OF_PEERS = 2;

// Mock the mempools
const makeMockPools = () => {
return {
txPool: {
addTxs: jest.fn(() => {}),
getTxByHash: jest.fn().mockReturnValue(undefined),
deleteTxs: jest.fn(),
getAllTxs: jest.fn().mockReturnValue([]),
getAllTxHashes: jest.fn().mockReturnValue([]),
getMinedTxHashes: jest.fn().mockReturnValue([]),
getPendingTxHashes: jest.fn().mockReturnValue([]),
getTxStatus: jest.fn().mockReturnValue(undefined),
markAsMined: jest.fn(),
},
attestationPool: {
addAttestations: jest.fn(),
deleteAttestations: jest.fn(),
deleteAttestationsForSlot: jest.fn(),
getAttestationsForSlot: jest.fn().mockReturnValue(undefined),
},
epochProofQuotePool: {
addQuote: jest.fn(),
getQuotes: jest.fn().mockReturnValue([]),
deleteQuotesToEpoch: jest.fn(),
},
};
};

describe('Req Resp p2p client integration', () => {
let txPool: Mockify<TxPool>;
let attestationPool: Mockify<AttestationPool>;
let epochProofQuotePool: Mockify<EpochProofQuotePool>;
let blockSource: MockL2BlockSource;
let l2BlockSource: MockL2BlockSource;
let kvStore: AztecKVStore;
let worldStateSynchronizer: WorldStateSynchronizer;
let worldState: WorldStateSynchronizer;
let proofVerifier: ClientProtocolCircuitVerifier;
let bootNodePort: number;
const logger = createDebugLogger('p2p-client-integration-test');

const getPorts = async (numberOfPeers: number) => {
const ports = [];
for (let i = 0; i < numberOfPeers; i++) {
const port = (await getRandomPort()) || bootNodePort + i + 1;
ports.push(port);
}
return ports;
};
beforeEach(() => {
({ txPool, attestationPool, epochProofQuotePool } = makeMockPools());
});

const getPorts = (numberOfPeers: number) => Promise.all(Array.from({ length: numberOfPeers }, () => getPort()));

const createClients = async (numberOfPeers: number, alwaysTrueVerifier: boolean = true): Promise<P2PClient[]> => {
const clients: P2PClient[] = [];
Expand All @@ -77,11 +100,14 @@ describe('Req Resp p2p client integration', () => {
const enr = SignableENR.createFromPeerId(peerId);

const udpAnnounceAddress = `127.0.0.1:${ports[i]}`;
const publicAddr = multiaddr(convertToMultiaddr(udpAnnounceAddress, 'udp'));
const tcpAnnounceAddress = `127.0.0.1:${ports[i]}`;
const udpPublicAddr = multiaddr(convertToMultiaddr(udpAnnounceAddress, 'udp'));
const tcpPublicAddr = multiaddr(convertToMultiaddr(tcpAnnounceAddress, 'tcp'));

// ENRS must include the network and a discoverable address (udp for discv5)
enr.set(AZTEC_ENR_KEY, Uint8Array.from([AZTEC_NET]));
enr.setLocationMultiaddr(publicAddr);
enr.setLocationMultiaddr(udpPublicAddr);
enr.setLocationMultiaddr(tcpPublicAddr);

return enr.encodeTxt();
}),
Expand All @@ -103,47 +129,14 @@ describe('Req Resp p2p client integration', () => {
udpListenAddress: listenAddr,
tcpAnnounceAddress: addr,
udpAnnounceAddress: addr,
l2QueueSize: 1,
bootstrapNodes: [...otherNodes],
blockCheckIntervalMS: 1000,
peerCheckIntervalMS: 1000,
transactionProtocol: '',
minPeerCount: 1,
maxPeerCount: 10,
keepProvenTxsInPoolFor: 0,
queryForIp: false,
l1ChainId: 31337,
dataDirectory: undefined,
l1Contracts: { rollupAddress: EthAddress.ZERO },
};

txPool = {
addTxs: jest.fn(() => {}),
getTxByHash: jest.fn().mockReturnValue(undefined),
deleteTxs: jest.fn(),
getAllTxs: jest.fn().mockReturnValue([]),
getAllTxHashes: jest.fn().mockReturnValue([]),
getMinedTxHashes: jest.fn().mockReturnValue([]),
getPendingTxHashes: jest.fn().mockReturnValue([]),
getTxStatus: jest.fn().mockReturnValue(undefined),
markAsMined: jest.fn(),
};

attestationPool = {
addAttestations: jest.fn(),
deleteAttestations: jest.fn(),
deleteAttestationsForSlot: jest.fn(),
getAttestationsForSlot: jest.fn().mockReturnValue(undefined),
};

epochProofQuotePool = {
addQuote: jest.fn(),
getQuotes: jest.fn().mockReturnValue([]),
deleteQuotesToEpoch: jest.fn(),
};
} as P2PConfig & DataStoreConfig;

blockSource = new MockL2BlockSource();
blockSource.createBlocks(100);
l2BlockSource = new MockL2BlockSource();
l2BlockSource.createBlocks(100);

proofVerifier = alwaysTrueVerifier ? new AlwaysTrueCircuitVerifier() : new AlwaysFalseCircuitVerifier();
kvStore = openTmpStore();
Expand All @@ -153,7 +146,7 @@ describe('Req Resp p2p client integration', () => {
epochProofQuotePool: epochProofQuotePool as unknown as EpochProofQuotePool,
store: kvStore,
};
const client = await createP2PClient(config, blockSource, proofVerifier, worldStateSynchronizer, undefined, deps);
const client = await createP2PClient(config, l2BlockSource, proofVerifier, worldState, undefined, deps);

await client.start();
clients.push(client);
Expand All @@ -173,8 +166,7 @@ describe('Req Resp p2p client integration', () => {
await sleep(1000);
};

// TODO: re-enable all in file with https://github.com/AztecProtocol/aztec-packages/issues/8707 is fixed
it.skip(
it(
'Returns undefined if unable to find a transaction from another peer',
async () => {
// We want to create a set of nodes and request transaction from them
Expand All @@ -197,7 +189,7 @@ describe('Req Resp p2p client integration', () => {
TEST_TIMEOUT,
);

it.skip(
it(
'Can request a transaction from another peer',
async () => {
// We want to create a set of nodes and request transaction from them
Expand All @@ -223,7 +215,7 @@ describe('Req Resp p2p client integration', () => {
TEST_TIMEOUT,
);

it.skip(
it(
'Will penalize peers that send invalid proofs',
async () => {
// We want to create a set of nodes and request transaction from them
Expand Down Expand Up @@ -255,7 +247,7 @@ describe('Req Resp p2p client integration', () => {
TEST_TIMEOUT,
);

it.skip(
it(
'Will penalize peers that send the wrong transaction',
async () => {
// We want to create a set of nodes and request transaction from them
Expand Down
Loading