Skip to content

Commit 99c7b38

Browse files
Tx: fix transaction tester (#3942)
* tx: transaction runner: update tester to correctly test * tx: 7702 add check which bans nested lists inside authority items * tx: add fork to test name * tx: fix test runner v2
1 parent 396094a commit 99c7b38

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

packages/tx/src/capabilities/eip7702.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export function verifyAuthorizationList(tx: EIP7702CompatibleTx) {
3636
'Invalid EIP-7702 transaction: authorization list item should have 6 elements',
3737
)
3838
}
39+
40+
for (const member of item) {
41+
// This checks if the `member` is a list, not bytes
42+
// This checks that the authority list does not have any embedded lists in it
43+
if (Array.isArray(member)) {
44+
throw EthereumJSErrorWithoutCode(
45+
'Invalid EIP-7702 transaction: authority list element is a list, not bytes',
46+
)
47+
}
48+
}
49+
3950
const [chainId, address, nonce, yParity, r, s] = item
4051

4152
validateNoLeadingZeroes({ yParity, r, s, nonce, chainId })

packages/tx/test/transactionRunner.spec.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Common, Mainnet } from '@ethereumjs/common'
2-
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
2+
import { EthereumJSErrorWithoutCode, bytesToHex, hexToBytes } from '@ethereumjs/util'
33
import minimist from 'minimist'
44
import { assert, describe, it } from 'vitest'
55

@@ -62,47 +62,49 @@ describe('TransactionTests', async () => {
6262
testName: string,
6363
testData: OfficialTransactionTestData,
6464
) => {
65-
it(testName, () => {
66-
for (const forkName of forkNames) {
67-
if (testData.result[forkName] === undefined) {
68-
continue
69-
}
65+
for (const forkName of forkNames) {
66+
if (testData.result[forkName] === undefined) {
67+
continue
68+
}
69+
it(`${testName} - [${forkName}]`, () => {
7070
const forkTestData = testData.result[forkName]
7171
const shouldBeInvalid = forkTestData.exception !== undefined
7272

73-
try {
74-
const rawTx = hexToBytes(testData.txbytes as PrefixedHexString)
75-
const hardfork = forkNameMap[forkName]
76-
const common = new Common({ chain: Mainnet, hardfork })
77-
const activateEIPs = EIPs[forkName]
78-
if (activateEIPs !== undefined) {
79-
common.setEIPs(activateEIPs)
80-
}
81-
const tx = createTxFromRLP(rawTx, { common })
82-
const sender = tx.getSenderAddress().toString()
83-
const hash = bytesToHex(tx.hash())
84-
const txIsValid = tx.isValid()
85-
const senderIsCorrect = forkTestData.sender === sender
86-
const hashIsCorrect = forkTestData.hash === hash
73+
const rawTx = hexToBytes(testData.txbytes as PrefixedHexString)
74+
const hardfork = forkNameMap[forkName]
75+
const common = new Common({ chain: Mainnet, hardfork })
76+
const activateEIPs = EIPs[forkName]
77+
if (activateEIPs !== undefined) {
78+
common.setEIPs(activateEIPs)
79+
}
8780

88-
const hashAndSenderAreCorrect = senderIsCorrect && hashIsCorrect
89-
if (shouldBeInvalid) {
90-
assert.isFalse(txIsValid, `Transaction should be invalid on ${forkName}`)
91-
} else {
92-
assert.isTrue(
93-
hashAndSenderAreCorrect && txIsValid,
94-
`Transaction should be valid on ${forkName}`,
95-
)
81+
let tx
82+
let sender
83+
let hash
84+
let isValid
85+
try {
86+
tx = createTxFromRLP(rawTx, { common })
87+
sender = tx.getSenderAddress().toString()
88+
hash = bytesToHex(tx.hash())
89+
if (!tx.isValid()) {
90+
throw EthereumJSErrorWithoutCode('Tx is invalid')
9691
}
92+
isValid = true
9793
} catch {
98-
if (shouldBeInvalid) {
99-
assert.isTrue(shouldBeInvalid, `Transaction should be invalid on ${forkName}`)
100-
} else {
101-
assert.fail(`Transaction should be valid on ${forkName}`)
94+
if (!shouldBeInvalid) {
95+
assert.fail('Tx creation threw an error, but should be valid')
10296
}
97+
// Tx is correctly marked as "invalid", so test has passed
98+
return
10399
}
104-
}
105-
}, 120000)
100+
101+
const senderIsCorrect = forkTestData.sender === sender
102+
const hashIsCorrect = forkTestData.hash === hash
103+
assert.isTrue(isValid, 'tx is valid')
104+
assert.isTrue(senderIsCorrect, 'sender is correct')
105+
assert.isTrue(hashIsCorrect, 'hash is correct')
106+
}, 120000)
107+
}
106108
},
107109
fileFilterRegex,
108110
undefined,

0 commit comments

Comments
 (0)