From a819ceeb1b9a7222061f7b2ada2c5cd3609ee001 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar Date: Fri, 27 May 2022 16:26:39 -0700 Subject: [PATCH] test: refactor local clients --- test/Client.test.ts | 22 +++++++++------------- test/conversations/Conversation.test.ts | 12 +++--------- test/conversations/Conversations.test.ts | 12 +++--------- test/helpers.ts | 12 ++++++++++++ 4 files changed, 27 insertions(+), 31 deletions(-) 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' })