Skip to content

Commit

Permalink
Revert default to namespace imports (#2842)
Browse files Browse the repository at this point in the history
* Revert default to namespace imports

* Adjust debug import syntax to make ESM happy

* Revert esModuleInterop changes

* fix qheap import and typing

* Revert more default to namespace imports

* fix json imports

* More namespace import fixes

* Update cli test in workflow

* fix kzg import

* fix more json imports

* Fix last tests

* Fix test imports
  • Loading branch information
acolytec3 committed Jun 30, 2023
1 parent 9132b40 commit 499c496
Show file tree
Hide file tree
Showing 144 changed files with 316 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/client-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ jobs:
with:
timeout_minutes: 10
max_attempts: 3
command: cd ${{github.workspace}}/packages/client && npm run tape -- 'test/sim/mainnet.spec.ts'
command: cd ${{github.workspace}}/packages/client && npm run tape -- 'test/integration/cli.spec.ts'
3 changes: 2 additions & 1 deletion packages/blockchain/src/consensus/clique.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ConsensusAlgorithm } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { Address, TypeOutput, bigIntToBytes, bytesToBigInt, toType } from '@ethereumjs/util'
import { debug as createDebugLogger } from 'debug'
import debugDefault from 'debug'
import { equalsBytes, hexToBytes } from 'ethereum-cryptography/utils.js'

import type { Blockchain } from '../index.js'
import type { Consensus, ConsensusOptions } from '../types.js'
import type { Block, BlockHeader } from '@ethereumjs/block'
import type { CliqueConfig } from '@ethereumjs/common'
const { debug: createDebugLogger } = debugDefault

const debug = createDebugLogger('blockchain:clique')

Expand Down
4 changes: 2 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
short,
toBytes,
} from '@ethereumjs/util'
import kzg from 'c-kzg'
import * as kzg from 'c-kzg'
import { existsSync, writeFileSync } from 'fs'
import { ensureDirSync, readFileSync, removeSync } from 'fs-extra'
import { Level } from 'level'
import { homedir } from 'os'
import path from 'path'
import * as path from 'path'
import readline from 'readline'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/devnets/4844-interop/tools/txGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
prefixedHexStringToBytes,
} from '@ethereumjs/util'

import kzg from 'c-kzg'
import * as kzg from 'c-kzg'
import { randomBytes } from '@ethereumjs/util'
import { Client } from 'jayson/promise'

Expand Down
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'

tape('[Libp2pNode]', async (t) => {
td.replace('libp2p')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { multiaddr } from 'multiaddr'
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'

import { Config } from '../../../src/config'
import { Event } from '../../../src/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bytesToHex, prefixedHexStringToBytes } from '@ethereumjs/util'
import tape from 'tape'
import * as tape from 'tape'

import { Libp2pSender } from '../../../src/net/protocol'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { bytesToUtf8, utf8ToBytes } from 'ethereum-cryptography/utils'
import { EventEmitter } from 'events'
import { multiaddr } from 'multiaddr'
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'

import { Config } from '../../../src/config'
import { getLogger } from '../../../src/logging'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/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 } from 'winston'

import type { Logger as WinstonLogger } from 'winston'
Expand Down
8 changes: 5 additions & 3 deletions packages/client/src/service/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
equalsBytes,
prefixedHexStringToBytes,
} from '@ethereumjs/util'
import Heap from 'qheap'

import type { Config } from '../config'
import type { Peer } from '../net/peer'
Expand All @@ -26,6 +25,9 @@ import type {
TypedTransaction,
} from '@ethereumjs/tx'
import type { VM } from '@ethereumjs/vm'
import type QHeap from 'qheap'

const Heap = require('qheap')

