Skip to content

Commit

Permalink
Monorepo: Remove esModuleInterop and allowSyntheticDefaultImports Op…
Browse files Browse the repository at this point in the history
…tions (cherry-picked) (#1975)

* Monorepo: set esModuleInterop TS compiler option to false

* client: change `import X` to `import * as X`

* client: replace qheap with js-priority-queue

* blockchain: change to import *

* blockchain/tests: change to import *

* block/test: change to import *

* common: change to import *

* common/tests: change to import *

* devp2p: change imports to import * or require()

* ethash/tests: change import tape to import * as

* rlp/tests: change imports to import *

* statemanager/test: change imports to import * as

* trie/tests: change imports to import *

* ts/tests: change imports to import *

* util/tests: change imports to import *

* vm: change json import to import *

* vm/tests: change imports to import *

* client/test: change imports to import *

* vm/tests: fix API test imports

* trie/benchmarks: fix benchmark test import

* client: fix qheap import problem

* Devp2p, EVM: fixed tests

Co-authored-by: ScottyPoi <[email protected]>
  • Loading branch information
holgerd77 and ScottyPoi authored Jun 21, 2022
1 parent 252e283 commit c5fb316
Show file tree
Hide file tree
Showing 230 changed files with 370 additions and 354 deletions.
2 changes: 1 addition & 1 deletion config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"downlevelIteration": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bytesToHex } from 'ethereum-cryptography/utils'
import { bufArrToArr, NestedUint8Array, toBuffer, zeros } from '@ethereumjs/util'
Expand All @@ -8,7 +8,7 @@ import { Block, BlockBuffer, BlockHeader } from '../src'
import blockFromRpc from '../src/from-rpc'
import { Mockchain } from './mockchain'
import { createBlock } from './util'
import testnetMerge from './testdata/testnetMerge.json'
import * as testnetMerge from './testdata/testnetMerge.json'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json'
import * as testDataGenesis from './testdata/genesishashestest.json'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/clique.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Address } from '@ethereumjs/util'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/difficulty.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Common, { Chain } from '@ethereumjs/common'
import { bufferToInt } from '@ethereumjs/util'
import { Block } from '../src'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Mockchain } from './mockchain'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/from-rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'
import blockFromRpc from '../src/from-rpc'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Address, toBuffer, zeros, KECCAK256_RLP, KECCAK256_RLP_ARRAY } from '@ethereumjs/util'
import RLP from 'rlp'
import Common, { Chain, CliqueConfig, Hardfork } from '@ethereumjs/common'
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/mergeBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Address, KECCAK256_RLP, KECCAK256_RLP_ARRAY, zeros } from '@ethereumjs/util'
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/src/db/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LRUCache from 'lru-cache'
import * as LRUCache from 'lru-cache'

