From 91c90922db1dce71b1d6cd98d69d1165686d17f9 Mon Sep 17 00:00:00 2001 From: Teo Gebhard Date: Fri, 20 Dec 2024 23:42:47 +0200 Subject: [PATCH] rm KeyServer --- packages/cli-tools/jest.config.js | 3 +- packages/cli-tools/jest.teardown.js | 5 -- packages/node/jest.config.js | 1 - packages/node/jest.teardown.js | 5 -- packages/sdk/jest.config.js | 1 - packages/sdk/jest.teardown.js | 6 -- packages/sdk/test/benchmarks/publish.js | 3 - packages/sdk/test/benchmarks/raw-pipeline.js | 7 -- packages/sdk/test/benchmarks/resend.js | 7 -- packages/sdk/test/benchmarks/subscribe.js | 4 - packages/test-utils/src/index.ts | 78 -------------------- 11 files changed, 1 insertion(+), 119 deletions(-) delete mode 100644 packages/cli-tools/jest.teardown.js delete mode 100644 packages/node/jest.teardown.js delete mode 100644 packages/sdk/jest.teardown.js diff --git a/packages/cli-tools/jest.config.js b/packages/cli-tools/jest.config.js index e8949fff1a..c3dcbb4dcb 100644 --- a/packages/cli-tools/jest.config.js +++ b/packages/cli-tools/jest.config.js @@ -1,5 +1,4 @@ const rootConfig = require('../../jest.config') module.exports = { - ...rootConfig, - globalTeardown: './jest.teardown.js' + ...rootConfig } diff --git a/packages/cli-tools/jest.teardown.js b/packages/cli-tools/jest.teardown.js deleted file mode 100644 index d17bcaaa18..0000000000 --- a/packages/cli-tools/jest.teardown.js +++ /dev/null @@ -1,5 +0,0 @@ -const { KeyServer } = require('@streamr/test-utils') - -module.exports = async () => { - await KeyServer.stopIfRunning() -} diff --git a/packages/node/jest.config.js b/packages/node/jest.config.js index d5edb12f11..3e79a25fd0 100644 --- a/packages/node/jest.config.js +++ b/packages/node/jest.config.js @@ -1,6 +1,5 @@ const rootConfig = require('../../jest.config') module.exports = { ...rootConfig, - globalTeardown: './jest.teardown.js', testTimeout: 10000 } diff --git a/packages/node/jest.teardown.js b/packages/node/jest.teardown.js deleted file mode 100644 index d17bcaaa18..0000000000 --- a/packages/node/jest.teardown.js +++ /dev/null @@ -1,5 +0,0 @@ -const { KeyServer } = require('@streamr/test-utils') - -module.exports = async () => { - await KeyServer.stopIfRunning() -} diff --git a/packages/sdk/jest.config.js b/packages/sdk/jest.config.js index a53e8572fe..08e9eea01d 100644 --- a/packages/sdk/jest.config.js +++ b/packages/sdk/jest.config.js @@ -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' diff --git a/packages/sdk/jest.teardown.js b/packages/sdk/jest.teardown.js deleted file mode 100644 index 7031a57f59..0000000000 --- a/packages/sdk/jest.teardown.js +++ /dev/null @@ -1,6 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -const { KeyServer } = require('@streamr/test-utils') - -module.exports = async () => { - await KeyServer.stopIfRunning() -} diff --git a/packages/sdk/test/benchmarks/publish.js b/packages/sdk/test/benchmarks/publish.js index 761094d3ed..5408366cb6 100644 --- a/packages/sdk/test/benchmarks/publish.js +++ b/packages/sdk/test/benchmarks/publish.js @@ -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 @@ -131,7 +129,6 @@ async function run() { }) suite.on('complete', async () => { - keyserver.destroy() log('Destroying clients') const tasks = [ client1.destroy(), diff --git a/packages/sdk/test/benchmarks/raw-pipeline.js b/packages/sdk/test/benchmarks/raw-pipeline.js index 2f99d7dd5b..3dd97724bc 100644 --- a/packages/sdk/test/benchmarks/raw-pipeline.js +++ b/packages/sdk/test/benchmarks/raw-pipeline.js @@ -2,7 +2,6 @@ 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') @@ -10,8 +9,6 @@ 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() @@ -216,10 +213,6 @@ async function run() { log(toStringBench(event.target)) }) - suite.on('complete', () => { - keyserver.destroy() - }) - log('starting') suite.run() } diff --git a/packages/sdk/test/benchmarks/resend.js b/packages/sdk/test/benchmarks/resend.js index a6716f3ed3..0ed5ad916e 100644 --- a/packages/sdk/test/benchmarks/resend.js +++ b/packages/sdk/test/benchmarks/resend.js @@ -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') @@ -161,10 +158,6 @@ async function run() { log(toStringBench(event.target)) }) - suite.on('complete', () => { - keyserver.destroy() - }) - log('starting') suite.run() } diff --git a/packages/sdk/test/benchmarks/subscribe.js b/packages/sdk/test/benchmarks/subscribe.js index d732e2dcee..0e5a8ee61d 100644 --- a/packages/sdk/test/benchmarks/subscribe.js +++ b/packages/sdk/test/benchmarks/subscribe.js @@ -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 @@ -140,7 +137,6 @@ async function run() { }) suite.on('complete', async () => { - keyserver.destroy() log('Destroying clients') const tasks = [ client1.destroy(), diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index 7267459259..717552b0b7 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts @@ -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' @@ -184,82 +182,6 @@ export function describeOnlyInNodeJs(...args: Parameters): 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 - private server?: http.Server - - public static async startIfNotRunning(): Promise { - if (KeyServer.singleton === undefined) { - KeyServer.singleton = new KeyServer() - await KeyServer.singleton.ready - } - } - - public static async stopIfRunning(): Promise { - 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 { - 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 { private readonly items: T[] = []