Skip to content

Commit cdea9e6

Browse files
authored
fix: include address transactions from genesis block (#1888)
1 parent 08cb144 commit cdea9e6

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

src/datastore/pg-store-v2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ export class PgStoreV2 extends BasePgStoreModule {
319319
WHERE principal = ${args.address}
320320
)
321321
UNION
322+
(
323+
SELECT tx_id, index_block_hash, microblock_hash
324+
FROM stx_events
325+
WHERE sender = ${args.address} OR recipient = ${args.address}
326+
)
327+
UNION
322328
(
323329
SELECT tx_id, index_block_hash, microblock_hash
324330
FROM ft_events

src/tests/address-tests.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('address tests', () => {
6969
const testAddr2 = 'ST1HB64MAJ1MBV4CQ80GF01DZS4T1DSMX20ADCRA4';
7070
const testContractAddr = 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world';
7171
const testAddr4 = 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C';
72-
const testTxId = '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008';
72+
const testTxId = '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009';
7373

7474
const block: DbBlock = {
7575
block_hash: '0x1234',
@@ -194,6 +194,7 @@ describe('address tests', () => {
194194
return [tx, stxEvents, ftEvents, nftEvents];
195195
};
196196
const txs = [
197+
createStxTx(testAddr4, testAddr2, 0, true, 1, 0, 0, true),
197198
createStxTx(testAddr4, testAddr2, 0, true, 0, 1, 0, true),
198199
createStxTx(testAddr4, testAddr2, 0, true, 0, 0, 1, true),
199200
createStxTx(testAddr1, testAddr2, 100_000, true, 1, 1, 1),
@@ -231,11 +232,11 @@ describe('address tests', () => {
231232
const expected1 = {
232233
limit: 3,
233234
offset: 0,
234-
total: 6,
235+
total: 7,
235236
results: [
236237
{
237238
tx: {
238-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
239+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
239240
tx_type: 'token_transfer',
240241
nonce: 0,
241242
anchor_mode: 'any',
@@ -257,7 +258,7 @@ describe('address tests', () => {
257258
parent_block_hash: '0x',
258259
parent_burn_block_time: 1626122935,
259260
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
260-
tx_index: 8,
261+
tx_index: 9,
261262
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
262263
token_transfer: {
263264
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
@@ -322,7 +323,7 @@ describe('address tests', () => {
322323
},
323324
{
324325
tx: {
325-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890005',
326+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890006',
326327
tx_type: 'token_transfer',
327328
nonce: 0,
328329
anchor_mode: 'any',
@@ -344,7 +345,7 @@ describe('address tests', () => {
344345
parent_block_hash: '0x',
345346
parent_burn_block_time: 1626122935,
346347
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
347-
tx_index: 5,
348+
tx_index: 6,
348349
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
349350
token_transfer: {
350351
recipient_address: 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world',
@@ -383,7 +384,7 @@ describe('address tests', () => {
383384
},
384385
{
385386
tx: {
386-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890004',
387+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890005',
387388
tx_type: 'token_transfer',
388389
nonce: 0,
389390
anchor_mode: 'any',
@@ -405,7 +406,7 @@ describe('address tests', () => {
405406
parent_block_hash: '0x',
406407
parent_burn_block_time: 1626122935,
407408
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
408-
tx_index: 4,
409+
tx_index: 5,
409410
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
410411
token_transfer: {
411412
recipient_address: 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world',
@@ -467,7 +468,7 @@ describe('address tests', () => {
467468
expect(v2Fetch1.status).toBe(200);
468469
expect(v2Fetch1.type).toBe('application/json');
469470
const v2Fetch1Json = JSON.parse(v2Fetch1.text);
470-
expect(v2Fetch1Json.total).toBe(6);
471+
expect(v2Fetch1Json.total).toBe(7);
471472
expect(v2Fetch1Json.results[0].tx).toStrictEqual(expected1.results[0].tx);
472473
expect(v2Fetch1Json.results[0].stx_sent).toBe('1339');
473474
expect(v2Fetch1Json.results[0].stx_received).toBe('0');
@@ -556,6 +557,23 @@ describe('address tests', () => {
556557
mint: 0,
557558
burn: 0,
558559
});
560+
expect(v2Fetch1Json.results[6].stx_sent).toBe('1234');
561+
expect(v2Fetch1Json.results[6].stx_received).toBe('0');
562+
expect(v2Fetch1Json.results[6].events.stx).toStrictEqual({
563+
transfer: 1,
564+
mint: 0,
565+
burn: 0,
566+
});
567+
expect(v2Fetch1Json.results[6].events.ft).toStrictEqual({
568+
transfer: 0,
569+
mint: 0,
570+
burn: 0,
571+
});
572+
expect(v2Fetch1Json.results[6].events.nft).toStrictEqual({
573+
transfer: 0,
574+
mint: 0,
575+
burn: 0,
576+
});
559577

560578
const v2Fetch2 = await supertest(api.server).get(
561579
`/extended/v2/addresses/${testAddr2}/transactions/${v2Fetch1Json.results[0].tx.tx_id}/events?limit=3`
@@ -659,7 +677,7 @@ describe('address tests', () => {
659677
expect(fetchSingleTxInformation.type).toBe('application/json');
660678
const expectedSingleTxInformation = {
661679
tx: {
662-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
680+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
663681
tx_type: 'token_transfer',
664682
nonce: 0,
665683
anchor_mode: 'any',
@@ -681,7 +699,7 @@ describe('address tests', () => {
681699
parent_block_hash: '0x',
682700
parent_burn_block_time: 1626122935,
683701
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
684-
tx_index: 8,
702+
tx_index: 9,
685703
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
686704
token_transfer: {
687705
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
@@ -727,11 +745,11 @@ describe('address tests', () => {
727745
const expected2 = {
728746
limit: 2,
729747
offset: 0,
730-
total: 4,
748+
total: 5,
731749
results: [
732750
{
733751
tx: {
734-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
752+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
735753
tx_type: 'token_transfer',
736754
nonce: 0,
737755
anchor_mode: 'any',
@@ -753,7 +771,7 @@ describe('address tests', () => {
753771
parent_block_hash: '0x',
754772
parent_burn_block_time: 1626122935,
755773
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
756-
tx_index: 8,
774+
tx_index: 9,
757775
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
758776
token_transfer: {
759777
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
@@ -818,7 +836,7 @@ describe('address tests', () => {
818836
},
819837
{
820838
tx: {
821-
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890007',
839+
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
822840
tx_type: 'token_transfer',
823841
nonce: 0,
824842
anchor_mode: 'any',
@@ -840,7 +858,7 @@ describe('address tests', () => {
840858
parent_block_hash: '0x',
841859
parent_burn_block_time: 1626122935,
842860
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
843-
tx_index: 7,
861+
tx_index: 8,
844862
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
845863
token_transfer: {
846864
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',

0 commit comments

Comments
 (0)