// Configuration constants
const MIN_GAS_PRICE_BUMP_PERCENT = 10
Expand Down Expand Up @@ -739,10 +741,10 @@ export class TxPool {
byNonce.set(address, txsSortedByNonce)
}
// Initialize a price based heap with the head transactions
const byPrice = new Heap<TypedTransaction>({
const byPrice = new Heap({
comparBefore: (a: TypedTransaction, b: TypedTransaction) =>
this.normalizedGasPrice(b, baseFee) - this.normalizedGasPrice(a, baseFee) < BigInt(0),
})
}) as QHeap<TypedTransaction>
for (const [address, txs] of byNonce) {
byPrice.insert(txs[0])
byNonce.set(address, txs.slice(1))
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/sync/fetcher/accountfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
equalsBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { debug as createDebugLogger } from 'debug'
import debugDefault from 'debug'

import { LevelDB } from '../../execution/level'
import { Event } from '../../types'
Expand All @@ -26,6 +26,7 @@ import type { FetcherOptions } from './fetcher'
import type { StorageRequest } from './storagefetcher'
import type { Job } from './types'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

type AccountDataResponse = AccountData[] & { completed?: boolean }

Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/sync/fetcher/bytecodefetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CODEHASH_PREFIX } from '@ethereumjs/statemanager'
import { Trie } from '@ethereumjs/trie'
import { bytesToHex, concatBytes, equalsBytes } from '@ethereumjs/util'
import { debug as createDebugLogger } from 'debug'
import debugDefault from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak'

import { Fetcher } from './fetcher'
Expand All @@ -11,6 +11,7 @@ import type { FetcherOptions } from './fetcher'
import type { Job } from './types'
import type { BatchDBOp } from '@ethereumjs/util'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

type ByteCodeDataResponse = Uint8Array[] & { completed?: boolean }

Expand Down
15 changes: 9 additions & 6 deletions packages/client/src/sync/fetcher/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { debug as createDebugLogger } from 'debug'
import Heap from 'qheap'
import debugDefault from 'debug'
import { Readable, Writable } from 'stream'

import { Event } from '../../types'
Expand All @@ -10,6 +9,10 @@ import type { PeerPool } from '../../net/peerpool'
import type { JobTask as BlockFetcherJobTask } from './blockfetcherbase'
import type { Job } from './types'
import type { Debugger } from 'debug'
import type QHeap from 'qheap'

const Heap = require('qheap')
const { debug: createDebugLogger } = debugDefault

export interface FetcherOptions {
/* Common chain config*/
Expand Down Expand Up @@ -52,8 +55,8 @@ export abstract class Fetcher<JobTask, JobResult, StorageItem> extends Readable
protected interval: number
protected banTime: number
protected maxQueue: number
protected in: Heap<Job<JobTask, JobResult, StorageItem>>
protected out: Heap<Job<JobTask, JobResult, StorageItem>>
protected in: QHeap<Job<JobTask, JobResult, StorageItem>>
protected out: QHeap<Job<JobTask, JobResult, StorageItem>>
protected total: number
protected processed: number // number of processed tasks, awaiting the write job
protected finished: number // number of tasks which are both processed and also finished writing
Expand Down Expand Up @@ -89,13 +92,13 @@ export abstract class Fetcher<JobTask, JobResult, StorageItem> extends Readable
a: Job<JobTask, JobResult, StorageItem>,
b: Job<JobTask, JobResult, StorageItem>
) => a.index < b.index,
})
}) as QHeap<Job<JobTask, JobResult, StorageItem>>
this.out = new Heap({
comparBefore: (
a: Job<JobTask, JobResult, StorageItem>,
b: Job<JobTask, JobResult, StorageItem>
) => a.index < b.index,
})
}) as QHeap<Job<JobTask, JobResult, StorageItem>>
this.total = 0
this.processed = 0
this.finished = 0
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/sync/fetcher/qheap.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/client/src/sync/fetcher/storagefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
equalsBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { debug as createDebugLogger } from 'debug'
import debugDefault from 'debug'

import { LevelDB } from '../../execution/level'
import { short } from '../../util'
Expand All @@ -19,6 +19,7 @@ import type { StorageData } from '../../net/protocol/snapprotocol'
import type { FetcherOptions } from './fetcher'
import type { Job } from './types'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

const TOTAL_RANGE_END = BigInt(2) ** BigInt(256) - BigInt(1)

Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/util/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { json as jsonParser } from 'body-parser'
import Connect from 'connect'
import cors from 'cors'
import * as Connect from 'connect'
import * as cors from 'cors'
import { createServer } from 'http'
import { Server as RPCServer } from 'jayson/promise'
import { decode } from 'jwt-simple'
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
Expand Up @@ -4,7 +4,7 @@ import { Block } from '@ethereumjs/block'
import { Blockchain } from '@ethereumjs/blockchain'
import { KeyEncoding, ValueEncoding } from '@ethereumjs/util'
import { bytesToHex, equalsBytes } from 'ethereum-cryptography/utils'
import tape from 'tape'
import * as tape from 'tape'

