Skip to content

Commit

Permalink
🚧 Failed to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roninjin10 committed Nov 1, 2024
1 parent 15c75b7 commit 896092c
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { maybeThrowOnFail } from '../internal/maybeThrowOnFail.js'

// TODO tevm_call should optionally take a signature too
// When it takes a real signature (like in case of eth.sendRawTransaction) we should
// use FeeMarketEIP1559Transaction rather than Impersonated
// use FeeMarket1559Transaction rather than Impersonated
const requireSig = false

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hexToBytes, hexToNumber } from '@tevm/utils'
import { txToJsonRpcTx } from '../utils/txToJsonRpcTx.js'
import { txToJSONRPCTx } from '../utils/txToJSONRPCTx.js'

/**
* Request handler for eth_getTransactionByBlockHashAndIndex JSON-RPC requests.
Expand All @@ -25,7 +25,7 @@ export const ethGetTransactionByBlockHashAndIndexJsonRpcProcedure = (client) =>
}
return {
method: request.method,
result: txToJsonRpcTx(tx, block, txIndex),
result: txToJSONRPCTx(tx, block, txIndex),
jsonrpc: '2.0',
...(request.id ? { id: request.id } : {}),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hexToBigInt, hexToNumber } from '@tevm/utils'
import { txToJsonRpcTx } from '../utils/txToJsonRpcTx.js'
import { txToJSONRPCTx } from '../utils/txToJSONRPCTx.js'

/**
* Request handler for eth_getTransactionByBlockNumberAndIndex JSON-RPC requests.
Expand Down Expand Up @@ -42,7 +42,7 @@ export const ethGetTransactionByBlockNumberAndIndexJsonRpcProcedure = (client) =
}
return {
method: request.method,
result: txToJsonRpcTx(tx, block, txIndex),
result: txToJSONRPCTx(tx, block, txIndex),
jsonrpc: '2.0',
...(request.id ? { id: request.id } : {}),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/actions/src/eth/ethGetTransactionByHashProcedure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createJsonRpcFetcher } from '@tevm/jsonrpc'
import { hexToBytes } from '@tevm/utils'
import { txToJsonRpcTx } from '../utils/txToJsonRpcTx.js'
import { txToJSONRPCTx } from '../utils/txToJSONRPCTx.js'

/**
* Request handler for eth_getTransactionByHash JSON-RPC requests.
Expand Down Expand Up @@ -62,7 +62,7 @@ export const ethGetTransactionByHashJsonRpcProcedure = (client) => {
}
return {
method: request.method,
result: txToJsonRpcTx(tx, block, txIndex),
result: txToJSONRPCTx(tx, block, txIndex),
jsonrpc: '2.0',
...(request.id ? { id: request.id } : {}),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/actions/src/eth/ethSendTransactionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ethSendTransactionHandler = (client) => async (params) => {
const impersonatedAccount = client.getImpersonatedAccount()
if (!tx.isSigned() && impersonatedAccount !== undefined) {
/**
* @type {import("@tevm/tx").FeeMarketEIP1559Transaction & {impersonatedAddress: import('@tevm/utils').EthjsAddress} }
* @type {import("@tevm/tx").FeeMarket1559Transaction & {impersonatedAddress: import('@tevm/utils').EthjsAddress} }
**/
const impersonatedTx = /** @type {any}*/ (tx)
impersonatedTx.impersonatedAddress = createAddress(impersonatedAccount)
Expand All @@ -31,7 +31,7 @@ export const ethSendTransactionHandler = (client) => async (params) => {
'Raw Transaction is not signed. Consider calling impersonate endpoint. In future versions unsigned transactions will be rejected.',
)
/**
* @type {import("@tevm/tx").FeeMarketEIP1559Transaction & {impersonatedAddress: EthjsAddress} }
* @type {import("@tevm/tx").FeeMarket1559Transaction & {impersonatedAddress: EthjsAddress} }
**/
const impersonatedTx = /** @type {any}*/ (tx)
impersonatedTx.impersonatedAddress = createAddress(
Expand Down
4 changes: 2 additions & 2 deletions packages/actions/src/utils/blockToJsonRpcBlock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bytesToHex, numberToHex, toBytes } from '@tevm/utils'
import { txToJsonRpcTx } from './txToJsonRpcTx.js'
import { txToJSONRPCTx } from './txToJSONRPCTx.js'

