Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

test: add transport compliance tests #149

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
},
"devDependencies": {
"@libp2p/interface-mocks": "^12.0.1",
"@libp2p/interface-transport-compliance-tests": "^4.0.2",
"@libp2p/peer-id-factory": "^2.0.3",
"@types/sinon": "^10.0.14",
"aegir": "^39.0.6",
Expand Down
50 changes: 50 additions & 0 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-env mocha */

import { mockRegistrar, mockUpgrader } from '@libp2p/interface-mocks'
import tests from '@libp2p/interface-transport-compliance-tests'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
import sinon from 'sinon'
import { stubInterface } from 'sinon-ts'
import { webRTC } from '../src/index.js'
import type { WebRTCTransportComponents } from '../src/private-to-private/transport.js'
import type { Ed25519PeerId } from '@libp2p/interface-peer-id'
import type { TransportManager } from '@libp2p/interface-transport'

describe('interface-transport compliance', () => {
let components: WebRTCTransportComponents

let relayPeerId: Ed25519PeerId

before(async () => {
relayPeerId = await createEd25519PeerId()
components = {
peerId: relayPeerId,
registrar: mockRegistrar(),
upgrader: mockUpgrader(),
transportManager: stubInterface<TransportManager>()
}
})

tests({
async setup () {
const transport = webRTC()(components)

const browserPeerId = await createEd25519PeerId()

const addrs = [
multiaddr(`/ip4/127.0.0.1/udp/9091/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/${relayPeerId.toString()}/p2p-circuit/webrtc/p2p/${browserPeerId.toString()}`)
]

// Used by the dial tests to simulate a delayed connect
const connector = {
delay () {},
restore () {
sinon.restore()
}
}
return { transport, addrs, connector }
},
async teardown () {}
})
})