@@ -8,7 +8,7 @@ import { AnchorMode, bufferCV, makeContractCall, tupleCV, uintCV } from '@stacks
88import { CoreRpcPoxInfo , StacksCoreRpcClient } from '../core-rpc/client' ;
99import { testnetKeys } from '../api/routes/debug' ;
1010import * as poxHelpers from '../pox-helpers' ;
11- import { parsePort } from '../helpers' ;
11+ import { hexToBuffer , parsePort } from '../helpers' ;
1212import { PgWriteStore } from '../datastore/pg-write-store' ;
1313import { StacksNetwork } from '@stacks/network' ;
1414import * as btcLib from 'bitcoinjs-lib' ;
@@ -20,6 +20,7 @@ import {
2020 BurnchainRewardsTotal ,
2121} from '@stacks/stacks-blockchain-api-types' ;
2222import { RPCClient } from 'rpc-bitcoin' ;
23+ import bignumber from 'bignumber.js' ;
2324
2425describe ( 'PoX-2 tests' , ( ) => {
2526 let db : PgWriteStore ;
@@ -406,6 +407,31 @@ describe('PoX-2 tests', () => {
406407 expect ( Number ( rewardsTotal . reward_amount ) ) . toBeGreaterThan ( 0 ) ;
407408 } ) ;
408409
410+ test ( 'stacking rewards - BTC JSON-RPC' , async ( ) => {
411+ const rewards = await fetchGet < BurnchainRewardListResponse > (
412+ `/extended/v1/burnchain/rewards/${ btcAddr } `
413+ ) ;
414+ const firstReward = rewards . results . sort (
415+ ( a , b ) => a . burn_block_height - b . burn_block_height
416+ ) [ 0 ] ;
417+ const blockResult : {
418+ tx : { vout ?: { scriptPubKey : { addresses ?: string [ ] } ; value ?: number } [ ] } [ ] ;
419+ } = await rpcClient . getblock ( {
420+ blockhash : hexToBuffer ( firstReward . burn_block_hash ) . toString ( 'hex' ) ,
421+ verbosity : 2 ,
422+ } ) ;
423+ const vout = blockResult . tx
424+ . flatMap ( t => t . vout )
425+ . find ( t => t ?. scriptPubKey . addresses ?. includes ( btcRegtestAddr ) && t . value ) ;
426+ if ( ! vout || ! vout . value ) {
427+ throw new Error (
428+ `Could not find bitcoin vout for ${ btcRegtestAddr } in block ${ firstReward . burn_block_hash } `
429+ ) ;
430+ }
431+ const sats = new bignumber ( vout . value ) . shiftedBy ( 8 ) . toString ( ) ;
432+ expect ( sats ) . toBe ( firstReward . reward_amount ) ;
433+ } ) ;
434+
409435 test ( 'stx unlocked - RPC balance endpoint' , async ( ) => {
410436 // Wait until account has unlocked (finished Stacking cycles)
411437 const rpcAccountInfo1 = await client . getAccount ( account . stacksAddress ) ;
0 commit comments