@@ -2,7 +2,15 @@ import * as assert from 'assert';
22
33import { networks } from '../../../src' ;
44import * as utxolib from '../../../src' ;
5- import { addWalletOutputToPsbt , getInternalChainCode , WalletUnspent , ZcashPsbt } from '../../../src/bitgo' ;
5+ import {
6+ addWalletOutputToPsbt ,
7+ getInternalChainCode ,
8+ ProprietaryKeySubtype ,
9+ PSBT_PROPRIETARY_IDENTIFIER ,
10+ WalletUnspent ,
11+ ZcashPsbt ,
12+ ZcashTransaction ,
13+ } from '../../../src/bitgo' ;
614import { getDefaultWalletKeys } from '../../../src/testutil' ;
715
816import { mockUnspents } from '../../../src/testutil/mock' ;
@@ -57,4 +65,26 @@ describe('Zcash PSBT', function () {
5765 psbt . extractTransaction ( true ) ;
5866 } ) ;
5967 } ) ;
68+
69+ it ( 'if the consensus branch id is already in the global map, it should not be added again' , function ( ) {
70+ psbt . setDefaultsForVersion ( network , 456 ) ;
71+ const psbtClone = ZcashPsbt . fromHex ( psbt . toHex ( ) , { network } ) ;
72+ const value = Buffer . alloc ( 4 ) ;
73+ value . writeUint32LE ( ZcashTransaction . VERSION4_BRANCH_NU6_1 ) ;
74+ psbtClone . addUnknownKeyValToGlobal ( {
75+ key : Buffer . concat ( [
76+ Buffer . of ( 0xfc ) ,
77+ Buffer . of ( 0x05 ) ,
78+ Buffer . from ( PSBT_PROPRIETARY_IDENTIFIER ) ,
79+ Buffer . of ( ProprietaryKeySubtype . ZEC_CONSENSUS_BRANCH_ID ) ,
80+ ] ) ,
81+ value,
82+ } ) ;
83+
84+ ( psbtClone as ZcashPsbt ) . setDefaultsForVersion ( network , ZcashTransaction . VERSION4_BRANCH_NU6_1 ) ;
85+
86+ const psbtBuffer = psbtClone . toBuffer ( ) ;
87+ const psbt2 = utxolib . bitgo . createPsbtFromBuffer ( psbtBuffer , network ) ;
88+ assert . deepStrictEqual ( psbt2 . toBuffer ( ) , psbtBuffer ) ;
89+ } ) ;
6090} ) ;
0 commit comments