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

Feature/more_p2p_tests #190

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface OceanNodeKeys {
}

export interface OceanNodeP2PConfig {
bootstrapNodes: string[]
ipV4BindAddress: string | null
ipV4BindTcpPort: number | null
ipV4BindWsPort: number | null
Expand Down
15 changes: 1 addition & 14 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ export class OceanP2P extends EventEmitter {
}

async createNode(config: OceanNodeConfig): Promise<Libp2p | null> {
const bootstrapers = [
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
'/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
// '/ip4/127.0.0.12/tcp/49100/p2p/12D3KooWLktGvbzuDK7gv1kS4pq6DNWxmxEREKVtBEhVFQmDNni7'
'/ip4/35.198.125.13/tcp/8000/p2p/16Uiu2HAmKZuuY2Lx3JiY938rJWZrYQh6kjBZCNrh3ALkodtwFRdF', // paulo
'/ip4/34.159.64.236/tcp/8000/p2p/16Uiu2HAmAy1GcZGhzFT3cbARTmodg9c3M4EAmtBZyDgu5cSL1NPr', // jaime
'/ip4/34.107.3.14/tcp/8000/p2p/16Uiu2HAm4DWmX56ZX2bKjvARJQZPMUZ9xsdtAfrMmd7P8czcN4UT', // maria
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
]
try {
this._publicAddress = config.keys.peerId.toString()
this._publicKey = config.keys.publicKey
Expand All @@ -164,7 +152,7 @@ export class OceanP2P extends EventEmitter {
],
peerDiscovery: [
bootstrap({
list: bootstrapers
list: config.p2pConfig.bootstrapNodes
}),
pubsubPeerDiscovery({
interval: config.p2pConfig.pubsubPeerDiscoveryInterval,
Expand Down Expand Up @@ -253,7 +241,6 @@ export class OceanP2P extends EventEmitter {
// hole punching errors are non-fatal
console.error(err)
})

return node
} catch (e) {
P2P_CONSOLE_LOGGER.logMessageWithEmoji(
Expand Down
12 changes: 12 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ export async function getConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
hasHttp: true,
hasP2P: true,
p2pConfig: {
bootstrapNodes: [
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
'/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
// '/ip4/127.0.0.12/tcp/49100/p2p/12D3KooWLktGvbzuDK7gv1kS4pq6DNWxmxEREKVtBEhVFQmDNni7'
'/ip4/35.198.125.13/tcp/8000/p2p/16Uiu2HAmKZuuY2Lx3JiY938rJWZrYQh6kjBZCNrh3ALkodtwFRdF', // paulo
'/ip4/34.159.64.236/tcp/8000/p2p/16Uiu2HAmAy1GcZGhzFT3cbARTmodg9c3M4EAmtBZyDgu5cSL1NPr', // jaime
'/ip4/34.107.3.14/tcp/8000/p2p/16Uiu2HAm4DWmX56ZX2bKjvARJQZPMUZ9xsdtAfrMmd7P8czcN4UT', // maria
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
],
ipV4BindAddress: getEnvValue(process.env.P2P_ipV4BindAddress, '0.0.0.0'),
ipV4BindTcpPort: getIntEnvValue(process.env.P2P_ipV4BindTcpPort, 0),
ipV4BindWsPort: getIntEnvValue(process.env.P2P_ipV4BindWsPort, 0),
Expand Down
65 changes: 59 additions & 6 deletions tests/unit/oceanP2P.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
import { assert } from 'chai'
import { Database } from '../../components/database/index.js'
import { getConfig } from '../../utils/config.js'
import { OceanP2P } from '../../components/P2P/index.js'
import { delay } from '../integration/testUtils.js'

describe('OceanP2P Test', () => {
it('Start instance of OceanP2P', async () => {
const config = await getConfig()
const db = await new Database(config.dbConfig)
const p2pNode = new OceanP2P(db, config)
assert(p2pNode, 'Failed to create P2P Node instance')
let node1: OceanP2P
let node2: OceanP2P
let config1: any
let config2: any
it('Start instance of OceanP2P node1', async () => {
process.env.PRIVATE_KEY = process.env.NODE1_PRIVATE_KEY
config1 = await getConfig()
config1.p2pConfig.ipV4BindTcpPort = 0
node1 = new OceanP2P(null, config1)
await node1.start()
assert(node1, 'Failed to create P2P Node instance')
})
it('Start instance of OceanP2P node2', async () => {
process.env.PRIVATE_KEY = process.env.NODE2_PRIVATE_KEY
config2 = await getConfig()
config2.p2pConfig.ipV4BindTcpPort = 0
node2 = new OceanP2P(null, config2)
await node2.start()
assert(node2, 'Failed to create P2P Node instance')
})
it('Start check peerID of each node', async () => {
assert(
config1.keys.peerId.toString() === node1._libp2p.peerId.toString(),
'Peer missmatch for node1'
)
assert(
config2.keys.peerId.toString() === node2._libp2p.peerId.toString(),
'Peer missmatch for node2'
)
})
delay(1000)
it('Start check if nodes are connected', async () => {
const allPeers1 = await node1.getAllPeerStore()
const peers1 = allPeers1.map((a: any) => a.id.toString())
assert(
peers1.includes(config2.keys.peerId.toString()),
'Node2 not found in node1 peer list'
)
const allPeers2 = await node2.getAllPeerStore()
const peers2 = allPeers2.map((a: any) => a.id.toString())
assert(
peers2.includes(config1.keys.peerId.toString()),
'Node1 not found in node2 peer list'
)
})
it('Start check if nodes are connected with pubsub', async () => {
let peers = await node1.getPeers()
const peers1 = peers.map((p) => p.toString())
assert(
peers1.includes(config2.keys.peerId.toString()),
'Node2 not found in node1 peer list'
)
peers = await node2.getPeers()
const peers2 = peers.map((p) => p.toString())
assert(
peers2.includes(config1.keys.peerId.toString()),
'Node1 not found in node2 peer list'
)
})
})
Loading