/**
* Simple LRU Cache that allows for keys of type Buffer
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/test/clique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Common, {
Hardfork,
} from '@ethereumjs/common'
import { Address } from '@ethereumjs/util'
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '../src'
import { CliqueConsensus, CLIQUE_NONCE_AUTH, CLIQUE_NONCE_DROP } from '../src/consensus/clique'

Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Block, BlockHeader, BlockOptions } from '@ethereumjs/block'
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '../src'
import { generateBlockchain, generateBlocks, isConsecutive, createTestDB } from './util'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import blocksData from './testdata/blocks_mainnet.json'
import * as blocksData from './testdata/blocks_mainnet.json'

import { MemoryLevel } from 'memory-level'

Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/test/pos.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tape from 'tape'
import * as tape from 'tape'
import { Block } from '@ethereumjs/block'
import Common, { Hardfork } from '@ethereumjs/common'
import Blockchain from '../src'
import testnet from './testdata/testnet.json'
import * as testnet from './testdata/testnet.json'

const buildChain = async (blockchain: Blockchain, common: Common, height: number) => {
const blocks: Block[] = []
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/test/reorg.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Block } from '@ethereumjs/block'
import { Address } from '@ethereumjs/util'
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '../src'
import { CliqueConsensus, CLIQUE_NONCE_AUTH } from '../src/consensus/clique'
import { generateConsecutiveBlock } from './util'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import { homedir } from 'os'
import path from 'path'
import readline from 'readline'
import * as path from 'path'
import * as readline from 'readline'
import { randomBytes } from 'crypto'
import { existsSync } from 'fs'
import { ensureDirSync, readFileSync, removeSync } from 'fs-extra'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk'
import * as chalk from 'chalk'
import { createLogger, format, transports as wTransports, Logger as WinstonLogger } from 'winston'
const DailyRotateFile = require('winston-daily-rotate-file')

Expand Down
8 changes: 4 additions & 4 deletions packages/client/lib/net/peer/libp2pnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

import { NOISE } from '@chainsafe/libp2p-noise'
import LibP2p from 'libp2p'
import * as LibP2P from 'libp2p'
import { Multiaddr } from 'multiaddr'
import PeerId from 'peer-id'
import Bootstrap from 'libp2p-bootstrap'
import * as PeerId from 'peer-id'
import * as Bootstrap from 'libp2p-bootstrap'
const TCP = require('libp2p-tcp')
const Websockets = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
Expand All @@ -29,7 +29,7 @@ export interface Libp2pNodeOptions {
bootnodes?: Multiaddr[]
}

export class Libp2pNode extends LibP2p {
export class Libp2pNode extends LibP2P {
constructor(options: Libp2pNodeOptions) {
const wsTransportKey = Websockets.prototype[Symbol.toStringTag]
options.bootnodes = options.bootnodes ?? []
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/net/peer/libp2ppeer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Multiaddr, multiaddr } from 'multiaddr'
import PeerId from 'peer-id'
import * as PeerId from 'peer-id'
import { Libp2pMuxedStream as MuxedStream } from '../../types'
import { Libp2pSender } from '../protocol/libp2psender'
import { Peer, PeerOptions } from './peer'
Expand Down
8 changes: 4 additions & 4 deletions packages/client/lib/net/protocol/libp2psender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pipe from 'it-pipe'
import pushable from 'it-pushable'
import * as pipe from 'it-pipe'
import * as pushable from 'it-pushable'
import { arrToBufArr, bufferToInt, bufArrToArr, intToBuffer } from '@ethereumjs/util'
import RLP from 'rlp'
import { Libp2pMuxedStream as MuxedStream } from '../../types'
Expand Down Expand Up @@ -34,10 +34,10 @@ export class Libp2pSender extends Sender {

init() {
// outgoing stream
pipe(this.pushable, this.stream)
pipe.pipe(this.pushable, this.stream)

// incoming stream
void pipe(this.stream, async (source: any) => {
void pipe.pipe(this.stream, async (source: any) => {
for await (const bl of source) {
// convert BufferList to Buffer
const data: Buffer = bl.slice()
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/net/server/libp2pserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PeerId from 'peer-id'
import * as PeerId from 'peer-id'
// eslint-disable-next-line implicit-dependencies/no-implicit
import { keys } from 'libp2p-crypto'
import { Multiaddr, multiaddr } from 'multiaddr'
Expand Down
1 change: 0 additions & 1 deletion packages/client/lib/sync/fetcher/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { debug as createDebugLogger, Debugger } from 'debug'
import { Readable, Writable } from 'stream'
import Heap from 'qheap'

import { PeerPool } from '../../net/peerpool'
import { Peer } from '../../net/peer'
import { Config } from '../../config'
Expand Down
1 change: 1 addition & 0 deletions packages/client/lib/sync/fetcher/qheap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module qheap {}
2 changes: 1 addition & 1 deletion packages/client/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from 'events'
import type { Multiaddr } from 'multiaddr'
import type { Block, BlockHeader } from '@ethereumjs/block'
import type Connection from '../../../node_modules/libp2p-interfaces/dist/src/connection/connection'
import type Connection = require('../../../node_modules/libp2p-interfaces/dist/src/connection/connection')
import type { MuxedStream } from '../../../node_modules/libp2p-interfaces/dist/src/stream-muxer/types'
import { Peer } from './net/peer'
import { Server } from './net/server'
Expand Down
3 changes: 2 additions & 1 deletion packages/client/lib/util/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { createServer } from 'http'
import { Server as RPCServer, HttpServer } from 'jayson/promise'
import { json as jsonParser } from 'body-parser'
import { decode, TAlgorithm } from 'jwt-simple'
import Connect, { IncomingMessage } from 'connect'
import * as Connect from 'connect'
import cors from 'cors'
import { inspect } from 'util'
import { RPCManager } from '../rpc'
import { Logger } from '../logging'

type IncomingMessage = Connect.IncomingMessage
const algorithm: TAlgorithm = 'HS256'

type CreateRPCServerOpts = {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"supertest": "^6.1.3",
"superwstest": "^2.0.1",
"tape": "^5.3.1",
"testdouble": "^3.8.2",
"testdouble": "^3.16.6",
"testdouble-timers": "^0.1.1",
"ts-node": "^10.2.1",
"typedoc": "^0.22.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/blockchain/chain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Block, BlockData, HeaderData } from '@ethereumjs/block'
import Blockchain from '@ethereumjs/blockchain'
import { Chain } from '../../lib/blockchain'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/cli/cli-libp2p.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChildProcessWithoutNullStreams, spawn } from 'child_process'
import tape from 'tape'
import * as tape from 'tape'

const end = (child: ChildProcessWithoutNullStreams, hasEnded: boolean, st: tape.Test) => {
if (hasEnded) return
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/cli/cli-rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChildProcessWithoutNullStreams, spawn } from 'child_process'
import tape from 'tape'
import * as tape from 'tape'
import { Client } from 'jayson/promise'

const cliArgs = ['--rpc', '--ws', '--dev', '--transports=rlpx']
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/cli/cli-sync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'child_process'
import tape from 'tape'
import * as tape from 'tape'

// get args for --network and --syncmode
const cliArgs = process.argv.filter(
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'
import { Config } from '../lib/config'
import { PeerPool } from '../lib/net/peerpool'

Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Config, DataDirectory } from '../lib/config'
import Common, { Chain } from '@ethereumjs/common'

Expand Down
8 changes: 4 additions & 4 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '@ethereumjs/blockchain'
import Common, { Chain as ChainEnum, Hardfork } from '@ethereumjs/common'
import VM from '@ethereumjs/vm'
import { Config } from '../../lib/config'
import { Chain } from '../../lib/blockchain'
import { VMExecution } from '../../lib/execution'
import blocksDataMainnet from '../testdata/blocks/mainnet.json'
import blocksDataGoerli from '../testdata/blocks/goerli.json'
import testnet from '../testdata/common/testnet.json'
import blocksDataMainnet = require('../testdata/blocks/mainnet.json')
import blocksDataGoerli = require('../testdata/blocks/goerli.json')
import testnet = require('../testdata/common/testnet.json')

tape('[VMExecution]', async (t) => {
t.test('Initialization', async (t) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/client/test/integration/beaconsync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tape from 'tape'
import * as tape from 'tape'
import Common from '@ethereumjs/common'
import { Event } from '../../lib/types'
import genesisJSON from '../testdata/geth-genesis/post-merge.json'
import * as genesisJSON from '../testdata/geth-genesis/post-merge.json'
import { parseCustomParams } from '../../lib/util'
import { wait, setup, destroy } from './util'

Expand All @@ -16,11 +16,12 @@ tape('[Integration:BeaconSync]', async (t) => {
t.test('should sync blocks', async (t) => {
const [remoteServer, remoteService] = await setup({ location: '127.0.0.2', height: 20, common })
const [localServer, localService] = await setup({ location: '127.0.0.1', height: 0, common })
const next = await remoteService.chain.getCanonicalHeadHeader()
;(localService.synchronizer as any).skeleton.status.progress.subchains = [
{
head: BigInt(21),
tail: BigInt(21),
next: (await remoteService.chain.getCanonicalHeadHeader()).hash(),
next: next.hash(),
},
]
await localService.synchronizer.stop()
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Config, SyncMode } from '../../lib/config'
import EthereumClient from '../../lib/client'
import { Event } from '../../lib/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '@ethereumjs/blockchain'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import { Block } from '@ethereumjs/block'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/fullsync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Event } from '../../lib/types'
import { wait, setup, destroy } from './util'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { setup, destroy } from './util'

tape('[Integration:LightEthereumService]', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/lightsync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { Event } from '../../lib/types'
import { wait, setup, destroy } from './util'
import { SyncMode } from '../../lib/config'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/merge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Blockchain, { CliqueConsensus } from '@ethereumjs/blockchain'
import Common, {
Chain as ChainCommon,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/miner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Blockchain, { CliqueConsensus } from '@ethereumjs/blockchain'
import Common, {
Chain as ChainCommon,
Expand Down
10 changes: 5 additions & 5 deletions packages/client/test/integration/mocks/mockpeer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events'
import pipe from 'it-pipe'
import pushable from 'it-pushable'
import * as EventEmitter from 'events'
import * as pipe from 'it-pipe'
import * as pushable from 'it-pushable'
import { Peer, PeerOptions } from '../../../lib/net/peer'
import MockServer from './mockserver'
import MockSender from './mocksender'
Expand Down Expand Up @@ -53,8 +53,8 @@ export default class MockPeer extends Peer {
async bindProtocols(stream: RemoteStream) {
const receiver = new EventEmitter()
const pushableFn: Pushable = pushable()
pipe(pushableFn, stream)
void pipe(stream, async (source: any) => {
pipe.pipe(pushableFn, stream)
void pipe.pipe(stream, async (source: any) => {
for await (const data of source) {
setTimeout(() => {
receiver.emit('data', data)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/peerpool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import Blockchain from '@ethereumjs/blockchain'
import { Config } from '../../lib/config'
import { Event } from '../../lib/types'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/logging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tape from 'tape'
import * as tape from 'tape'
import { getLogger } from '../lib/logging'

tape('[Logging]', (t) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/miner/miner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'
import Common, { Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx'
import { Block, BlockHeader } from '@ethereumjs/block'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'
import Common, { Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'
import { BlockHeader } from '@ethereumjs/block'
Expand Down
Loading

0 comments on commit c5fb316

Please sign in to comment.