diff --git a/src/datastore/pg-store.ts b/src/datastore/pg-store.ts index 26a29c04a1..c192378686 100644 --- a/src/datastore/pg-store.ts +++ b/src/datastore/pg-store.ts @@ -2051,19 +2051,25 @@ export class PgStore extends BasePgStore { >` WITH ordered_pox_events AS ( SELECT - stacker, pox_addr, amount_ustx, unlock_burn_height::integer, tx_id, + stacker, pox_addr, amount_ustx, unlock_burn_height::integer, tx_id, name, block_height, microblock_sequence, tx_index, event_index FROM ${sql(args.poxTable)} WHERE - canonical = true AND microblock_canonical = true AND - name = ${SyntheticPoxEventName.DelegateStx} AND delegate_to = ${args.delegator} AND - block_height <= ${args.blockHeight} AND block_height > ${args.afterBlockHeight} AND - (unlock_burn_height > ${args.burnBlockHeight} OR unlock_burn_height IS NULL) + canonical = true + AND microblock_canonical = true + AND delegate_to = ${args.delegator} + AND name IN ( + ${SyntheticPoxEventName.DelegateStx}, + ${SyntheticPoxEventName.RevokeDelegateStx} + ) + AND block_height <= ${args.blockHeight} + AND block_height > ${args.afterBlockHeight} + AND (unlock_burn_height > ${args.burnBlockHeight} OR unlock_burn_height IS NULL) ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC ), distinct_rows AS ( SELECT DISTINCT ON (stacker) - stacker, pox_addr, amount_ustx, unlock_burn_height, tx_id, + stacker, pox_addr, amount_ustx, unlock_burn_height, tx_id, name, block_height, microblock_sequence, tx_index, event_index FROM ordered_pox_events ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC @@ -2072,6 +2078,7 @@ export class PgStore extends BasePgStore { stacker, pox_addr, amount_ustx, unlock_burn_height, block_height::integer, tx_id, COUNT(*) OVER()::integer AS total_rows FROM distinct_rows + WHERE name = ${SyntheticPoxEventName.DelegateStx} ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC LIMIT ${args.limit} OFFSET ${args.offset} diff --git a/tests/2.5/pox-4-delegate-revoked-stacking.test.ts b/tests/2.5/pox-4-delegate-revoked-stacking.test.ts index 0b21119904..d4eeb236da 100644 --- a/tests/2.5/pox-4-delegate-revoked-stacking.test.ts +++ b/tests/2.5/pox-4-delegate-revoked-stacking.test.ts @@ -24,7 +24,6 @@ import { fetchGet, readOnlyFnCall, standByForPoxCycle, - standByForPoxCycleEnd, standByForTx, standByForTxSuccess, testEnv, @@ -207,6 +206,19 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { ); const delegatedAmount = BigInt(getDelegationInfo.data['amount-ustx'].value); expect(delegatedAmount).toBe(DELEGATE_HALF_AMOUNT); + + // validate pool delegations + const stackersRes: any = await fetchGet(`/extended/v1/pox4/${POOL.stxAddr}/delegations`); + expect(stackersRes).toBeDefined(); + expect(stackersRes.total).toBe(1); + expect(stackersRes.results).toHaveLength(1); + expect(stackersRes.results[0]).toEqual({ + amount_ustx: DELEGATE_HALF_AMOUNT.toString(), + pox_addr: STACKER.btcTestnetAddr, + stacker: STACKER.stxAddr, + tx_id: delegateStxDbTx.tx_id, + block_height: delegateStxDbTx.block_height, + }); }); test('Perform delegate-stack-stx', async () => { @@ -311,6 +323,12 @@ describe('PoX-4 - Delegate Revoked Stacking', () => { const coreBalanceInfo = await testEnv.client.getAccount(STACKER.stxAddr); expect(BigInt(coreBalanceInfo.locked)).toBe(DELEGATE_HALF_AMOUNT); expect(coreBalanceInfo.unlock_height).toBeGreaterThan(0); + + // validate pool delegation no longer exists + const stackersRes: any = await fetchGet(`/extended/v1/pox4/${POOL.stxAddr}/delegations`); + expect(stackersRes).toBeDefined(); + expect(stackersRes.total).toBe(0); + expect(stackersRes.results).toHaveLength(0); }); test('Try to perform delegate-stack-stx - while revoked', async () => {