Skip to content

Commit

Permalink
rm KeyServer
Browse files Browse the repository at this point in the history
  • Loading branch information
teogeb committed Dec 20, 2024
1 parent 72da6bc commit 91c9092
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 119 deletions.
3 changes: 1 addition & 2 deletions packages/cli-tools/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const rootConfig = require('../../jest.config')
module.exports = {
...rootConfig,
globalTeardown: './jest.teardown.js'
...rootConfig
}
5 changes: 0 additions & 5 deletions packages/cli-tools/jest.teardown.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/node/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const rootConfig = require('../../jest.config')
module.exports = {
...rootConfig,
globalTeardown: './jest.teardown.js',
testTimeout: 10000
}
5 changes: 0 additions & 5 deletions packages/node/jest.teardown.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/sdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const rootConfig = require('../../jest.config')
module.exports = {
...rootConfig,
globalSetup: './jest.setup.js',
globalTeardown: './jest.teardown.js',
setupFilesAfterEnv: rootConfig.setupFilesAfterEnv.concat([
'./test/test-utils/customMatchers.ts',
'@streamr/test-utils/setupCustomMatchers'
Expand Down
6 changes: 0 additions & 6 deletions packages/sdk/jest.teardown.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/sdk/test/benchmarks/publish.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { format } = require('util')
const { Benchmark } = require('benchmark')
const { KeyServer } = require('@streamr/test-utils')

// eslint-disable-next-line import/no-unresolved
const StreamrClient = require('../../dist')
const keyserver = new KeyServer()

// note this is not the number of messages, just the start number
let count = 100000 // pedantic: use large initial number so payload size is similar
Expand Down Expand Up @@ -131,7 +129,6 @@ async function run() {
})

suite.on('complete', async () => {
keyserver.destroy()
log('Destroying clients')
const tasks = [
client1.destroy(),
Expand Down
7 changes: 0 additions & 7 deletions packages/sdk/test/benchmarks/raw-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ const { format } = require('util')
const { Benchmark } = require('benchmark')
const { randomBytes } = require('crypto')
const bytes = require('bytes')
const { KeyServer } = require('@streamr/test-utils')

// eslint-disable-next-line import/no-unresolved
const StreamrClient = require('../../dist')
const { StreamMessage } = require('@streamr/protocol')

const { StorageNode, ConfigTest: clientOptions } = StreamrClient

const keyserver = new KeyServer()

async function getPrivateKey() {
const response = await fetch('http://localhost:45454/key')
return response.text()
Expand Down Expand Up @@ -216,10 +213,6 @@ async function run() {
log(toStringBench(event.target))
})

suite.on('complete', () => {
keyserver.destroy()
})

log('starting')
suite.run()
}
Expand Down
7 changes: 0 additions & 7 deletions packages/sdk/test/benchmarks/resend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ const { format } = require('util')
const { Benchmark } = require('benchmark')
const { randomBytes } = require('crypto')
const bytes = require('bytes')
const { KeyServer } = require('@streamr/test-utils')

// eslint-disable-next-line import/no-unresolved
const StreamrClient = require('../../dist')

const keyserver = new KeyServer()

const { StorageNode } = StreamrClient
async function getPrivateKey() {
const response = await fetch('http://localhost:45454/key')
Expand Down Expand Up @@ -161,10 +158,6 @@ async function run() {
log(toStringBench(event.target))
})

suite.on('complete', () => {
keyserver.destroy()
})

log('starting')
suite.run()
}
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/test/benchmarks/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ const { Benchmark } = require('benchmark')

// eslint-disable-next-line import/no-unresolved
const StreamrClient = require('../../dist')
const { KeyServer } = require('@streamr/test-utils')

const keyserver = new KeyServer()

// note this is not the number of messages, just the start number
let count = 100000 // pedantic: use large initial number so payload size is similar
Expand Down Expand Up @@ -140,7 +137,6 @@ async function run() {
})

suite.on('complete', async () => {
keyserver.destroy()
log('Destroying clients')
const tasks = [
client1.destroy(),
Expand Down
78 changes: 0 additions & 78 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { EthereumAddress, toEthereumAddress, toUserId, UserID, until, waitForEvent, Logger, retry } from '@streamr/utils'
import cors from 'cors'
import crypto, { randomBytes } from 'crypto'
import { AbstractSigner, Contract, JsonRpcProvider, parseEther, Provider, TransactionResponse, Wallet } from 'ethers'
import { EventEmitter, once } from 'events'
import express from 'express'
import http from 'http'
import random from 'lodash/random'
import { AddressInfo } from 'net'
import { Readable } from 'stream'
Expand Down Expand Up @@ -184,82 +182,6 @@ export function describeOnlyInNodeJs(...args: Parameters<typeof describe>): void
}
}

/**
* Used to spin up an HTTP server used by integration tests to fetch private keys having non-zero ERC-20 token
* balances in streamr-docker-dev environment.
*/
export class KeyServer {
public static readonly KEY_SERVER_PORT = 45454
private static singleton: KeyServer | undefined
private readonly ready: Promise<unknown>
private server?: http.Server

public static async startIfNotRunning(): Promise<void> {
if (KeyServer.singleton === undefined) {
KeyServer.singleton = new KeyServer()
await KeyServer.singleton.ready
}
}

public static async stopIfRunning(): Promise<void> {
if (KeyServer.singleton !== undefined) {
const temp = KeyServer.singleton
KeyServer.singleton = undefined
await temp.destroy()
}
}

private constructor() {
const app = express()
app.use(cors())
let c = 1
app.get('/key', (_req, res) => {
const hexString = c.toString(16)
const privateKey = '0x' + hexString.padStart(64, '0')
res.send(privateKey)
c += 1
if (c > 1000) {
c = 1
} else if (c === 10) {
/*
NET-666: There is something weird about the 10th key '0x0000000000....a'
that causes StreamRegistryContract to read a weird value to msg.sender
that does NOT correspond to the public address. Until that is investigated
and solved, skipping this key.
*/
c = 11
}
})
console.info(`starting up keyserver on port ${KeyServer.KEY_SERVER_PORT}...`)
this.ready = new Promise((resolve, reject) => {
this.server = app.listen(KeyServer.KEY_SERVER_PORT)
.once('listening', () => {
console.info(`keyserver started on port ${KeyServer.KEY_SERVER_PORT}`)
resolve(true)
})
.once('error', (err) => {
reject(err)
})
})
}

private destroy(): Promise<unknown> {
if (this.server === undefined) {
return Promise.resolve(true)
}
return new Promise((resolve, reject) => {
this.server!.close((err) => {
if (err) {
reject(err)
} else {
console.info(`closed keyserver on port ${KeyServer.KEY_SERVER_PORT}`)
resolve(true)
}
})
})
}
}

export class Queue<T> {

private readonly items: T[] = []
Expand Down

0 comments on commit 91c9092

Please sign in to comment.