Skip to content

Commit a819cee

Browse files
committed
test: refactor local clients
1 parent 8cbdd15 commit a819cee

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

test/Client.test.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import assert from 'assert'
2-
import { pollFor, newWallet, dumpStream } from './helpers'
2+
import {
3+
pollFor,
4+
newWallet,
5+
dumpStream,
6+
newLocalDockerClient,
7+
newDevClient,
8+
} from './helpers'
39
import { publishUserContact, sleep } from '../src/utils'
410
import Client, { KeyStoreType } from '../src/Client'
511
import { TestKeyCodec, ContentTypeTestKey } from './ContentTypeTestKey'
@@ -13,16 +19,6 @@ import {
1319
PrivateKeyBundle,
1420
} from '../src'
1521

16-
const newLocalDockerClient = (): Promise<Client> =>
17-
Client.create(newWallet(), {
18-
bootstrapAddrs: [
19-
'/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA',
20-
],
21-
})
22-
23-
const newTestnetClient = (): Promise<Client> =>
24-
Client.create(newWallet(), { env: 'dev' })
25-
2622
describe('Client', () => {
2723
const tests = [
2824
{
@@ -32,8 +28,8 @@ describe('Client', () => {
3228
]
3329
if (process.env.CI || process.env.TESTNET) {
3430
tests.push({
35-
name: 'testnet',
36-
newClient: newTestnetClient,
31+
name: 'dev',
32+
newClient: newDevClient,
3733
})
3834
}
3935
tests.forEach((testCase) => {

test/conversations/Conversation.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { Client } from '../../src'
2-
import { Wallet } from 'ethers'
32
import { sleep } from '../../src/utils'
4-
5-
const opts = {
6-
bootstrapAddrs: [
7-
'/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA',
8-
],
9-
}
3+
import { newLocalDockerClient } from '../helpers'
104

115
jest.setTimeout(20000)
126

@@ -15,8 +9,8 @@ describe('conversations', () => {
159
let bob: Client
1610

1711
beforeEach(async () => {
18-
alice = await Client.create(Wallet.createRandom(), opts)
19-
bob = await Client.create(Wallet.createRandom(), opts)
12+
alice = await newLocalDockerClient()
13+
bob = await newLocalDockerClient()
2014
})
2115

2216
afterEach(async () => {

test/conversations/Conversations.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1+
import { newLocalDockerClient } from './../helpers'
12
import { Client } from '../../src'
2-
import { Wallet } from 'ethers'
33
import { sleep } from '../../src/utils'
44

5-
const opts = {
6-
bootstrapAddrs: [
7-
'/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA',
8-
],
9-
}
10-
115
jest.setTimeout(20000)
126

137
describe('conversations', () => {
148
let alice: Client
159
let bob: Client
1610

1711
beforeEach(async () => {
18-
alice = await Client.create(Wallet.createRandom(), opts)
19-
bob = await Client.create(Wallet.createRandom(), opts)
12+
alice = await newLocalDockerClient()
13+
bob = await newLocalDockerClient()
2014
await sleep(100)
2115
})
2216

test/helpers.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import {
55
ContentCodec,
66
ContentTypeId,
77
TextCodec,
8+
Client,
89
} from '../src'
910
import Stream from '../src/Stream'
1011
import { promiseWithTimeout } from '../src/utils'
1112

13+
const LOCAL_DOCKER_MULTIADDR =
14+
'/ip4/127.0.0.1/tcp/9001/ws/p2p/16Uiu2HAmNCxLZCkXNbpVPBpSSnHj9iq4HZQj7fxRzw2kj1kKSHHA'
15+
1216
export const sleep = (ms: number): Promise<void> =>
1317
new Promise((resolve) => setTimeout(resolve, ms))
1418

@@ -89,3 +93,11 @@ export class CodecRegistry {
8993
return this._codecs.get(key)
9094
}
9195
}
96+
97+
export const newLocalDockerClient = (): Promise<Client> =>
98+
Client.create(newWallet(), {
99+
bootstrapAddrs: [LOCAL_DOCKER_MULTIADDR],
100+
})
101+
102+
export const newDevClient = (): Promise<Client> =>
103+
Client.create(newWallet(), { env: 'dev' })

0 commit comments

Comments
 (0)