@@ -2,8 +2,18 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
22import { Address , toBuffer } from '@ethereumjs/util'
33import * as tape from 'tape'
44
5- import { Transaction } from '../src'
6-
5+ import {
6+ AccessListEIP2930Transaction ,
7+ FeeMarketEIP1559Transaction ,
8+ Transaction ,
9+ TransactionFactory ,
10+ } from '../src'
11+
12+ import type {
13+ AccessListEIP2930ValuesArray ,
14+ FeeMarketEIP1559ValuesArray ,
15+ TxValuesArray ,
16+ } from '../src'
717import type { AddressLike , BigIntLike , BufferLike } from '@ethereumjs/util'
818
919// @returns : Array with subtypes of the AddressLike type for a given address
@@ -136,3 +146,109 @@ tape('[Transaction Input Values]', function (t) {
136146 st . end ( )
137147 } )
138148} )
149+
150+ tape ( '[Invalid Array Input values]' , ( t ) => {
151+ const txTypes = [ 0x0 , 0x1 , 0x2 ]
152+ for ( const signed of [ false , true ] ) {
153+ for ( const txType of txTypes ) {
154+ let tx = TransactionFactory . fromTxData ( { type : txType } )
155+ if ( signed ) {
156+ tx = tx . sign ( Buffer . from ( '42' . repeat ( 32 ) , 'hex' ) )
157+ }
158+ const rawValues = tx . raw ( )
159+ for ( let x = 0 ; x < rawValues . length ; x ++ ) {
160+ rawValues [ x ] = < any > [ 1 , 2 , 3 ]
161+ switch ( txType ) {
162+ case 0 :
163+ t . throws ( ( ) => Transaction . fromValuesArray ( rawValues as TxValuesArray ) )
164+ break
165+ case 1 :
166+ t . throws ( ( ) =>
167+ AccessListEIP2930Transaction . fromValuesArray (
168+ rawValues as AccessListEIP2930ValuesArray
169+ )
170+ )
171+ break
172+ case 2 :
173+ t . throws ( ( ) =>
174+ FeeMarketEIP1559Transaction . fromValuesArray ( rawValues as FeeMarketEIP1559ValuesArray )
175+ )
176+ break
177+ }
178+ }
179+ }
180+ }
181+ t . end ( )
182+ } )
183+
184+ tape ( '[Invalid Access Lists]' , ( t ) => {
185+ const txTypes = [ 0x1 , 0x2 ]
186+ const invalidAccessLists = [
187+ [ [ ] ] , // does not have an address and does not have slots
188+ [ [ [ ] , [ ] ] ] , // the address is an array
189+ [ [ '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ] ] , // there is no storage slot array
190+ [
191+ [
192+ '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ,
193+ [ '0x0000000000000000000000000000000000000000000000000000000000000003' , [ ] ] ,
194+ ] ,
195+ ] , // one of the slots is an array
196+ [
197+ [
198+ '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ,
199+ [ '0x0000000000000000000000000000000000000000000000000000000000000003' ] ,
200+ '0xab' ,
201+ ] ,
202+ ] , // extra field
203+ [
204+ '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' ,
205+ [ '0x0000000000000000000000000000000000000000000000000000000000000003' ] ,
206+ ] , // account/slot needs to be encoded in a deeper array layer
207+ ]
208+ for ( const signed of [ false , true ] ) {
209+ for ( const txType of txTypes ) {
210+ for ( const invalidAccessListItem of invalidAccessLists ) {
211+ let tx : any
212+ try {
213+ tx = TransactionFactory . fromTxData ( {
214+ type : txType ,
215+ accessList : < any > invalidAccessListItem ,
216+ } )
217+ if ( signed ) {
218+ tx = tx . sign ( Buffer . from ( '42' . repeat ( 32 ) , 'hex' ) )
219+ }
220+ t . fail ( 'did not fail on `fromTxData`' )
221+ } catch ( e : any ) {
222+ t . pass ( 'failed ok on decoding in `fromTxData`' )
223+ tx = TransactionFactory . fromTxData ( { type : txType } )
224+ if ( signed ) {
225+ tx = tx . sign ( Buffer . from ( '42' . repeat ( 32 ) , 'hex' ) )
226+ }
227+ }
228+ const rawValues = tx ! . raw ( )
229+
230+ if ( txType === 1 && rawValues [ 7 ] . length === 0 ) {
231+ rawValues [ 7 ] = invalidAccessListItem
232+ } else if ( txType === 2 && rawValues [ 8 ] . length === 0 ) {
233+ rawValues [ 8 ] = invalidAccessListItem
234+ }
235+
236+ switch ( txType ) {
237+ case 1 :
238+ t . throws ( ( ) =>
239+ AccessListEIP2930Transaction . fromValuesArray (
240+ rawValues as AccessListEIP2930ValuesArray
241+ )
242+ )
243+ break
244+ case 2 :
245+ t . throws ( ( ) =>
246+ FeeMarketEIP1559Transaction . fromValuesArray ( rawValues as FeeMarketEIP1559ValuesArray )
247+ )
248+ break
249+ }
250+ }
251+ }
252+ }
253+ t . end ( )
254+ } )
0 commit comments