@@ -9,7 +9,14 @@ import { common, Triple } from '@bitgo/sdk-core';
99import { getReplayProtectionPubkeys , ErrorDeprecatedTxFormat } from '../../src' ;
1010import type { Unspent } from '../../src/unspent' ;
1111
12- import { getUtxoWallet , getDefaultWalletKeys , getUtxoCoin , keychainsBase58 , defaultBitGo } from './util' ;
12+ import {
13+ getUtxoWallet ,
14+ getDefaultWalletKeys ,
15+ getNetworkForCoinName ,
16+ getUtxoCoin ,
17+ keychainsBase58 ,
18+ defaultBitGo ,
19+ } from './util' ;
1320
1421describe ( 'signTransaction' , function ( ) {
1522 const bgUrl = common . Environments [ defaultBitGo . getEnv ( ) ] . uri ;
@@ -21,7 +28,7 @@ describe('signTransaction', function () {
2128 const pubs = keychainsBase58 . map ( ( v ) => v . pub ) as Triple < string > ;
2229
2330 function validatePsbt ( txHex : string , targetSigCount : 0 | 1 , targetNonceCount ?: 1 | 2 ) {
24- const psbt = utxolib . bitgo . createPsbtFromHex ( txHex , coin . network ) ;
31+ const psbt = utxolib . bitgo . createPsbtFromHex ( txHex , getNetworkForCoinName ( coin . name ) ) ;
2532 psbt . data . inputs . forEach ( ( input , index ) => {
2633 const parsed = utxolib . bitgo . parsePsbtInput ( input ) ;
2734 if ( parsed . scriptType === 'taprootKeyPathSpend' ) {
@@ -38,7 +45,7 @@ describe('signTransaction', function () {
3845 }
3946
4047 function validateTx ( txHex : string , unspents : Unspent < bigint > [ ] , targetSigCount : 0 | 1 ) {
41- const tx = utxolib . bitgo . createTransactionFromHex ( txHex , coin . network ) ;
48+ const tx = utxolib . bitgo . createTransactionFromHex ( txHex , getNetworkForCoinName ( coin . name ) ) ;
4249 unspents . forEach ( ( u , i ) => {
4350 const sigCount = utxolib . bitgo . getStrictSignatureCount ( tx . ins [ i ] ) ;
4451 const expectedSigCount = utxolib . bitgo . isWalletUnspent ( u ) && ! ! targetSigCount ? 1 : 0 ;
@@ -56,7 +63,7 @@ describe('signTransaction', function () {
5663 const txHex = tx . toHex ( ) ;
5764
5865 function nockSignPsbt ( psbtHex : string ) : nock . Scope {
59- const psbt = utxolib . bitgo . createPsbtFromHex ( psbtHex , coin . network ) ;
66+ const psbt = utxolib . bitgo . createPsbtFromHex ( psbtHex , getNetworkForCoinName ( coin . name ) ) ;
6067 return nock ( bgUrl )
6168 . post ( `/api/v2/${ wallet . coin ( ) } /wallet/${ wallet . id ( ) } /tx/signpsbt` , ( body ) => body . psbt )
6269 . reply ( 200 , { psbt : psbt . setAllInputsMusig2NonceHD ( rootWalletKeys . bitgo ) . toHex ( ) } ) ;
@@ -147,7 +154,7 @@ describe('signTransaction', function () {
147154 . map ( ( scriptType ) => ( { scriptType, value : BigInt ( 1000 ) } ) ) ;
148155 const unspentSum = inputs . reduce ( ( prev : bigint , curr ) => prev + curr . value , BigInt ( 0 ) ) ;
149156 const outputs : testutil . Output [ ] = [ { scriptType : 'p2sh' , value : unspentSum - BigInt ( 1000 ) } ] ;
150- const psbt = testutil . constructPsbt ( inputs , outputs , coin . network , rootWalletKeys , 'unsigned' , {
157+ const psbt = testutil . constructPsbt ( inputs , outputs , getNetworkForCoinName ( coin . name ) , rootWalletKeys , 'unsigned' , {
151158 p2shP2pkKey : replayProtectionKey ,
152159 } ) ;
153160
@@ -163,7 +170,7 @@ describe('signTransaction', function () {
163170 . map ( ( scriptType ) => ( { scriptType, value : BigInt ( 1000 ) } ) ) ;
164171 const unspentSum = inputs . reduce ( ( prev : bigint , cur ) => prev + cur . value , BigInt ( 0 ) ) ;
165172 const outputs : testutil . Output [ ] = [ { scriptType : 'p2sh' , value : unspentSum - BigInt ( 1000 ) } ] ;
166- const psbt = testutil . constructPsbt ( inputs , outputs , coin . network , rootWalletKeys , 'unsigned' , {
173+ const psbt = testutil . constructPsbt ( inputs , outputs , getNetworkForCoinName ( coin . name ) , rootWalletKeys , 'unsigned' , {
167174 p2shP2pkKey : replayProtectionKey ,
168175 } ) ;
169176
@@ -181,8 +188,16 @@ describe('signTransaction', function () {
181188 } ) ) ;
182189 const unspentSum = inputs . reduce ( ( prev : bigint , curr ) => prev + curr . value , BigInt ( 0 ) ) ;
183190 const outputs : testutil . TxnOutput < bigint > [ ] = [ { scriptType : 'p2sh' , value : unspentSum - BigInt ( 1000 ) } ] ;
184- const txBuilder = testutil . constructTxnBuilder ( inputs , outputs , coin . network , rootWalletKeys , 'unsigned' ) ;
185- const unspents = inputs . map ( ( v , i ) => testutil . toTxnUnspent ( v , i , coin . network , rootWalletKeys ) ) ;
191+ const txBuilder = testutil . constructTxnBuilder (
192+ inputs ,
193+ outputs ,
194+ getNetworkForCoinName ( coin . name ) ,
195+ rootWalletKeys ,
196+ 'unsigned'
197+ ) ;
198+ const unspents = inputs . map ( ( v , i ) =>
199+ testutil . toTxnUnspent ( v , i , getNetworkForCoinName ( coin . name ) , rootWalletKeys )
200+ ) ;
186201
187202 // Legacy format transactions are now deprecated and should throw ErrorDeprecatedTxFormat
188203 await assert . rejects ( async ( ) => {
@@ -194,7 +209,7 @@ describe('signTransaction', function () {
194209 const inputs : testutil . Input [ ] = [ { scriptType : 'taprootKeyPathSpend' , value : BigInt ( 1000 ) } ] ;
195210 const unspentSum = inputs . reduce ( ( prev : bigint , curr ) => prev + curr . value , BigInt ( 0 ) ) ;
196211 const outputs : testutil . Output [ ] = [ { scriptType : 'p2sh' , value : unspentSum - BigInt ( 1000 ) } ] ;
197- const psbt = testutil . constructPsbt ( inputs , outputs , coin . network , rootWalletKeys , 'unsigned' ) ;
212+ const psbt = testutil . constructPsbt ( inputs , outputs , getNetworkForCoinName ( coin . name ) , rootWalletKeys , 'unsigned' ) ;
198213
199214 await assert . rejects (
200215 async ( ) => {
0 commit comments