Skip to content

Commit bdc7eb1

Browse files
tx: migrate test data to js (#3684)
* tx: migrate test data * tx: remove script --------- Co-authored-by: Holger Drewes <[email protected]>
1 parent 6714f0d commit bdc7eb1

25 files changed

+684
-667
lines changed

packages/tx/test/base.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import {
3030
paramsTx,
3131
} from '../src/index.js'
3232

33-
import eip1559Fixtures from './json/eip1559txs.json'
34-
import eip2930Fixtures from './json/eip2930txs.json'
35-
import legacyFixtures from './json/txs.json'
33+
import { eip1559TxsData } from './testData/eip1559txs.js'
34+
import { eip2930TxsData } from './testData/eip2930txs.js'
35+
import { txsData } from './testData/txs.js'
3636

3737
import type { BaseTransaction } from '../src/baseTransaction.js'
3838
import type { AccessList2930TxData, FeeMarketEIP1559TxData, LegacyTxData } from '../src/index.js'
@@ -42,17 +42,17 @@ describe('[BaseTransaction]', () => {
4242
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
4343

4444
const legacyTxs: BaseTransaction<TransactionType.Legacy>[] = []
45-
for (const tx of legacyFixtures.slice(0, 4)) {
45+
for (const tx of txsData.slice(0, 4)) {
4646
legacyTxs.push(createLegacyTx(tx.data as LegacyTxData, { common }))
4747
}
4848

4949
const eip2930Txs: BaseTransaction<TransactionType.AccessListEIP2930>[] = []
50-
for (const tx of eip2930Fixtures) {
50+
for (const tx of eip2930TxsData) {
5151
eip2930Txs.push(createAccessList2930Tx(tx.data as AccessList2930TxData, { common }))
5252
}
5353

5454
const eip1559Txs: BaseTransaction<TransactionType.FeeMarketEIP1559>[] = []
55-
for (const tx of eip1559Fixtures) {
55+
for (const tx of eip1559TxsData) {
5656
eip1559Txs.push(createFeeMarket1559Tx(tx.data as FeeMarketEIP1559TxData, { common }))
5757
}
5858

@@ -64,7 +64,7 @@ describe('[BaseTransaction]', () => {
6464
type: TransactionType.Legacy,
6565
values: Array(6).fill(zero),
6666
txs: legacyTxs,
67-
fixtures: legacyFixtures,
67+
fixtures: txsData,
6868
activeCapabilities: [],
6969
create: {
7070
txData: createLegacyTx,
@@ -84,7 +84,7 @@ describe('[BaseTransaction]', () => {
8484
type: TransactionType.AccessListEIP2930,
8585
values: [new Uint8Array([1])].concat(Array(7).fill(zero)),
8686
txs: eip2930Txs,
87-
fixtures: eip2930Fixtures,
87+
fixtures: eip2930TxsData,
8888
activeCapabilities: [Capability.EIP2718TypedTransaction, Capability.EIP2930AccessLists],
8989
create: {
9090
txData: createAccessList2930Tx,
@@ -99,7 +99,7 @@ describe('[BaseTransaction]', () => {
9999
type: TransactionType.FeeMarketEIP1559,
100100
values: [new Uint8Array([1])].concat(Array(8).fill(zero)),
101101
txs: eip1559Txs,
102-
fixtures: eip1559Fixtures,
102+
fixtures: eip1559TxsData,
103103
activeCapabilities: [
104104
Capability.EIP1559FeeMarket,
105105
Capability.EIP2718TypedTransaction,

packages/tx/test/eip1559.spec.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { assert, describe, it } from 'vitest'
55

66
import { createFeeMarket1559Tx } from '../src/index.js'
77

8-
import testdata from './json/eip1559.json' // Source: Besu
8+
import { eip1559Data } from './testData/eip1559.js' // Source: Besu
99

10-
import type { FeeMarketEIP1559TxData, JSONTx } from '../src/index.js'
11-
import type { PrefixedHexString } from '@ethereumjs/util'
10+
import type { JSONTx } from '../src/index.js'
1211

1312
const common = createCustomCommon({ chainId: 4 }, Mainnet)
1413
common.setHardfork(Hardfork.London)
@@ -106,21 +105,21 @@ describe('[FeeMarket1559Tx]', () => {
106105
})
107106

108107
it('sign()', () => {
109-
for (let index = 0; index < testdata.length; index++) {
110-
const data = testdata[index]
111-
const pkey = hexToBytes(data.privateKey as PrefixedHexString)
112-
const txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, { common })
108+
for (let index = 0; index < eip1559Data.length; index++) {
109+
const data = eip1559Data[index]
110+
const pkey = hexToBytes(data.privateKey)
111+
const txn = createFeeMarket1559Tx(data, { common })
113112
const signed = txn.sign(pkey)
114113
const rlpSerialized = RLP.encode(Uint8Array.from(signed.serialize()))
115114
assert.ok(
116-
equalsBytes(rlpSerialized, hexToBytes(data.signedTransactionRLP as PrefixedHexString)),
115+
equalsBytes(rlpSerialized, hexToBytes(data.signedTransactionRLP)),
117116
'Should sign txs correctly',
118117
)
119118
}
120119
})
121120

122121
it('addSignature() -> correctly adds correct signature values', () => {
123-
const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString)
122+
const privKey = hexToBytes(eip1559Data[0].privateKey)
124123
const tx = createFeeMarket1559Tx({})
125124
const signedTx = tx.sign(privKey)
126125
const addSignatureTx = tx.addSignature(signedTx.v!, signedTx.r!, signedTx.s!)
@@ -129,7 +128,7 @@ describe('[FeeMarket1559Tx]', () => {
129128
})
130129

131130
it('addSignature() -> correctly converts raw ecrecover values', () => {
132-
const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString)
131+
const privKey = hexToBytes(eip1559Data[0].privateKey)
133132
const tx = createFeeMarket1559Tx({})
134133

135134
const msgHash = tx.getHashedMessageToSign()
@@ -142,7 +141,7 @@ describe('[FeeMarket1559Tx]', () => {
142141
})
143142

144143
it('addSignature() -> throws when adding the wrong v value', () => {
145-
const privKey = hexToBytes(testdata[0].privateKey as PrefixedHexString)
144+
const privKey = hexToBytes(eip1559Data[0].privateKey)
146145
const tx = createFeeMarket1559Tx({})
147146

148147
const msgHash = tx.getHashedMessageToSign()
@@ -155,9 +154,9 @@ describe('[FeeMarket1559Tx]', () => {
155154
})
156155

157156
it('hash()', () => {
158-
const data = testdata[0]
159-
const pkey = hexToBytes(data.privateKey as PrefixedHexString)
160-
let txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, { common })
157+
const data = eip1559Data[0]
158+
const pkey = hexToBytes(data.privateKey)
159+
let txn = createFeeMarket1559Tx(data, { common })
161160
let signed = txn.sign(pkey)
162161
const expectedHash = hexToBytes(
163162
'0x2e564c87eb4b40e7f469b2eec5aa5d18b0b46a24e8bf0919439cfb0e8fcae446',
@@ -166,7 +165,7 @@ describe('[FeeMarket1559Tx]', () => {
166165
equalsBytes(signed.hash(), expectedHash),
167166
'Should provide the correct hash when frozen',
168167
)
169-
txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, {
168+
txn = createFeeMarket1559Tx(data, {
170169
common,
171170
freeze: false,
172171
})
@@ -178,9 +177,9 @@ describe('[FeeMarket1559Tx]', () => {
178177
})
179178

180179
it('freeze property propagates from unsigned tx to signed tx', () => {
181-
const data = testdata[0]
182-
const pkey = hexToBytes(data.privateKey as PrefixedHexString)
183-
const txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, {
180+
const data = eip1559Data[0]
181+
const pkey = hexToBytes(data.privateKey)
182+
const txn = createFeeMarket1559Tx(data, {
184183
common,
185184
freeze: false,
186185
})
@@ -190,9 +189,9 @@ describe('[FeeMarket1559Tx]', () => {
190189
})
191190

192191
it('common propagates from the common of tx, not the common in TxOptions', () => {
193-
const data = testdata[0]
194-
const pkey = hexToBytes(data.privateKey as PrefixedHexString)
195-
const txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, {
192+
const data = eip1559Data[0]
193+
const pkey = hexToBytes(data.privateKey)
194+
const txn = createFeeMarket1559Tx(data, {
196195
common,
197196
freeze: false,
198197
})
@@ -239,9 +238,9 @@ describe('[FeeMarket1559Tx]', () => {
239238
})
240239

241240
it('toJSON()', () => {
242-
const data = testdata[0]
243-
const pkey = hexToBytes(data.privateKey as PrefixedHexString)
244-
const txn = createFeeMarket1559Tx(data as FeeMarketEIP1559TxData, { common })
241+
const data = eip1559Data[0]
242+
const pkey = hexToBytes(data.privateKey)
243+
const txn = createFeeMarket1559Tx(data, { common })
245244
const signed = txn.sign(pkey)
246245

247246
const json = signed.toJSON()

packages/tx/test/eip4844.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
paramsTx,
2727
} from '../src/index.js'
2828

29-
import blobTx from './json/serialized4844tx.json'
29+
import { serialized4844TxData } from './testData/serialized4844tx.js'
3030

3131
import type { BlobEIP4844TxData } from '../src/index.js'
3232
import type { Common } from '@ethereumjs/common'
@@ -657,7 +657,7 @@ describe('Network wrapper deserialization test', () => {
657657
const commitments = blobsToCommitments(kzg, blobs)
658658
const proofs = blobsToProofs(kzg, blobs, commitments)
659659

660-
const wrapper = hexToBytes(blobTx.tx as PrefixedHexString)
660+
const wrapper = hexToBytes(serialized4844TxData.tx as PrefixedHexString)
661661
const deserializedTx = createBlob4844TxFromSerializedNetworkWrapper(wrapper, {
662662
common,
663663
})
@@ -677,7 +677,7 @@ describe('Network wrapper deserialization test', () => {
677677
const networkSerialized = bytesToHex(deserializedTx.serializeNetworkWrapper())
678678
const serialized = bytesToHex(deserializedTx.serialize())
679679
const sender = deserializedTx.getSenderAddress().toString()
680-
assert.equal(networkSerialized, blobTx.tx, 'network serialization should match')
680+
assert.equal(networkSerialized, serialized4844TxData.tx, 'network serialization should match')
681681

682682
assert.deepEqual(
683683
txMeta,

packages/tx/test/eip7702.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const common = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun, eips: [77
2222
const pkey = hexToBytes(`0x${'20'.repeat(32)}`)
2323
const addr = createAddressFromPrivateKey(pkey)
2424

25-
const ones32 = `0x${'01'.repeat(32)}` as PrefixedHexString
25+
const ones32: PrefixedHexString = `0x${'01'.repeat(32)}`
2626

2727
function getTxData(override: Partial<AuthorizationListItem> = {}): TxData {
2828
const validAuthorizationList: AuthorizationListItem = {

packages/tx/test/fromRpc.spec.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
} from '../src/index.js'
1111
import { normalizeTxParams } from '../src/util.js'
1212

13-
import optimismTx from './json/optimismTx.json'
14-
import rpcTx from './json/rpcTx.json'
15-
import v0Tx from './json/v0tx.json'
13+
import { optimismTxData } from './testData/optimismTx.js'
14+
import { rpcTxData } from './testData/rpcTx.js'
15+
import { v0txData } from './testData/v0tx.js'
1616

1717
import type { TypedTxData } from '../src/index.js'
1818

@@ -32,13 +32,13 @@ describe('[fromJSONRPCProvider]', () => {
3232
global.fetch = async (_url: string, req: any) => {
3333
const json = JSON.parse(req.body)
3434
if (json.params[0] === '0xed1960aa7d0d7b567c946d94331dddb37a1c67f51f30bf51f256ea40db88cfb0') {
35-
const txData = await import(`./json/rpcTx.json`)
35+
const { rpcTxData } = await import(`./testData/rpcTx.js`)
3636
return {
3737
ok: true,
3838
status: 200,
3939
json: () => {
4040
return {
41-
result: txData,
41+
result: rpcTxData,
4242
}
4343
},
4444
}
@@ -73,12 +73,12 @@ describe('[fromJSONRPCProvider]', () => {
7373

7474
describe('[normalizeTxParams]', () => {
7575
it('should work', () => {
76-
const normedTx = normalizeTxParams(rpcTx)
76+
const normedTx = normalizeTxParams(rpcTxData)
7777
const tx = createTx(normedTx)
7878
assert.equal(normedTx.gasLimit, 21000n, 'correctly converted "gas" to "gasLimit"')
7979
assert.equal(
8080
bytesToHex(tx.hash()),
81-
rpcTx.hash,
81+
rpcTxData.hash,
8282
'converted normed tx data to transaction object',
8383
)
8484
})
@@ -87,8 +87,7 @@ describe('[normalizeTxParams]', () => {
8787
describe('fromRPC: interpret v/r/s values of 0x0 as undefined for Optimism system txs', () => {
8888
it('should work', async () => {
8989
for (const txType of txTypes) {
90-
;(optimismTx as any).type = txType
91-
const tx = await createTxFromRPC(optimismTx as TypedTxData)
90+
const tx = await createTxFromRPC({ ...optimismTxData, type: txType } as TypedTxData)
9291
assert.ok(tx.v === undefined)
9392
assert.ok(tx.s === undefined)
9493
assert.ok(tx.r === undefined)
@@ -106,9 +105,8 @@ describe('fromRPC: ensure `v="0x0"` is correctly decoded for signed txs', () =>
106105
// legacy tx cannot have v=0
107106
continue
108107
}
109-
;(v0Tx as any).type = txType
110108
const common = createCustomCommon({ chainId: 0x10f2c }, Mainnet)
111-
const tx = await createTxFromRPC(v0Tx as TypedTxData, { common })
109+
const tx = await createTxFromRPC({ ...v0txData, type: txType } as TypedTxData, { common })
112110
assert.ok(tx.isSigned())
113111
}
114112
})

packages/tx/test/json/eip1559.json

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)