@@ -3,7 +3,7 @@ import { start, stop } from '@libp2p/interface/startable'
33import { Key } from 'interface-datastore'
44import { MemoryDatastore , NamespaceDatastore } from 'datastore-core'
55
6- import { LiveReplicator as Replicator } from '@/replicator/live/index.js'
6+ import { LiveReplicator } from '@/replicator/live/index.js'
77import { Replica } from '@/replica/index.js'
88import { StaticAccess as Access } from '@/access/static/index.js'
99import staticAccessProtocol from '@/access/static/protocol.js'
@@ -14,39 +14,40 @@ import { getTestManifest } from '../test-utils/manifest.js'
1414import { getTestIdentities , getTestIdentity } from '../test-utils/identities.js'
1515import { basalEntry } from '@/entry/basal/index.js'
1616import { basalIdentity } from '@/identity/basal/index.js'
17- import type { Multiaddr } from '@multiformats/multiaddr'
18- import { getDhtService , getIdentifyService , getPubsubService , type UsedServices } from '../test-utils/libp2p/services.js'
19- import type { Helia } from '@helia/interface'
20- import { createLibp2p , Libp2pOptions , type Libp2p } from 'libp2p'
21- import { getLibp2pDefaults } from '../test-utils/libp2p/defaults.js'
22- import { getPeerDiscovery } from '../test-utils/libp2p/peerDiscovery.js'
23- import { createHelia } from 'helia'
24- import { waitForMultiaddrs } from '../test-utils/network.js'
17+ import { getTestKeyChain } from 'test/test-utils/keychain.js'
18+ import { MemoryBlockstore } from 'blockstore-core'
19+ import type { Ed25519PeerId } from '@libp2p/interface/dist/src/peer-id/index.js'
20+ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
21+ import { getTestPubSubNetwork } from 'test/test-mocks/pubsub.js'
22+ import type { PubSub } from '@libp2p/interface/pubsub'
2523
26- const testName = 'live-replicator'
27-
28- type TestServices = UsedServices < 'identify' | 'pubsub' | 'dht' >
24+ const testName = 'replicator/live'
2925
3026describe ( testName , ( ) => {
3127 let
32- helia1: Helia < Libp2p < TestServices > > ,
33- helia2 : Helia < Libp2p < TestServices > > ,
34- libp2p1 : Libp2p < TestServices > ,
35- libp2p2 : Libp2p < TestServices > ,
36- addr2 : Multiaddr [ ] ,
28+ id1: Ed25519PeerId ,
29+ id2 : Ed25519PeerId ,
30+ pubsub1 : PubSub ,
31+ pubsub2 : PubSub ,
3732 replica1 : Replica ,
3833 replica2 : Replica ,
39- replicator1 : Replicator ,
40- replicator2 : Replicator ,
34+ replicator1 : LiveReplicator ,
35+ replicator2 : LiveReplicator ,
4136 testPaths1 : TestPaths ,
4237 testPaths2 : TestPaths ,
4338 access : Access ,
4439 datastore : MemoryDatastore ,
4540 datastore1 : NamespaceDatastore ,
46- datastore2 : NamespaceDatastore
41+ datastore2 : NamespaceDatastore ,
42+ blockstore : MemoryBlockstore
4743
4844 before ( async ( ) => {
49- // debug.enable('libp2p:*')
45+ id1 = await createEd25519PeerId ( )
46+ id2 = await createEd25519PeerId ( )
47+
48+ const { createPubSubPeer } = getTestPubSubNetwork ( )
49+ pubsub1 = createPubSubPeer ( id1 )
50+ pubsub2 = createPubSubPeer ( id2 )
5051
5152 testPaths1 = getTestPaths ( tempPath , testName + '/1' )
5253 testPaths2 = getTestPaths ( tempPath , testName + '/2' )
@@ -55,43 +56,24 @@ describe(testName, () => {
5556 datastore1 = new NamespaceDatastore ( datastore , new Key ( testPaths1 . replica ) )
5657 datastore2 = new NamespaceDatastore ( datastore , new Key ( testPaths2 . replica ) )
5758
58- const createLibp2pOptions = async ( ) : Promise < Libp2pOptions < TestServices > > => ( {
59- ...( await getLibp2pDefaults ( ) ) ,
60- peerDiscovery : await getPeerDiscovery ( ) ,
61- services : {
62- identify : getIdentifyService ( ) ,
63- pubsub : getPubsubService ( ) ,
64- dht : getDhtService ( true )
65- }
66- } )
67-
68- libp2p1 = await createLibp2p ( await createLibp2pOptions ( ) )
69- libp2p2 = await createLibp2p ( await createLibp2pOptions ( ) )
70-
71- await Promise . all ( [
72- waitForMultiaddrs ( libp2p1 ) ,
73- waitForMultiaddrs ( libp2p2 )
74- ] )
75-
76- helia1 = await createHelia ( { libp2p : libp2p1 } )
77- helia2 = await createHelia ( { libp2p : libp2p2 } )
78-
79- addr2 = libp2p2 . getMultiaddrs ( )
80-
8159 const identities1 = await getTestIdentities ( testPaths1 )
8260 const identities2 = await getTestIdentities ( testPaths2 )
61+ const keychain1 = getTestKeyChain ( )
62+ const keychain2 = getTestKeyChain ( )
8363
8464 const identity1 = await getTestIdentity (
8565 identities1 ,
86- libp2p1 . keychain ,
66+ keychain1 ,
8767 testName
8868 )
8969 const identity2 = await getTestIdentity (
9070 identities2 ,
91- libp2p2 . keychain ,
71+ keychain2 ,
9272 testName
9373 )
9474
75+ blockstore = new MemoryBlockstore ( )
76+
9577 const write = [ identity1 . id , identity2 . id ]
9678 const accessConfig = {
9779 access : { protocol : staticAccessProtocol , config : { write } }
@@ -104,7 +86,7 @@ describe(testName, () => {
10486 replica1 = new Replica ( {
10587 manifest,
10688 datastore : datastore1 ,
107- blockstore : helia1 . blockstore ,
89+ blockstore,
10890 access,
10991 identity : identity1 ,
11092 components : {
@@ -115,7 +97,7 @@ describe(testName, () => {
11597 replica2 = new Replica ( {
11698 manifest,
11799 datastore : datastore2 ,
118- blockstore : helia2 . blockstore ,
100+ blockstore,
119101 access,
120102 identity : identity2 ,
121103 components : {
@@ -125,35 +107,31 @@ describe(testName, () => {
125107 } )
126108 await start ( replica1 , replica2 )
127109
128- replicator1 = new Replicator ( {
129- ipfs : helia1 ,
110+ replicator1 = new LiveReplicator ( {
111+ peerId : id1 ,
112+ pubsub : pubsub1 ,
130113 replica : replica1 ,
131114 datastore : datastore1 ,
132- blockstore : helia1 . blockstore
115+ blockstore
133116 } )
134- replicator2 = new Replicator ( {
135- ipfs : helia2 ,
117+ replicator2 = new LiveReplicator ( {
118+ peerId : id2 ,
119+ pubsub : pubsub2 ,
136120 replica : replica2 ,
137121 datastore : datastore2 ,
138- blockstore : helia2 . blockstore
122+ blockstore
139123 } )
140124 } )
141125
142126 after ( async ( ) => {
143127 await stop ( access )
144128 await stop ( replicator1 , replicator2 )
145129 await stop ( replica1 , replica2 )
146- await stop ( helia1 )
147- await stop ( helia2 )
148130 } )
149131
150132 describe ( 'instance' , ( ) => {
151133 before ( async ( ) => {
152134 await start ( replicator1 , replicator2 )
153- await Promise . all ( [
154- libp2p1 . dial ( addr2 ) ,
155- new Promise ( resolve => { libp2p2 . addEventListener ( 'peer:connect' , resolve , { once : true } ) } )
156- ] )
157135 } )
158136
159137 it ( 'exposes instance properties' , ( ) => {
0 commit comments