@@ -71,6 +71,17 @@ const newFakeTx = TransactionFactory.fromTxData(
7171 { common, freeze : false } ,
7272) ;
7373
74+ const contractDeploymentFakeTx = TransactionFactory . fromTxData (
75+ {
76+ nonce : '0x00' ,
77+ gasPrice : '0x09184e72a000' ,
78+ gasLimit : '0x2710' ,
79+ value : '0x00' ,
80+ data : '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' ,
81+ } ,
82+ { common, freeze : false } ,
83+ ) ;
84+
7485const fakeTypeTwoTx = FeeMarketEIP1559Transaction . fromTxData (
7586 {
7687 nonce : '0x00' ,
@@ -416,6 +427,50 @@ describe('TrezorKeyring', function () {
416427 assert ( TrezorConnect . ethereumSignTransaction . calledOnce ) ;
417428 } ) ;
418429
430+ it ( 'should pass serialized contract deployment transaction to trezor and return signed tx' , async function ( ) {
431+ sinon . stub ( TransactionFactory , 'fromTxData' ) . callsFake ( ( ) => {
432+ // without having a private key/public key pair in this test, we have
433+ // mock out this method and return the original tx because we can't
434+ // replicate r and s values without the private key.
435+ return contractDeploymentFakeTx ;
436+ } ) ;
437+
438+ sinon . stub ( TrezorConnect , 'ethereumSignTransaction' ) . callsFake ( ( ) => {
439+ return Promise . resolve ( {
440+ success : true ,
441+ payload : { v : '0x25' , r : '0x0' , s : '0x0' } ,
442+ } ) ;
443+ } ) ;
444+
445+ sinon
446+ . stub ( contractDeploymentFakeTx , 'getSenderAddress' )
447+ . callsFake ( ( ) => fakeAccounts [ 0 ] ) ;
448+
449+ sinon
450+ . stub ( contractDeploymentFakeTx , 'verifySignature' )
451+ . callsFake ( ( ) => true ) ;
452+
453+ const returnedTx = await keyring . signTransaction (
454+ fakeAccounts [ 0 ] ,
455+ contractDeploymentFakeTx ,
456+ ) ;
457+ // ensure we get a new version transaction back
458+ assert . equal ( returnedTx . getChainId , undefined ) ;
459+ assert . equal ( returnedTx . common . chainIdBN ( ) . toString ( 'hex' ) , '1' ) ;
460+ assert ( TrezorConnect . ethereumSignTransaction . calledOnce ) ;
461+ assert . deepEqual (
462+ TrezorConnect . ethereumSignTransaction . getCall ( 0 ) . args [ 0 ] ,
463+ {
464+ path : `m/44'/60'/0'/0/0` ,
465+ transaction : {
466+ ...contractDeploymentFakeTx . toJSON ( ) ,
467+ to : '0x' ,
468+ chainId : 1 ,
469+ } ,
470+ } ,
471+ ) ;
472+ } ) ;
473+
419474 it ( 'should pass correctly encoded EIP1559 transaction to trezor and return signed tx' , async function ( ) {
420475 // Copied from @MetaMask /eth-ledger-bridge-keyring
421476 // Generated by signing fakeTypeTwoTx with an unknown private key
0 commit comments