Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add webkit test script #1627

Merged
merged 21 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7d73f81
Add webkit test script
MarcoPolo Mar 15, 2023
cfd5c4b
Add webkit test to CI
MarcoPolo Mar 16, 2023
c3cde5e
Install playwright deps
MarcoPolo Mar 20, 2023
c77c006
Merge branch 'master' into marco/js-libp2p-test-webkit
achingbrain Apr 30, 2023
6cc9030
Fix stream stubbing. We can't set the property value like this on safari
MarcoPolo May 2, 2023
5ed2146
Bump @libp2p/crypto
MarcoPolo May 2, 2023
111ba6b
Update @libp2p/crypto
MarcoPolo May 5, 2023
f288f82
Merge branch 'master' into marco/js-libp2p-test-webkit
MarcoPolo May 5, 2023
bc177f5
Merge remote-tracking branch 'origin/master' into marco/js-libp2p-tes…
achingbrain May 18, 2023
36c38ba
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 23, 2023
2f0dde9
refactor: updated formatters
maschad May 23, 2023
3da460d
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 26, 2023
ede58c6
Merge branch 'master' into marco/js-libp2p-test-webkit
maschad May 31, 2023
3d6a67e
test: skip flaky connect and disconnect event tests
maschad May 31, 2023
8e43bb5
deps: update logger to enable multiaddr formatting
maschad May 31, 2023
a78db93
test: ensure that libp2p nodes are shutdown in identify service spec
maschad Jun 1, 2023
5a24425
chore: linting fixes
maschad Jun 1, 2023
c21177e
chore: remove webkit fixes
achingbrain Jun 2, 2023
d29de4a
refactor: updated multiaddr formatting in logs
maschad Jun 3, 2023
34cdc28
Merge branch 'master' into marco/js-libp2p-test-webkit
achingbrain Jun 6, 2023
37044fa
chore: edits for consistency
achingbrain Jun 6, 2023
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
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