import { Chain } from '../../src/blockchain'
import { Config } from '../../src/config'
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 { spawn } from 'child_process'
import tape from 'tape'
import * as tape from 'tape'

import type { ChildProcessWithoutNullStreams } from 'child_process'

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,6 +1,6 @@
import { spawn } from 'child_process'
import { Client } from 'jayson/promise'
import tape from 'tape'
import * as tape from 'tape'

import type { ChildProcessWithoutNullStreams } from 'child_process'

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 '../src/config'
import { PeerPool } from '../src/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,5 +1,5 @@
import { Chain, Common } from '@ethereumjs/common'
import tape from 'tape'
import * as tape from 'tape'

import { Config, DataDirectory } from '../src/config'

Expand Down
10 changes: 5 additions & 5 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Blockchain } from '@ethereumjs/blockchain'
import { Chain as ChainEnum, Common, Hardfork } from '@ethereumjs/common'
import { bytesToHex } from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import tape from 'tape'
import * as tape from 'tape'

import { Chain } from '../../src/blockchain'
import { Config } from '../../src/config'
import { VMExecution } from '../../src/execution'
import { closeRPC, setupChain } from '../rpc/helpers'
import blocksDataGoerli from '../testdata/blocks/goerli.json'
import blocksDataMainnet from '../testdata/blocks/mainnet.json'
import testnet from '../testdata/common/testnet.json'
import shanghaiJSON from '../testdata/geth-genesis/withdrawals.json'
import * as blocksDataGoerli from '../testdata/blocks/goerli.json'
import * as blocksDataMainnet from '../testdata/blocks/mainnet.json'
import * as testnet from '../testdata/common/testnet.json'
import * as shanghaiJSON from '../testdata/geth-genesis/withdrawals.json'

tape('[VMExecution]', async (t) => {
t.test('Initialization', async (t) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/integration/beaconsync.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BlockHeader } from '@ethereumjs/block'
import { Common } from '@ethereumjs/common'
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'

import { Event } from '../../src/types'
import genesisJSON from '../testdata/geth-genesis/post-merge.json'
import * as genesisJSON from '../testdata/geth-genesis/post-merge.json'

import { destroy, setup, wait } from './util'

Expand Down
55 changes: 55 additions & 0 deletions packages/client/test/integration/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { spawn } from 'child_process'
import * as tape from 'tape'

tape('[CLI]', (t) => {
t.test('should start up client and execute blocks blocks', { timeout: 300000 }, (t) => {
const file = require.resolve('../../dist/bin/cli.js')
const child = spawn(process.execPath, [file, '--dev=poa'])

let hasEnded = false

const timeout = setTimeout(() => {
t.fail('timed out before finishing')
// eslint-disable-next-line @typescript-eslint/no-use-before-define
end()
}, 240000)

const end = () => {
clearTimeout(timeout)
if (!hasEnded) {
hasEnded = true
child.kill('SIGINT')
t.end()
}
}

child.stdout.on('data', (data) => {
const message = data.toString()
// log message for easier debugging
// eslint-disable-next-line no-console
console.log(message)

if (message.toLowerCase().includes('error') === true) {
t.fail(message)
return end()
}
if (message.includes('Executed') === true) {
t.pass('successfully executed blocks')
return end()
}
})

child.stderr.on('data', (data) => {
const message = data.toString()
t.fail(`stderr: ${message}`)
end()
})

child.on('close', (code) => {
if (code !== null && code > 0) {
t.fail(`child process exited with code ${code}`)
end()
}
})
})
})
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 { EthereumClient } from '../../src/client'
import { Config, SyncMode } from '../../src/config'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/integration/fullethereumservice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
prefixedHexStringToBytes,
toBytes,
} from '@ethereumjs/util'
import tape from 'tape'
import td from 'testdouble'
import * as tape from 'tape'
import * as td from 'testdouble'

import { Config } from '../../src/config'
import { FullEthereumService } from '../../src/service'
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 '../../src/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 { destroy, setup } from './util'

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 { SyncMode } from '../../src/config'
import { Event } from '../../src/types'
Expand Down
Loading

0 comments on commit 499c496

Please sign in to comment.