@@ -13,11 +13,18 @@ const EIP2930Common = new Common({
13
13
hardfork : 'berlin' ,
14
14
} )
15
15
16
+ const pKey = Buffer . from ( '4646464646464646464646464646464646464646464646464646464646464646' , 'hex' )
17
+
16
18
const simpleUnsignedEIP2930Transaction = EIP2930Transaction . fromTxData (
17
19
{ chainId : new BN ( 1 ) } ,
18
20
{ common : EIP2930Common }
19
21
)
20
22
23
+ const simpleUnsignedLegacyTransaction = LegacyTransaction . fromTxData ( { } )
24
+
25
+ const simpleSignedEIP2930Transaction = simpleUnsignedEIP2930Transaction . sign ( pKey )
26
+ const simpleSignedLegacyTransaction = simpleUnsignedLegacyTransaction . sign ( pKey )
27
+
21
28
tape ( '[TransactionFactory]: Basic functions' , function ( t ) {
22
29
t . test ( 'should return the right type' , function ( st ) {
23
30
const serialized = simpleUnsignedEIP2930Transaction . serialize ( )
@@ -78,4 +85,38 @@ tape('[TransactionFactory]: Basic functions', function (t) {
78
85
} )
79
86
st . end ( )
80
87
} )
88
+
89
+ t . test ( 'should decode raw block body data' , function ( st ) {
90
+ const rawLegacy = simpleSignedLegacyTransaction . raw ( )
91
+ const rawEIP2930 = simpleSignedEIP2930Transaction . raw ( )
92
+
93
+ const legacyTx = TransactionFactory . fromBlockBodyData ( rawLegacy )
94
+ const eip2930Tx = TransactionFactory . fromBlockBodyData ( rawEIP2930 , { common : EIP2930Common } )
95
+
96
+ st . equals ( legacyTx . constructor . name , LegacyTransaction . name )
97
+ st . equals ( eip2930Tx . constructor . name , EIP2930Transaction . name )
98
+ st . end ( )
99
+ } )
100
+
101
+ t . test ( 'should create the right transaction types from tx data' , function ( st ) {
102
+ const legacyTx = TransactionFactory . fromTxData ( { type : 0 } )
103
+ const legacyTx2 = TransactionFactory . fromTxData ( { } )
104
+ const eip2930Tx = TransactionFactory . fromTxData ( { type : 1 } , { common : EIP2930Common } )
105
+ st . throws ( ( ) => {
106
+ TransactionFactory . fromTxData ( { type : 1 } )
107
+ } )
108
+
109
+ st . equals ( legacyTx . constructor . name , LegacyTransaction . name )
110
+ st . equals ( legacyTx2 . constructor . name , LegacyTransaction . name )
111
+ st . equals ( eip2930Tx . constructor . name , EIP2930Transaction . name )
112
+ st . end ( )
113
+ } )
114
+
115
+ t . test ( 'if eip2718 is not activated, always return that the eip is not activated' , function ( st ) {
116
+ const newCommon = new Common ( { chain : 'mainnet' , hardfork : 'istanbul' } )
117
+
118
+ const eip2930Active = TransactionFactory . eipSupport ( newCommon , 2930 )
119
+ st . ok ( ! eip2930Active )
120
+ st . end ( )
121
+ } )
81
122
} )
0 commit comments