@@ -3177,4 +3177,63 @@ describe('address tests', () => {
3177
3177
expect ( result . type ) . toBe ( 'application/json' ) ;
3178
3178
expect ( JSON . parse ( result . text ) . balance ) . toBe ( v1balance ) ;
3179
3179
} ) ;
3180
+
3181
+ test ( 'balance calculation after miner rewards' , async ( ) => {
3182
+ const addr1 = 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335' ;
3183
+
3184
+ // Send some initial balance for addr1
3185
+ await db . update (
3186
+ new TestBlockBuilder ( {
3187
+ block_height : 1 ,
3188
+ index_block_hash : '0x0001' ,
3189
+ parent_index_block_hash : '' ,
3190
+ } )
3191
+ . addTx ( {
3192
+ tx_id : '0x1101' ,
3193
+ token_transfer_recipient_address : addr1 ,
3194
+ type_id : DbTxTypeId . TokenTransfer ,
3195
+ token_transfer_amount : 20_000n ,
3196
+ fee_rate : 50n ,
3197
+ } )
3198
+ . addTxStxEvent ( {
3199
+ amount : 20_000n ,
3200
+ block_height : 1 ,
3201
+ recipient : addr1 ,
3202
+ tx_id : '0x1101' ,
3203
+ } )
3204
+ . build ( )
3205
+ ) ;
3206
+ // Add some miner rewards
3207
+ await db . update (
3208
+ new TestBlockBuilder ( {
3209
+ block_height : 2 ,
3210
+ index_block_hash : '0x0002' ,
3211
+ parent_index_block_hash : '0x0001' ,
3212
+ } )
3213
+ . addMinerReward ( {
3214
+ index_block_hash : '0x0002' ,
3215
+ recipient : addr1 ,
3216
+ coinbase_amount : 2000n ,
3217
+ tx_fees_anchored : 0n ,
3218
+ tx_fees_streamed_confirmed : 0n ,
3219
+ tx_fees_streamed_produced : 0n ,
3220
+ } )
3221
+ . build ( )
3222
+ ) ;
3223
+
3224
+ // Check that v1 balance matches v2 balance.
3225
+ let result = await supertest ( api . server ) . get ( `/extended/v1/address/${ addr1 } /stx` ) ;
3226
+ expect ( result . status ) . toBe ( 200 ) ;
3227
+ expect ( result . type ) . toBe ( 'application/json' ) ;
3228
+ let json = JSON . parse ( result . text ) ;
3229
+ const v1balance = json . balance ;
3230
+ const v1Rewards = json . total_miner_rewards_received ;
3231
+ expect ( v1balance ) . toBe ( '22000' ) ;
3232
+ result = await supertest ( api . server ) . get ( `/extended/v2/addresses/${ addr1 } /balances/stx` ) ;
3233
+ expect ( result . status ) . toBe ( 200 ) ;
3234
+ expect ( result . type ) . toBe ( 'application/json' ) ;
3235
+ json = JSON . parse ( result . text ) ;
3236
+ expect ( json . balance ) . toBe ( v1balance ) ;
3237
+ expect ( json . total_miner_rewards_received ) . toBe ( v1Rewards ) ;
3238
+ } ) ;
3180
3239
} ) ;
0 commit comments