Skip to content

Commit

Permalink
test: Add webkit test script (#1627)
Browse files Browse the repository at this point in the history
Runs test suite on webkit along with other browsers

---------

Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: chad <chad.nehemiah94@gmail.com>
  • Loading branch information
3 people authored Jun 6, 2023
1 parent 8e5df6f commit 14aa40f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ jobs:
directory: ./.nyc_output
flags: firefox-webworker

test-webkit:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
- uses: ipfs/aegir/actions/cache-node-modules@master
- run: npx playwright install-deps
- run: npm run --if-present test:webkit
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
with:
directory: ./.nyc_output
flags: webkit

test-electron-main:
needs: check
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion examples/libp2p-in-the-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"license": "ISC",
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^7.0.0",
"@chainsafe/libp2p-gossipsub": "^8.0.0",
"@chainsafe/libp2p-noise": "^12.0.0",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@libp2p/bootstrap": "^8.0.0",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit",
"test:examples": "cd examples && npm run test:all",
"test:interop": "aegir test -t node -f dist/test/interop.js"
},
"dependencies": {
"@achingbrain/nat-port-mapper": "^1.0.3",
"@libp2p/crypto": "^1.0.4",
"@libp2p/crypto": "^1.0.17",
"@libp2p/interface-address-manager": "^3.0.0",
"@libp2p/interface-connection": "^5.0.0",
"@libp2p/interface-connection-encrypter": "^4.0.0",
Expand All @@ -142,7 +143,7 @@
"@libp2p/interface-transport": "^4.0.0",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/keychain": "^2.0.0",
"@libp2p/logger": "^2.0.1",
"@libp2p/logger": "^2.1.1",
"@libp2p/multistream-select": "^3.1.8",
"@libp2p/peer-collections": "^3.0.0",
"@libp2p/peer-id": "^2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/autonat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable {
// they either told us which address worked/didn't work, or we only sent them one address
const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr)

log('autonat response for %s is %s', addr, dialResponse.status)
log('autonat response for %a is %s', addr, dialResponse.status)

if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) {
// the remote could not parse our request
Expand All @@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable {
}

if (!multiaddrs.some(ma => ma.equals(addr))) {
log('peer reported %s as %s but it was not in our observed address list', addr, dialResponse.status)
log('peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status)
continue
}

Expand All @@ -544,14 +544,14 @@ class DefaultAutoNATService implements Startable {

if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) {
// we are now convinced
log('%s is externally dialable', addr)
log('%a is externally dialable', addr)
addressManager.confirmObservedAddr(addr)
return
}

if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) {
// we are now unconvinced
log('%s is not externally dialable', addr)
log('%a is not externally dialable', addr)
addressManager.removeObservedAddr(addr)
return
}
Expand Down
37 changes: 22 additions & 15 deletions test/autonat/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@

import { start, stop } from '@libp2p/interfaces/startable'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { multiaddr } from '@multiformats/multiaddr'
import { expect } from 'aegir/chai'
import all from 'it-all'
import * as lp from 'it-length-prefixed'
import { pipe } from 'it-pipe'
import { pushable } from 'it-pushable'
import sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { stubInterface } from 'sinon-ts'
import { Uint8ArrayList } from 'uint8arraylist'
import { PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION } from '../../src/autonat/constants.js'
import { autoNATService, type AutoNATServiceInit } from '../../src/autonat/index.js'
import { autoNATService } from '../../src/autonat/index.js'
import { Message } from '../../src/autonat/pb/index.js'
import { type Components, defaultComponents } from '../../src/components.js'
import { defaultComponents } from '../../src/components.js'
import type { AutoNATServiceInit } from '../../src/autonat/index.js'
import type { Components } from '../../src/components.js'
import type { DefaultConnectionManager } from '../../src/connection-manager/index.js'
import type { AddressManager } from '@libp2p/interface-address-manager'
import type { Connection, Stream } from '@libp2p/interface-connection'
Expand All @@ -25,6 +27,8 @@ import type { PeerRouting } from '@libp2p/interface-peer-routing'
import type { PeerStore } from '@libp2p/interface-peer-store'
import type { Registrar } from '@libp2p/interface-registrar'
import type { Transport, TransportManager } from '@libp2p/interface-transport'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { StubbedInstance } from 'sinon-ts'

const defaultInit: AutoNATServiceInit = {
protocolPrefix: 'libp2p',
Expand Down Expand Up @@ -92,19 +96,22 @@ describe('autonat', () => {
connection.remoteAddr = multiaddr(`/ip4/${host}/tcp/28319/p2p/${peer.id.toString()}`)
connectionManager.openConnection.withArgs(peer.id).resolves(connection)

// stub autonat protocol stream
const stream = stubInterface<Stream>()
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).resolves(stream)
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).callsFake(async () => {
// stub autonat protocol stream
const stream = stubInterface<Stream>()

// stub autonat response
const response = Message.encode({
type: Message.MessageType.DIAL_RESPONSE,
dialResponse
// stub autonat response
const response = Message.encode({
type: Message.MessageType.DIAL_RESPONSE,
dialResponse
})
stream.source = (async function * () {
yield lp.encode.single(response)
}())
stream.sink.returns(Promise.resolve())

return stream
})
stream.source = (async function * () {
yield lp.encode.single(response)
}())
stream.sink.returns(Promise.resolve())

return peer
}
Expand Down

0 comments on commit 14aa40f

Please sign in to comment.