diff --git a/restructure/relay/tests/test-config.js b/restructure/relay/tests/test-config.js index 636a578..81f9af0 100644 --- a/restructure/relay/tests/test-config.js +++ b/restructure/relay/tests/test-config.js @@ -1,9 +1,15 @@ // Test configuration for libp2p-relay +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; +import { createEd25519PeerId } from '@libp2p/peer-id-factory'; + +// Create a consistent test PeerId for all tests +const testPeerId = await createEd25519PeerId(); + export const testConfig = { relayDevMode: true, serverName: 'test-server', relayPubsubPeerDiscoveryTopics: 'test-topic', - relayPrivateKey: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', + relayPrivateKey: testPeerId.privateKey, bootstrapList: ['/ip4/127.0.0.1/tcp/63785/p2p/12D3KooWRBxYrPDRsLS9PSK3H8YQpKYHTrzK7J2kgjJwGp8JmpHR'], pubsubPeerDiscoveryTopics: ['test-topic'], scoreThresholds: { diff --git a/restructure/relay/tests/unit/testPinningService.js b/restructure/relay/tests/unit/testPinningService.js index 93f2f9b..58e2ffa 100644 --- a/restructure/relay/tests/unit/testPinningService.js +++ b/restructure/relay/tests/unit/testPinningService.js @@ -13,16 +13,31 @@ describe('PinningService', () => { sandbox = sinon.createSandbox(); mockHelia = { blockstore: { - put: sandbox.stub().resolves(), - get: sandbox.stub().resolves() + put: sandbox.stub().resolves(Buffer.from('test')), + get: sandbox.stub().resolves(Buffer.from('test')), + has: sandbox.stub().resolves(true) + }, + dag: { + get: sandbox.stub().resolves({ value: Buffer.from('test') }), + put: sandbox.stub().resolves() } }; mockOrbitdb = { + open: sandbox.stub().resolves({ + add: sandbox.stub().resolves('hash'), + get: sandbox.stub().resolves({ value: 'test' }), + close: sandbox.stub().resolves() + }), + close: sandbox.stub().resolves(), id: 'test-id', identity: { id: 'test-identity' } }; mockElectrumClient = { - request: sandbox.stub().resolves() + request: sandbox.stub().resolves(), + connect: sandbox.stub().resolves(), + close: sandbox.stub().resolves(), + blockchain_scripthash_subscribe: sandbox.stub().resolves(), + blockchain_scripthash_get_history: sandbox.stub().resolves([]) }; pinningService = new PinningService(mockHelia, mockOrbitdb, mockElectrumClient); @@ -46,10 +61,15 @@ describe('PinningService', () => { describe('pinContent', () => { it('should pin content successfully', async () => { - const cid = 'QmPZv7P8nQUSh6E3dGXhE3k8SqF6kY4GKH5bmFtX9DVQeH'; + const mockCid = { + toString: () => 'QmPZv7P8nQUSh6E3dGXhE3k8SqF6kY4GKH5bmFtX9DVQeH', + toV1: () => ({ + toString: () => 'QmPZv7P8nQUSh6E3dGXhE3k8SqF6kY4GKH5bmFtX9DVQeH' + }) + }; const duration = 30; - await pinningService.pinContent(cid, duration); + await pinningService.pinContent(mockCid, duration); expect(mockHelia.blockstore.put.called).to.be.true; }); diff --git a/restructure/relay/tests/unit/testPubsubHandler.js b/restructure/relay/tests/unit/testPubsubHandler.js index 464067c..fbd160f 100644 --- a/restructure/relay/tests/unit/testPubsubHandler.js +++ b/restructure/relay/tests/unit/testPubsubHandler.js @@ -11,22 +11,36 @@ describe('PubsubHandler', () => { beforeEach(() => { sandbox = sinon.createSandbox(); mockNode = { - services: { - pubsub: { - subscribe: sandbox.stub().resolves(), - publish: sandbox.stub().resolves(), + libp2p: { + services: { + pubsub: { + subscribe: sandbox.stub().resolves(), + publish: sandbox.stub().resolves(), + addEventListener: sandbox.stub(), + removeEventListener: sandbox.stub(), + topics: new Set(), + start: sandbox.stub().resolves(), + stop: sandbox.stub().resolves() + }, + identify: { + multicodecs: ['/noise'], + start: sandbox.stub().resolves(), + stop: sandbox.stub().resolves() + } + }, + connectionManager: { + getConnections: sandbox.stub().returns([]), addEventListener: sandbox.stub(), - topics: new Set() + removeEventListener: sandbox.stub() + }, + peerId: { + toString: () => 'QmTestPeerId', + toBytes: () => new Uint8Array([1, 2, 3]), + type: 'Ed25519' }, - identify: { - multicodecs: ['/noise'] - } - }, - connectionManager: { - getConnections: sandbox.stub().returns([]) - }, - peerId: { - toString: () => 'QmTestPeerId' + start: sandbox.stub().resolves(), + stop: sandbox.stub().resolves(), + getMultiaddrs: () => [] } }; mockPinningService = {