Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/datastore/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
20 changes: 19 additions & 1 deletion tests/2.5/pox-4-delegate-revoked-stacking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
fetchGet,
readOnlyFnCall,
standByForPoxCycle,
standByForPoxCycleEnd,
standByForTx,
standByForTxSuccess,
testEnv,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down