|
1 | 1 | import { Common, Mainnet } from '@ethereumjs/common'
|
2 |
| -import { bytesToHex, hexToBytes } from '@ethereumjs/util' |
| 2 | +import { EthereumJSErrorWithoutCode, bytesToHex, hexToBytes } from '@ethereumjs/util' |
3 | 3 | import minimist from 'minimist'
|
4 | 4 | import { assert, describe, it } from 'vitest'
|
5 | 5 |
|
@@ -62,47 +62,49 @@ describe('TransactionTests', async () => {
|
62 | 62 | testName: string,
|
63 | 63 | testData: OfficialTransactionTestData,
|
64 | 64 | ) => {
|
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}]`, () => { |
70 | 70 | const forkTestData = testData.result[forkName]
|
71 | 71 | const shouldBeInvalid = forkTestData.exception !== undefined
|
72 | 72 |
|
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 | + } |
87 | 80 |
|
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') |
96 | 91 | }
|
| 92 | + isValid = true |
97 | 93 | } 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') |
102 | 96 | }
|
| 97 | + // Tx is correctly marked as "invalid", so test has passed |
| 98 | + return |
103 | 99 | }
|
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 | + } |
106 | 108 | },
|
107 | 109 | fileFilterRegex,
|
108 | 110 | undefined,
|
|
0 commit comments