diff --git a/test/Client.test.ts b/test/Client.test.ts index f55512d27..547835fc6 100644 --- a/test/Client.test.ts +++ b/test/Client.test.ts @@ -1,5 +1,11 @@ import assert from 'assert' -import { pollFor, newWallet, dumpStream } from './helpers' +import { + pollFor, + newWallet, + dumpStream, + newLocalDockerClient, + newDevClient, +} from './helpers' import { publishUserContact, sleep } from '../src/utils' import Client, { KeyStoreType } from '../src/Client' import { TestKeyCodec, ContentTypeTestKey } from './ContentTypeTestKey' @@ -13,16 +19,6 @@ import { PrivateKeyBundle, } from '../src' -const newLocalDockerClient = (): Promise => - Client.create(newWallet(), { - bootstrapAddrs: [ - '/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA', - ], - }) - -const newTestnetClient = (): Promise => - Client.create(newWallet(), { env: 'dev' }) - describe('Client', () => { const tests = [ { @@ -32,8 +28,8 @@ describe('Client', () => { ] if (process.env.CI || process.env.TESTNET) { tests.push({ - name: 'testnet', - newClient: newTestnetClient, + name: 'dev', + newClient: newDevClient, }) } tests.forEach((testCase) => { diff --git a/test/conversations/Conversation.test.ts b/test/conversations/Conversation.test.ts index 93631371c..482d29713 100644 --- a/test/conversations/Conversation.test.ts +++ b/test/conversations/Conversation.test.ts @@ -1,12 +1,6 @@ import { Client } from '../../src' -import { Wallet } from 'ethers' import { sleep } from '../../src/utils' - -const opts = { - bootstrapAddrs: [ - '/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA', - ], -} +import { newLocalDockerClient } from '../helpers' jest.setTimeout(20000) @@ -15,8 +9,8 @@ describe('conversations', () => { let bob: Client beforeEach(async () => { - alice = await Client.create(Wallet.createRandom(), opts) - bob = await Client.create(Wallet.createRandom(), opts) + alice = await newLocalDockerClient() + bob = await newLocalDockerClient() }) afterEach(async () => { diff --git a/test/conversations/Conversations.test.ts b/test/conversations/Conversations.test.ts index a10d31491..8791bbf9c 100644 --- a/test/conversations/Conversations.test.ts +++ b/test/conversations/Conversations.test.ts @@ -1,13 +1,7 @@ +import { newLocalDockerClient } from './../helpers' import { Client } from '../../src' -import { Wallet } from 'ethers' import { sleep } from '../../src/utils' -const opts = { - bootstrapAddrs: [ - '/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA', - ], -} - jest.setTimeout(20000) describe('conversations', () => { @@ -15,8 +9,8 @@ describe('conversations', () => { let bob: Client beforeEach(async () => { - alice = await Client.create(Wallet.createRandom(), opts) - bob = await Client.create(Wallet.createRandom(), opts) + alice = await newLocalDockerClient() + bob = await newLocalDockerClient() await sleep(100) }) diff --git a/test/helpers.ts b/test/helpers.ts index 4b079aa40..d16c7e6e2 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -5,10 +5,14 @@ import { ContentCodec, ContentTypeId, TextCodec, + Client, } from '../src' import Stream from '../src/Stream' import { promiseWithTimeout } from '../src/utils' +const LOCAL_DOCKER_MULTIADDR = + '/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA' + export const sleep = (ms: number): Promise => new Promise((resolve) => setTimeout(resolve, ms)) @@ -89,3 +93,11 @@ export class CodecRegistry { return this._codecs.get(key) } } + +export const newLocalDockerClient = (): Promise => + Client.create(newWallet(), { + bootstrapAddrs: [LOCAL_DOCKER_MULTIADDR], + }) + +export const newDevClient = (): Promise => + Client.create(newWallet(), { env: 'dev' })