@@ -31,6 +31,7 @@ import { RPCClient } from 'rpc-bitcoin';
3131import * as supertest from 'supertest' ;
3232import { Pox2ContractIdentifer } from '../pox-helpers' ;
3333import { ClarityValueUInt , decodeClarityValue } from 'stacks-encoding-native-js' ;
34+ import { decodeBtcAddress } from '@stacks/stacking' ;
3435
3536// Perform Stack-STX operation on Bitcoin.
3637// See https://github.com/stacksgov/sips/blob/0da29c6911c49c45e4125dbeaed58069854591eb/sips/sip-007/sip-007-stacking-consensus.md#stx-operations-on-bitcoin
@@ -39,6 +40,7 @@ async function createPox2StackStx(args: {
3940 cycleCount : number ;
4041 stackerAddress : string ;
4142 bitcoinWif : string ;
43+ poxAddrPayout : string ;
4244} ) {
4345 const btcAccount = ECPair . fromWIF ( args . bitcoinWif , btc . networks . regtest ) ;
4446 const feeAmount = 0.0001 ;
@@ -116,7 +118,7 @@ async function createPox2StackStx(args: {
116118 } )
117119 // The second Bitcoin output will be used as the reward address for any stacking rewards.
118120 . addOutput ( {
119- address : c32ToB58 ( args . stackerAddress ) ,
121+ address : args . poxAddrPayout ,
120122 value : Math . round ( outAmount1 - feeAmount * sats ) ,
121123 } )
122124 . signInput ( 0 , btcAccount )
@@ -145,6 +147,11 @@ describe('PoX-2 - Stack using Bitcoin-chain ops', () => {
145147 const accountKey = '72e8e3725324514c38c2931ed337ab9ab8d8abaae83ed2275456790194b1fd3101' ;
146148 let account : Account ;
147149
150+ // testnet btc addr: tb1pf4x64urhdsdmadxxhv2wwjv6e3evy59auu2xaauu3vz3adxtskfschm453
151+ // regtest btc addr: bcrt1pf4x64urhdsdmadxxhv2wwjv6e3evy59auu2xaauu3vz3adxtskfs4w3npt
152+ const poxAddrPayoutKey = 'c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01' ;
153+ let poxAddrPayoutAccount : Account ;
154+
148155 let testAccountBalance : bigint ;
149156 const testAccountBtcBalance = 5 ;
150157 let testStackAmount : bigint ;
@@ -159,6 +166,7 @@ describe('PoX-2 - Stack using Bitcoin-chain ops', () => {
159166 ( { db, api, client, stacksNetwork, bitcoinRpcClient } = testEnv ) ;
160167
161168 account = accountFromKey ( accountKey ) ;
169+ poxAddrPayoutAccount = accountFromKey ( poxAddrPayoutKey , 'p2tr' ) ;
162170
163171 const poxInfo = await client . getPox ( ) ;
164172 const [ contractAddress , contractName ] = poxInfo . contract_id . split ( '.' ) ;
@@ -246,6 +254,7 @@ describe('PoX-2 - Stack using Bitcoin-chain ops', () => {
246254 stxOpBtcTxs = await createPox2StackStx ( {
247255 bitcoinWif : account . wif ,
248256 stackerAddress : account . stxAddr ,
257+ poxAddrPayout : poxAddrPayoutAccount . btcAddr ,
249258 stxAmount : testStackAmount ,
250259 cycleCount : 6 ,
251260 } ) ;
@@ -298,11 +307,16 @@ describe('PoX-2 - Stack using Bitcoin-chain ops', () => {
298307 expect ( callArg1 . name ) . toBe ( 'amount-ustx' ) ;
299308 expect ( BigInt ( decodeClarityValue < ClarityValueUInt > ( callArg1 . hex ) . value ) ) . toBe ( testStackAmount ) ;
300309
310+ const expectedPoxPayoutAddr = decodeBtcAddress ( poxAddrPayoutAccount . btcTestnetAddr ) ;
311+ const expectedPoxPayoutAddrRepr = `(tuple (hashbytes 0x${ Buffer . from (
312+ expectedPoxPayoutAddr . data
313+ ) . toString ( 'hex' ) } ) (version 0x${ Buffer . from ( [ expectedPoxPayoutAddr . version ] ) . toString (
314+ 'hex'
315+ ) } ))`;
301316 const callArg2 = txObj . contract_call . function_args ! [ 1 ] ;
302317 expect ( callArg2 . name ) . toBe ( 'pox-addr' ) ;
303- const callArg2Addr = decodePoxAddrArg ( callArg2 . hex ) ;
304- expect ( callArg2Addr . stxAddr ) . toBe ( account . stxAddr ) ;
305- expect ( callArg2Addr . btcAddr ) . toBe ( account . btcAddr ) ;
318+ expect ( callArg2 . type ) . toBe ( '(tuple (hashbytes (buff 32)) (version (buff 1)))' ) ;
319+ expect ( callArg2 . repr ) . toBe ( expectedPoxPayoutAddrRepr ) ;
306320 } ) ;
307321
308322 // TODO: this is very flaky
0 commit comments