/**
* @param {import('@tevm/block').Block} block
Expand All @@ -10,7 +10,7 @@ export const blockToJsonRpcBlock = async (block, includeTransactions) => {
const json = block.toJSON()
const header = /** @type {import('@tevm/block').JsonHeader}*/ (json.header)
const transactions = block.transactions.map((tx, txIndex) =>
includeTransactions ? txToJsonRpcTx(tx, block, txIndex) : bytesToHex(tx.hash()),
includeTransactions ? txToJSONRPCTx(tx, block, txIndex) : bytesToHex(tx.hash()),
)

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './SerializeToJson.js'
export * from './blockToJsonRpcBlock.js'
export * from './generateRandomId.js'
export * from './parseBlockTag.js'
export * from './txToJsonRpcTx.js'
export * from './txToJSONRPCTx.js'
2 changes: 1 addition & 1 deletion packages/actions/src/utils/txToJsonRpcTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bytesToHex, numberToHex } from '@tevm/utils'
* @param {number} [txIndex]
* @returns {import('../common/TransactionResult.js').TransactionResult}
*/
export const txToJsonRpcTx = (tx, block, txIndex) => {
export const txToJSONRPCTx = (tx, block, txIndex) => {
const txJSON = tx.toJSON()
// TODO make this typing less janky
return /** @type any*/ ({
Expand Down
10 changes: 5 additions & 5 deletions packages/actions/src/utils/txToJsonRpcTx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { getBlockFromRpc } from '@tevm/blockchain'
import { optimism } from '@tevm/common'
import { createTevmNode } from '@tevm/node'
import { transports } from '@tevm/test-utils'
import { FeeMarketEIP1559Transaction } from '@tevm/tx'
import { FeeMarket1559Transaction } from '@tevm/tx'
import { EthjsAddress } from '@tevm/utils'
import { describe, expect, it } from 'vitest'
import { txToJsonRpcTx } from './txToJsonRpcTx.js'
import { txToJSONRPCTx } from './txToJSONRPCTx.js'

describe(txToJsonRpcTx.name, () => {
describe(txToJSONRPCTx.name, () => {
it('should work', async () => {
const tx = new FeeMarketEIP1559Transaction({
const tx = new FeeMarket1559Transaction({
to: EthjsAddress.fromString(`0x${'a'.repeat(40)}`),
data: Uint8Array.from([1, 2, 3]),
value: 100n,
Expand All @@ -31,6 +31,6 @@ describe(txToJsonRpcTx.name, () => {
{ blockTag: 121960766n, transport: transports.optimism },
vm.common,
)
expect(txToJsonRpcTx(tx, block, 0)).toMatchSnapshot()
expect(txToJSONRPCTx(tx, block, 0)).toMatchSnapshot()
})
})
4 changes: 2 additions & 2 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { executionPayloadFromBeaconPayload } from './from-beacon-payload.js'
import { BlockHeader } from './header.js'

import type { Common } from '@tevm/common'
import type { FeeMarketEIP1559Transaction, LegacyTransaction, TypedTransaction } from '@tevm/tx'
import type { FeeMarket1559Transaction, LegacyTransaction, TypedTransaction } from '@tevm/tx'
import { ClRequest } from './ClRequest.js'
import type { BeaconPayloadJson } from './from-beacon-payload.js'
import type {
Expand Down Expand Up @@ -509,7 +509,7 @@ export class Block {
const errs = tx.getValidationErrors()
if (this.common.ethjsCommon.isActivatedEIP(1559)) {
if (tx.supports(Capability.EIP1559FeeMarket)) {
tx = tx as FeeMarketEIP1559Transaction
tx = tx as FeeMarket1559Transaction
if (tx.maxFeePerGas < (this.header.baseFeePerGas as bigint)) {
errs.push('tx unable to pay base fee (EIP-1559 tx)')
}
Expand Down
6 changes: 3 additions & 3 deletions packages/block/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Common } from '@tevm/common'
import type { JsonRpcTx, JsonTx, TransactionType, TxData } from '@tevm/tx'
import type { JSONRPCTx, JSONTx, TransactionType, TxData } from '@tevm/tx'
import type { AddressLike, BigIntLike, BytesLike, Hex, JsonRpcWithdrawal, WithdrawalData } from '@tevm/utils'
import type { ClRequest } from './ClRequest.js'
import type { BlockHeader } from './header.js'
Expand Down Expand Up @@ -180,7 +180,7 @@ export interface JsonBlock {
* Header data for the block
*/
header?: JsonHeader
transactions?: JsonTx[]
transactions?: JSONTx[]
uncleHeaders?: JsonHeader[]
withdrawals?: JsonRpcWithdrawal[]
requests?: Hex[] | null
Expand Down Expand Up @@ -238,7 +238,7 @@ export interface JsonRpcBlock {
gasLimit: Hex | string // the maximum gas allowed in this block.
gasUsed: Hex | string // the total used gas by all transactions in this block.
timestamp: Hex | string // the unix timestamp for when the block was collated.
transactions: Array<JsonRpcTx | Hex | string> // Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
transactions: Array<JSONRPCTx | Hex | string> // Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles: Hex[] | string[] // Array of uncle hashes
baseFeePerGas?: Hex | string // If EIP-1559 is enabled for this block, returns the base fee per gas
withdrawals?: Array<JsonRpcWithdrawal> // If EIP-4895 is enabled for this block, array of withdrawals
Expand Down
4 changes: 2 additions & 2 deletions packages/tx/src/ImpersonatedTx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import type { FeeMarket1559Transaction } from '@ethereumjs/tx'

export interface ImpersonatedTx extends FeeMarketEIP1559Transaction {
export interface ImpersonatedTx extends FeeMarket1559Transaction {
isImpersonated: true
}
10 changes: 5 additions & 5 deletions packages/tx/src/createImpersonatedTx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import { FeeMarket1559Transaction } from '@ethereumjs/tx'
import { InternalError, InvalidGasLimitError } from '@tevm/errors'
import { EthjsAddress, keccak256 } from '@tevm/utils'

Expand All @@ -7,24 +7,24 @@ import { EthjsAddress, keccak256 } from '@tevm/utils'
*/

/**
* Creates an impersonated tx that wraps {@link FeeMarketEIP1559Transaction}.
* Creates an impersonated tx that wraps {@link FeeMarket1559Transaction}.
* Wraps following methods
* - 'isImpersonated'
* - 'hash'
* - 'isSigned'
* - 'getSenderAddress'
* @throws {CreateImpersonatedTxError} Error if the constructor for {@link FeeMarketEIP1559Transaction} throws
* @throws {CreateImpersonatedTxError} Error if the constructor for {@link FeeMarket1559Transaction} throws
* @param {import("@ethereumjs/tx").FeeMarketEIP1559TxData & {impersonatedAddress: EthjsAddress}} txData
* @param {import("@ethereumjs/tx").TxOptions} [opts]
* @returns {import('./ImpersonatedTx.js').ImpersonatedTx}
*/
export const createImpersonatedTx = (txData, opts) => {
/**
* @type {FeeMarketEIP1559Transaction}
* @type {FeeMarket1559Transaction}
*/
let tx
try {
tx = new FeeMarketEIP1559Transaction(txData, opts)
tx = new FeeMarket1559Transaction(txData, opts)
} catch (e) {
if (!(e instanceof Error)) {
throw new InternalError('Unknown Error', { cause: /** @type any*/ (e) })
Expand Down
24 changes: 12 additions & 12 deletions packages/tx/src/createImpersonatedTx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Common } from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import { FeeMarket1559Transaction } from '@ethereumjs/tx'
import { InternalError, InvalidGasLimitError } from '@tevm/errors'
import { EthjsAddress } from '@tevm/utils'
import { type MockedFunction, afterEach, describe, expect, it, vi } from 'vitest'
Expand All @@ -9,21 +9,21 @@ vi.mock('@ethereumjs/tx', async () => {
const actualEthjsTx = (await vi.importActual('@ethereumjs/tx')) as any
const mockClass = vi.fn()
mockClass.mockImplementation((...args: any[]) => {
return new actualEthjsTx.FeeMarketEIP1559Transaction(...args)
return new actualEthjsTx.FeeMarket1559Transaction(...args)
})
return {
...actualEthjsTx,
FeeMarketEIP1559Transaction: mockClass,
FeeMarket1559Transaction: mockClass,
}
})

const FeeMarketEIP1559TransactionMock = FeeMarketEIP1559Transaction as unknown as MockedFunction<any>
const FeeMarket1559TransactionMock = FeeMarket1559Transaction as unknown as MockedFunction<any>

afterEach(async () => {
vi.resetAllMocks()
const actualEthjsTx = (await vi.importActual('@ethereumjs/tx')) as any
FeeMarketEIP1559TransactionMock.mockImplementation((...args: any[]) => {
return new actualEthjsTx.FeeMarketEIP1559Transaction(...args)
FeeMarket1559TransactionMock.mockImplementation((...args: any[]) => {
return new actualEthjsTx.FeeMarket1559Transaction(...args)
})
})

Expand Down Expand Up @@ -75,7 +75,7 @@ describe(createImpersonatedTx.name, () => {
const ethjsError = new Error(
'gasLimit cannot exceed MAX_UINT64 (2^64-1), given 374144419156711147060143317175368453031918731001855 (tx type=2 hash=not available (unsigned) nonce=0 value=0 signed=false hf=error maxFeePerGas=undefined maxPriorityFeePerGas=undefined)',
)
FeeMarketEIP1559TransactionMock.mockImplementation(() => {
FeeMarket1559TransactionMock.mockImplementation(() => {
throw ethjsError
})
expect(() => createImpersonatedTx({ impersonatedAddress, data, gasLimit: `0x${'ff'.repeat(21)}` })).toThrow(
Expand All @@ -87,7 +87,7 @@ describe(createImpersonatedTx.name, () => {
const expectedError = new Error(
'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)',
)
FeeMarketEIP1559TransactionMock.mockImplementation(() => {
FeeMarket1559TransactionMock.mockImplementation(() => {
throw expectedError
})
const impersonatedAddress = EthjsAddress.fromString(`0x${'42'.repeat(20)}`)
Expand All @@ -97,9 +97,9 @@ describe(createImpersonatedTx.name, () => {
)
})

it('should throw an error if FeeMarketEIP1559Transaction throws', () => {
it('should throw an error if FeeMarket1559Transaction throws', () => {
const expectedError = new Error('Constructor error')
FeeMarketEIP1559TransactionMock.mockImplementation(() => {
FeeMarket1559TransactionMock.mockImplementation(() => {
throw expectedError
})

Expand All @@ -110,9 +110,9 @@ describe(createImpersonatedTx.name, () => {
)
})

it('should throw an error if FeeMarketEIP1559Transaction throws non error', () => {
it('should throw an error if FeeMarket1559Transaction throws non error', () => {
const notError = { not: 'error' }
FeeMarketEIP1559TransactionMock.mockImplementation(() => {
FeeMarket1559TransactionMock.mockImplementation(() => {
throw notError
})
const impersonatedAddress = EthjsAddress.fromString(`0x${'42'.repeat(20)}`)
Expand Down
14 changes: 7 additions & 7 deletions packages/tx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ export {
type TxOptions,
TransactionType,
LegacyTransaction,
AccessListEIP2930Transaction,
FeeMarketEIP1559Transaction,
AccessList2930Transaction,
FeeMarket1559Transaction,
BlobEIP4844Transaction,
TransactionFactory,
Capability,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isFeeMarketEIP1559Tx,
isAccessList2930Tx,
isBlob4844Tx,
isFeeMarket1559Tx,
isLegacyTx,
type JsonRpcTx,
type JsonTx,
type JSONRPCTx,
type JSONTx,
type AccessList,
type AccessListItem,
} from '@ethereumjs/tx'
Expand Down
16 changes: 8 additions & 8 deletions packages/txpool/src/TxPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import {
BlobEIP4844Transaction,
Capability,
isAccessListEIP2930Tx,
isBlobEIP4844Tx,
isFeeMarketEIP1559Tx,
isAccessList2930Tx,
isBlob4844Tx,
isFeeMarket1559Tx,
isLegacyTx,
} from '@tevm/tx'
import { EthjsAccount, EthjsAddress, bytesToHex, bytesToUnprefixedHex, equalsBytes } from '@tevm/utils'
import type { Vm } from '@tevm/vm'

import type { Block } from '@tevm/block'
import {
type FeeMarketEIP1559Transaction,
type FeeMarket1559Transaction,
type ImpersonatedTx,
type LegacyTransaction,
type TypedTransaction,
Expand Down Expand Up @@ -409,12 +409,12 @@ export class TxPool {
const supports1559 = tx.supports(Capability.EIP1559FeeMarket)
if (typeof baseFee === 'bigint' && baseFee !== 0n) {
if (supports1559) {
return (tx as FeeMarketEIP1559Transaction).maxPriorityFeePerGas
return (tx as FeeMarket1559Transaction).maxPriorityFeePerGas
}
return (tx as LegacyTransaction).gasPrice - baseFee
}
if (supports1559) {
return (tx as FeeMarketEIP1559Transaction).maxFeePerGas
return (tx as FeeMarket1559Transaction).maxFeePerGas
}
return (tx as LegacyTransaction).gasPrice
}
Expand All @@ -437,14 +437,14 @@ export class TxPool {
}
}

if (isAccessListEIP2930Tx(tx)) {
if (isAccessList2930Tx(tx)) {
return {
maxFee: tx.gasPrice,
tip: tx.gasPrice,
}
}

if (isFeeMarketEIP1559Tx(tx) || isBlobEIP4844Tx(tx)) {
if (isFeeMarket1559Tx(tx) || isBlob4844Tx(tx)) {
return {
maxFee: tx.maxFeePerGas,
tip: tx.maxPriorityFeePerGas,
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/actions/buildBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createChain } from '@tevm/blockchain'
import { mainnet } from '@tevm/common'
import { createEvm } from '@tevm/evm'
import { createStateManager } from '@tevm/state'
import { FeeMarketEIP1559Transaction } from '@tevm/tx'
import { FeeMarket1559Transaction } from '@tevm/tx'
import {
type Address,
EthjsAccount,
Expand Down Expand Up @@ -89,7 +89,7 @@ describe(buildBlock.name, () => {
await stateManager.checkpoint()
await stateManager.commit()

const tx = FeeMarketEIP1559Transaction.fromTxData({
const tx = FeeMarket1559Transaction.fromTxData({
data: hexToBytes(
encodeFunctionData({
abi: MOCKERC20_ABI,
Expand Down
Loading

0 comments on commit 896092c

Please sign in to comment.