@aztec/p2p 0.7.10 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +7 -9
- package/dest/client/mocks.d.ts +5 -0
- package/dest/client/mocks.d.ts.map +1 -1
- package/dest/client/mocks.js +8 -1
- package/dest/service/libp2p_service.d.ts +3 -2
- package/dest/service/libp2p_service.d.ts.map +1 -1
- package/dest/service/libp2p_service.js +15 -9
- package/package.json +54 -5
- package/src/bootstrap/bootstrap.ts +6 -8
- package/src/client/mocks.ts +8 -0
- package/src/service/libp2p_service.ts +14 -7
- package/.eslintrc.cjs +0 -1
- package/.tsbuildinfo +0 -1
- package/dest/client/p2p_client.test.d.ts +0 -2
- package/dest/client/p2p_client.test.d.ts.map +0 -1
- package/dest/client/p2p_client.test.js +0 -58
- package/dest/service/known_txs.test.d.ts +0 -2
- package/dest/service/known_txs.test.d.ts.map +0 -1
- package/dest/service/known_txs.test.js +0 -34
- package/dest/service/tx_messages.test.d.ts +0 -2
- package/dest/service/tx_messages.test.d.ts.map +0 -1
- package/dest/service/tx_messages.test.js +0 -48
- package/dest/tx_pool/tx_pool.test.d.ts +0 -2
- package/dest/tx_pool/tx_pool.test.d.ts.map +0 -1
- package/dest/tx_pool/tx_pool.test.js +0 -20
- package/src/client/p2p_client.test.ts +0 -79
- package/src/service/known_txs.test.ts +0 -47
- package/src/service/tx_messages.test.ts +0 -67
- package/src/tx_pool/tx_pool.test.ts +0 -25
- package/tsconfig.json +0 -20
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { L2BlockSource, mockTx } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
import { expect, jest } from '@jest/globals';
|
|
4
|
-
|
|
5
|
-
import { P2PService } from '../index.js';
|
|
6
|
-
import { TxPool } from '../tx_pool/index.js';
|
|
7
|
-
import { MockBlockSource } from './mocks.js';
|
|
8
|
-
import { P2PClient } from './p2p_client.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Mockify helper for testing purposes.
|
|
12
|
-
*/
|
|
13
|
-
type Mockify<T> = {
|
|
14
|
-
[P in keyof T]: ReturnType<typeof jest.fn>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('In-Memory P2P Client', () => {
|
|
18
|
-
let txPool: Mockify<TxPool>;
|
|
19
|
-
let blockSource: L2BlockSource;
|
|
20
|
-
let p2pService: Mockify<P2PService>;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
txPool = {
|
|
24
|
-
addTxs: jest.fn(),
|
|
25
|
-
getTxByHash: jest.fn().mockReturnValue(undefined),
|
|
26
|
-
deleteTxs: jest.fn(),
|
|
27
|
-
getAllTxs: jest.fn().mockReturnValue([]),
|
|
28
|
-
getAllTxHashes: jest.fn().mockReturnValue([]),
|
|
29
|
-
hasTx: jest.fn().mockReturnValue(false),
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
p2pService = {
|
|
33
|
-
start: jest.fn(),
|
|
34
|
-
stop: jest.fn(),
|
|
35
|
-
propagateTx: jest.fn(),
|
|
36
|
-
settledTxs: jest.fn(),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
blockSource = new MockBlockSource();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('can start & stop', async () => {
|
|
43
|
-
const client = new P2PClient(blockSource, txPool, p2pService);
|
|
44
|
-
expect(await client.isReady()).toEqual(false);
|
|
45
|
-
|
|
46
|
-
await client.start();
|
|
47
|
-
expect(await client.isReady()).toEqual(true);
|
|
48
|
-
|
|
49
|
-
await client.stop();
|
|
50
|
-
expect(await client.isReady()).toEqual(false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('adds txs to pool', async () => {
|
|
54
|
-
const client = new P2PClient(blockSource, txPool, p2pService);
|
|
55
|
-
await client.start();
|
|
56
|
-
const tx1 = mockTx();
|
|
57
|
-
const tx2 = mockTx();
|
|
58
|
-
await client.sendTx(tx1);
|
|
59
|
-
await client.sendTx(tx2);
|
|
60
|
-
|
|
61
|
-
expect(txPool.addTxs).toHaveBeenCalledTimes(2);
|
|
62
|
-
await client.stop();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('rejects txs after being stopped', async () => {
|
|
66
|
-
const client = new P2PClient(blockSource, txPool, p2pService);
|
|
67
|
-
await client.start();
|
|
68
|
-
const tx1 = mockTx();
|
|
69
|
-
const tx2 = mockTx();
|
|
70
|
-
await client.sendTx(tx1);
|
|
71
|
-
await client.sendTx(tx2);
|
|
72
|
-
|
|
73
|
-
expect(txPool.addTxs).toHaveBeenCalledTimes(2);
|
|
74
|
-
await client.stop();
|
|
75
|
-
const tx3 = mockTx();
|
|
76
|
-
await expect(client.sendTx(tx3)).rejects.toThrow();
|
|
77
|
-
expect(txPool.addTxs).toHaveBeenCalledTimes(2);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
|
-
import { TxHash } from '@aztec/types';
|
|
3
|
-
|
|
4
|
-
import { expect } from '@jest/globals';
|
|
5
|
-
import { Ed25519PeerId, PeerId } from '@libp2p/interface-peer-id';
|
|
6
|
-
import { mock } from 'jest-mock-extended';
|
|
7
|
-
|
|
8
|
-
import { KnownTxLookup } from './known_txs.js';
|
|
9
|
-
|
|
10
|
-
const createMockPeerId = (peerId: string): PeerId => {
|
|
11
|
-
return mock<Ed25519PeerId>({
|
|
12
|
-
toString: () => peerId,
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const createTxHash = () => {
|
|
17
|
-
return new TxHash(randomBytes(32));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
describe('Known Txs', () => {
|
|
21
|
-
it('Returns false when a peer has not seen a tx', () => {
|
|
22
|
-
const knownTxs = new KnownTxLookup();
|
|
23
|
-
|
|
24
|
-
const peer = createMockPeerId('Peer 1');
|
|
25
|
-
const txHash = createTxHash();
|
|
26
|
-
|
|
27
|
-
expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(false);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('Returns true when a peer has seen a tx', () => {
|
|
31
|
-
const knownTxs = new KnownTxLookup();
|
|
32
|
-
|
|
33
|
-
const peer = createMockPeerId('Peer 1');
|
|
34
|
-
const peer2 = createMockPeerId('Peer 2');
|
|
35
|
-
const txHash = createTxHash();
|
|
36
|
-
|
|
37
|
-
knownTxs.addPeerForTx(peer, txHash.toString());
|
|
38
|
-
|
|
39
|
-
expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(true);
|
|
40
|
-
expect(knownTxs.hasPeerSeenTx(peer2, txHash.toString())).toEqual(false);
|
|
41
|
-
|
|
42
|
-
knownTxs.addPeerForTx(peer2, txHash.toString());
|
|
43
|
-
|
|
44
|
-
expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(true);
|
|
45
|
-
expect(knownTxs.hasPeerSeenTx(peer2, txHash.toString())).toEqual(true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Tx, TxHash, mockTx } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
import { expect } from '@jest/globals';
|
|
4
|
-
import { randomBytes } from 'crypto';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
Messages,
|
|
8
|
-
createGetTransactionsRequestMessage,
|
|
9
|
-
createTransactionHashesMessage,
|
|
10
|
-
createTransactionsMessage,
|
|
11
|
-
decodeGetTransactionsRequestMessage,
|
|
12
|
-
decodeMessageType,
|
|
13
|
-
decodeTransactionHashesMessage,
|
|
14
|
-
decodeTransactionsMessage,
|
|
15
|
-
fromTxMessage,
|
|
16
|
-
getEncodedMessage,
|
|
17
|
-
toTxMessage,
|
|
18
|
-
} from './tx_messages.js';
|
|
19
|
-
|
|
20
|
-
const makeTxHash = () => {
|
|
21
|
-
return new TxHash(randomBytes(32));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const verifyTx = (actual: Tx, expected: Tx) => {
|
|
25
|
-
expect(actual.data!.toBuffer()).toEqual(expected.data?.toBuffer());
|
|
26
|
-
expect(actual.proof!.toBuffer()).toEqual(expected.proof!.toBuffer());
|
|
27
|
-
expect(actual.encryptedLogs!.toBuffer()).toEqual(expected.encryptedLogs?.toBuffer());
|
|
28
|
-
expect(actual.newContracts!.length).toEqual(expected.newContracts!.length);
|
|
29
|
-
for (let i = 0; i < actual.newContracts!.length; i++) {
|
|
30
|
-
expect(actual.newContracts![i].toBuffer()).toEqual(expected.newContracts![i].toBuffer());
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
describe('Messages', () => {
|
|
35
|
-
it('Correctly serialises and deserialises a single private transaction', () => {
|
|
36
|
-
const transaction = mockTx();
|
|
37
|
-
const message = toTxMessage(transaction);
|
|
38
|
-
const decodedTransaction = fromTxMessage(message);
|
|
39
|
-
verifyTx(decodedTransaction, transaction);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Correctly serialises and deserialises transactions messages', () => {
|
|
43
|
-
const privateTransactions = [mockTx(), mockTx(), mockTx()];
|
|
44
|
-
const message = createTransactionsMessage(privateTransactions);
|
|
45
|
-
expect(decodeMessageType(message)).toBe(Messages.POOLED_TRANSACTIONS);
|
|
46
|
-
const decodedTransactions = decodeTransactionsMessage(getEncodedMessage(message));
|
|
47
|
-
verifyTx(decodedTransactions[0], privateTransactions[0]);
|
|
48
|
-
verifyTx(decodedTransactions[1], privateTransactions[1]);
|
|
49
|
-
verifyTx(decodedTransactions[2], privateTransactions[2]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('Correctly serialises and deserialises transaction hashes message', () => {
|
|
53
|
-
const txHashes = [makeTxHash(), makeTxHash(), makeTxHash()];
|
|
54
|
-
const message = createTransactionHashesMessage(txHashes);
|
|
55
|
-
expect(decodeMessageType(message)).toEqual(Messages.POOLED_TRANSACTION_HASHES);
|
|
56
|
-
const decodedHashes = decodeTransactionHashesMessage(getEncodedMessage(message));
|
|
57
|
-
expect(decodedHashes.map(x => x.toString())).toEqual(txHashes.map(x => x.toString()));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Correctly serialises and deserialises get transactions message', () => {
|
|
61
|
-
const txHashes = [makeTxHash(), makeTxHash(), makeTxHash()];
|
|
62
|
-
const message = createGetTransactionsRequestMessage(txHashes);
|
|
63
|
-
expect(decodeMessageType(message)).toEqual(Messages.GET_TRANSACTIONS);
|
|
64
|
-
const decodedHashes = decodeGetTransactionsRequestMessage(getEncodedMessage(message));
|
|
65
|
-
expect(decodedHashes.map(x => x.toString())).toEqual(txHashes.map(x => x.toString()));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { mockTx } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
import { InMemoryTxPool } from './index.js';
|
|
4
|
-
|
|
5
|
-
describe('In-Memory TX pool', () => {
|
|
6
|
-
it('Adds txs to the pool', async () => {
|
|
7
|
-
const pool = new InMemoryTxPool();
|
|
8
|
-
const tx1 = mockTx();
|
|
9
|
-
|
|
10
|
-
await pool.addTxs([tx1]);
|
|
11
|
-
const poolTx = pool.getTxByHash(await tx1.getTxHash());
|
|
12
|
-
expect(await poolTx!.getTxHash()).toEqual(await tx1.getTxHash());
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('Removes txs from the pool', async () => {
|
|
16
|
-
const pool = new InMemoryTxPool();
|
|
17
|
-
const tx1 = mockTx();
|
|
18
|
-
|
|
19
|
-
await pool.addTxs([tx1]);
|
|
20
|
-
pool.deleteTxs([await tx1.getTxHash()]);
|
|
21
|
-
|
|
22
|
-
const poolTx = pool.getTxByHash(await tx1.getTxHash());
|
|
23
|
-
expect(poolTx).toBeFalsy();
|
|
24
|
-
});
|
|
25
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "..",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dest",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"tsBuildInfoFile": ".tsbuildinfo"
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../circuits.js"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "../foundation"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"path": "../types"
|
|
17
|
-
}
|
|
18
|
-
],
|
|
19
|
-
"include": ["src"]
|
|
20
|
-
}
|