Skip to content

Commit

Permalink
fix: include address transactions from genesis block (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Mar 15, 2024
1 parent 08cb144 commit cdea9e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/datastore/pg-store-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ export class PgStoreV2 extends BasePgStoreModule {
WHERE principal = ${args.address}
)
UNION
(
SELECT tx_id, index_block_hash, microblock_hash
FROM stx_events
WHERE sender = ${args.address} OR recipient = ${args.address}
)
UNION
(
SELECT tx_id, index_block_hash, microblock_hash
FROM ft_events
Expand Down
50 changes: 34 additions & 16 deletions src/tests/address-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('address tests', () => {
const testAddr2 = 'ST1HB64MAJ1MBV4CQ80GF01DZS4T1DSMX20ADCRA4';
const testContractAddr = 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world';
const testAddr4 = 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C';
const testTxId = '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008';
const testTxId = '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009';

const block: DbBlock = {
block_hash: '0x1234',
Expand Down Expand Up @@ -194,6 +194,7 @@ describe('address tests', () => {
return [tx, stxEvents, ftEvents, nftEvents];
};
const txs = [
createStxTx(testAddr4, testAddr2, 0, true, 1, 0, 0, true),
createStxTx(testAddr4, testAddr2, 0, true, 0, 1, 0, true),
createStxTx(testAddr4, testAddr2, 0, true, 0, 0, 1, true),
createStxTx(testAddr1, testAddr2, 100_000, true, 1, 1, 1),
Expand Down Expand Up @@ -231,11 +232,11 @@ describe('address tests', () => {
const expected1 = {
limit: 3,
offset: 0,
total: 6,
total: 7,
results: [
{
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -257,7 +258,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 8,
tx_index: 9,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
Expand Down Expand Up @@ -322,7 +323,7 @@ describe('address tests', () => {
},
{
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890005',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890006',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -344,7 +345,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 5,
tx_index: 6,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world',
Expand Down Expand Up @@ -383,7 +384,7 @@ describe('address tests', () => {
},
{
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890004',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890005',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -405,7 +406,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 4,
tx_index: 5,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST27W5M8BRKA7C5MZE2R1S1F4XTPHFWFRNHA9M04Y.hello-world',
Expand Down Expand Up @@ -467,7 +468,7 @@ describe('address tests', () => {
expect(v2Fetch1.status).toBe(200);
expect(v2Fetch1.type).toBe('application/json');
const v2Fetch1Json = JSON.parse(v2Fetch1.text);
expect(v2Fetch1Json.total).toBe(6);
expect(v2Fetch1Json.total).toBe(7);
expect(v2Fetch1Json.results[0].tx).toStrictEqual(expected1.results[0].tx);
expect(v2Fetch1Json.results[0].stx_sent).toBe('1339');
expect(v2Fetch1Json.results[0].stx_received).toBe('0');
Expand Down Expand Up @@ -556,6 +557,23 @@ describe('address tests', () => {
mint: 0,
burn: 0,
});
expect(v2Fetch1Json.results[6].stx_sent).toBe('1234');
expect(v2Fetch1Json.results[6].stx_received).toBe('0');
expect(v2Fetch1Json.results[6].events.stx).toStrictEqual({
transfer: 1,
mint: 0,
burn: 0,
});
expect(v2Fetch1Json.results[6].events.ft).toStrictEqual({
transfer: 0,
mint: 0,
burn: 0,
});
expect(v2Fetch1Json.results[6].events.nft).toStrictEqual({
transfer: 0,
mint: 0,
burn: 0,
});

const v2Fetch2 = await supertest(api.server).get(
`/extended/v2/addresses/${testAddr2}/transactions/${v2Fetch1Json.results[0].tx.tx_id}/events?limit=3`
Expand Down Expand Up @@ -659,7 +677,7 @@ describe('address tests', () => {
expect(fetchSingleTxInformation.type).toBe('application/json');
const expectedSingleTxInformation = {
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -681,7 +699,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 8,
tx_index: 9,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
Expand Down Expand Up @@ -727,11 +745,11 @@ describe('address tests', () => {
const expected2 = {
limit: 2,
offset: 0,
total: 4,
total: 5,
results: [
{
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890009',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -753,7 +771,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 8,
tx_index: 9,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
Expand Down Expand Up @@ -818,7 +836,7 @@ describe('address tests', () => {
},
{
tx: {
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890007',
tx_id: '0x03807fdb726b3cb843e0330c564a4974037be8f9ea58ec7f8ebe03c34b890008',
tx_type: 'token_transfer',
nonce: 0,
anchor_mode: 'any',
Expand All @@ -840,7 +858,7 @@ describe('address tests', () => {
parent_block_hash: '0x',
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
tx_index: 7,
tx_index: 8,
tx_result: { hex: '0x0100000000000000000000000000000001', repr: 'u1' },
token_transfer: {
recipient_address: 'ST3DWSXBPYDB484QXFTR81K4AWG4ZB5XZNFF3H70C',
Expand Down

0 comments on commit cdea9e6

Please sign in to comment.