@@ -3,6 +3,7 @@ import Common from '@ethereumjs/common'
3
3
import { LegacyTransaction , EIP2930Transaction } from '../src'
4
4
import { TxsJsonEntry } from './types'
5
5
import { BaseTransaction } from '../src/baseTransaction'
6
+ import { privateToPublic } from 'ethereumjs-util'
6
7
7
8
tape ( '[BaseTransaction]' , function ( t ) {
8
9
const legacyFixtures : TxsJsonEntry [ ] = require ( './json/txs.json' )
@@ -144,7 +145,66 @@ tape('[BaseTransaction]', function (t) {
144
145
st . notOk ( tx . validate ( ) , `${ txType . name } : should not validate correctly` )
145
146
} )
146
147
}
148
+ st . end ( )
149
+ } )
150
+
151
+ t . test ( 'sign()' , function ( st ) {
152
+ for ( const txType of txTypes ) {
153
+ txType . txs . forEach ( function ( tx : any , i : number ) {
154
+ const { privateKey } = txType . fixtures [ i ]
155
+ if ( privateKey ) {
156
+ st . ok ( tx . sign ( Buffer . from ( privateKey , 'hex' ) ) , `${ txType . name } : should sign tx` )
157
+ }
158
+ } )
159
+ }
160
+ st . end ( )
161
+ } )
162
+
163
+ t . test ( 'getSenderAddress()' , function ( st ) {
164
+ for ( const txType of txTypes ) {
165
+ txType . txs . forEach ( function ( tx : any , i : number ) {
166
+ const { privateKey, sendersAddress } = txType . fixtures [ i ]
167
+ if ( privateKey ) {
168
+ const signedTx = tx . sign ( Buffer . from ( privateKey , 'hex' ) )
169
+ st . equals (
170
+ signedTx . getSenderAddress ( ) . toString ( ) ,
171
+ `0x${ sendersAddress } ` ,
172
+ `${ txType . name } : should get sender's address after signing it`
173
+ )
174
+ }
175
+ } )
176
+ }
177
+ st . end ( )
178
+ } )
179
+
180
+ t . test ( 'getSenderPublicKey()' , function ( st ) {
181
+ for ( const txType of txTypes ) {
182
+ txType . txs . forEach ( function ( tx : any , i : number ) {
183
+ const { privateKey } = txType . fixtures [ i ]
184
+ if ( privateKey ) {
185
+ const signedTx = tx . sign ( Buffer . from ( privateKey , 'hex' ) )
186
+ const txPubKey = signedTx . getSenderPublicKey ( )
187
+ const pubKeyFromPriv = privateToPublic ( Buffer . from ( privateKey , 'hex' ) )
188
+ st . ok (
189
+ txPubKey . equals ( pubKeyFromPriv ) ,
190
+ `${ txType . name } : should get sender's public key after signing it`
191
+ )
192
+ }
193
+ } )
194
+ }
195
+ st . end ( )
196
+ } )
147
197
198
+ t . test ( 'verifySignature()' , function ( st ) {
199
+ for ( const txType of txTypes ) {
200
+ txType . txs . forEach ( function ( tx : any , i : number ) {
201
+ const { privateKey } = txType . fixtures [ i ]
202
+ if ( privateKey ) {
203
+ const signedTx = tx . sign ( Buffer . from ( privateKey , 'hex' ) )
204
+ st . ok ( signedTx . verifySignature ( ) , `${ txType . name } : should verify signing it` )
205
+ }
206
+ } )
207
+ }
148
208
st . end ( )
149
209
} )
150
210
} )
0 commit comments