From 68a5fa016c88578fe0d7914c7f0f86b56af02e5b Mon Sep 17 00:00:00 2001 From: Gabriel Claramunt Date: Mon, 29 Sep 2025 13:14:10 -0300 Subject: [PATCH] filter allow spends by source address only --- prisma/seed.ts | 14 ++++++++++++++ src/handlers/allowSpendsHandler.ts | 14 ++++---------- tests/handlers/actionsHandler.test.ts | 4 ++-- tests/handlers/allowSpendsHandler.test.ts | 16 ++++++++-------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index fc2f12c..4a3b080 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -329,6 +329,20 @@ export const data_dag_allow_spends = [ created_at: new Date("2024-01-03T10:00:00Z"), updated_at: new Date("2024-01-03T10:00:00Z"), }, + { + hash: "allowSpendHash6", + currency_id: "currency-3", + source_addr: data_addresses[0].address, + destination_addr: data_addresses[1].address, + amount: 1500n, + fee: 8n, + last_valid_epoch_progress: 800n, + ordinal: 6n, + snapshot_hash: data_global_snapshots[1].hash, + round_id: "44444444-4444-4444-4444-444444444444", + created_at: new Date("2024-01-04T10:00:00Z"), + updated_at: new Date("2024-01-04T10:00:00Z"), + }, ]; export const data_dag_spend_transactions = [ diff --git a/src/handlers/allowSpendsHandler.ts b/src/handlers/allowSpendsHandler.ts index dafd490..927e3dd 100644 --- a/src/handlers/allowSpendsHandler.ts +++ b/src/handlers/allowSpendsHandler.ts @@ -184,7 +184,7 @@ export const addressAllowSpends = async ( fromCreatedAtOrdinalCursor, { where: { - OR: [{ source_addr: address }, { destination_addr: address }], + source_addr: address, ...ifActiveAllowSpend(event), }, include: dagInclude, @@ -390,10 +390,7 @@ export const addressAllowSpendExpirations = async ( hashCursor, { where: { - OR: [ - { source_addr: address }, - { dag_allow_spend: { destination_addr: address } }, - ], + source_addr: address, }, include: dagInclude, orderBy: [{ created_at: "desc" }, { hash: "asc" }], @@ -487,7 +484,7 @@ export const currencyAddressAllowSpends = async ( { where: { metagraph_id, - OR: [{ source_addr: address }, { destination_addr: address }], + source_addr: address, ...ifActiveMetagraphAllowSpend(event), }, include: metagraphInclude, @@ -650,10 +647,7 @@ export const currencyAddressAllowSpendExpirations = async ( { where: { metagraph_id, - OR: [ - { source_addr: address }, - { metagraph_allow_spend: { destination_addr: address } }, - ], + source_addr: address, }, include: metagraphInclude, orderBy: [{ created_at: "desc" }, { hash: "asc" }], diff --git a/tests/handlers/actionsHandler.test.ts b/tests/handlers/actionsHandler.test.ts index e40e57c..bb34b56 100644 --- a/tests/handlers/actionsHandler.test.ts +++ b/tests/handlers/actionsHandler.test.ts @@ -84,7 +84,7 @@ describe("actionsHandler", () => { expect(result.statusCode).toBe(200); const body = validatePaginatedResponse(result); - expect(body.data.length).toBe(18); + expect(body.data.length).toBe(19); body.data.forEach(validateAction); }); @@ -122,7 +122,7 @@ describe("actionsHandler", () => { expect(result.statusCode).toBe(200); const body = validatePaginatedResponse(result); - expect(body.data.length).toBe(12); + expect(body.data.length).toBe(13); body.data.forEach(validateAction); }); diff --git a/tests/handlers/allowSpendsHandler.test.ts b/tests/handlers/allowSpendsHandler.test.ts index 3a8a196..fbef8d6 100644 --- a/tests/handlers/allowSpendsHandler.test.ts +++ b/tests/handlers/allowSpendsHandler.test.ts @@ -132,7 +132,7 @@ describe("AllowSpends Handler Integration Tests", () => { expect(response.statusCode).toBe(200); const body = validatePaginatedResponse(response); - expect(body.data.length).toBe(2); + expect(body.data.length).toBe(3); body.data.forEach(validateDagAllowSpend); }); }); @@ -199,19 +199,19 @@ describe("AllowSpends Handler Integration Tests", () => { describe("addressAllowSpends", () => { it("should return allow spends for a specific address", async () => { - const address = data_addresses[3].address; + const address = data_addresses[0].address; const event = createAPIGatewayEvent({ address }); const response = await allowSpendsHandler.addressAllowSpends(event); expect(response.statusCode).toBe(200); const body = validatePaginatedResponse(response); - expect(body.data.length).toBe(1); + expect(body.data.length).toBe(3); body.data.forEach(validateDagAllowSpend); }); it("should return active only allow spends for a specific address", async () => { - const address = data_addresses[3].address; + const address = data_addresses[0].address; const event = createAPIGatewayEvent({ address }, { active: "true" }); const response = await allowSpendsHandler.addressAllowSpends(event); @@ -511,7 +511,7 @@ describe("Metagraph AllowSpends Handler Integration Tests", () => { it("should return allow spends for an address", async () => { const event = createAPIGatewayEvent({ metagraph_id: data_metagraphs[0].id, - address: data_addresses[1].address, + address: data_addresses[0].address, }); const response = await allowSpendsHandler.currencyAddressAllowSpends( @@ -525,7 +525,7 @@ describe("Metagraph AllowSpends Handler Integration Tests", () => { const event = createAPIGatewayEvent( { metagraph_id: data_metagraphs[0].id, - address: data_addresses[1].address, + address: data_addresses[0].address, }, { active: "true" } ); @@ -539,7 +539,7 @@ describe("Metagraph AllowSpends Handler Integration Tests", () => { }); it("currencyAddressAllowSpendsPagination", async () => { const metagraph_id = data_metagraphs[0].id; - const address = data_addresses[1].address; + const address = data_addresses[0].address; await validatePaginationNext( "1", { metagraph_id, address }, @@ -552,7 +552,7 @@ describe("Metagraph AllowSpends Handler Integration Tests", () => { it("should return spend transactions for an address", async () => { const event = createAPIGatewayEvent({ metagraph_id: data_dag_spend_transactions[1].currency_id, - address: data_addresses[1].address, + address: data_addresses[0].address, }); const response =