Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/controllers/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,16 @@ export const transfersByResourceBetweenDomainsSchema = {
}

export const transfersByDomainSchema = {
summary: "Get all transfers with a specific domain as source or destination",
summary:
"Get all transfers with a specific domain as source or destination. Possible to get transfers by domain only as source and only as destination.",
querystring: {
type: "object",
properties: {
...paginationSchema,
domain: {
type: "string",
default: "source",
default: undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might break something on explorer-ui if it assumed source right now.
@tcar121293 Do you know how this is used right now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wainola can you validate this also

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means it can be undefined, doesn't it? if so, yes, it would break explorer as is a property we are using to render info

nullable: true,
enum: ["source", "destination"],
},
},
Expand Down
34 changes: 22 additions & 12 deletions src/services/transfers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The Licensed Work is (c) 2023 Sygma
SPDX-License-Identifier: LGPL-3.0-only
*/
import { PrismaClient, Transfer, TransferStatus } from "@prisma/client"
import { Prisma, PrismaClient, Transfer, TransferStatus } from "@prisma/client"
import { NotFound, getTransferQueryParams } from "../utils/helpers"

export type Pagination = {
Expand Down Expand Up @@ -34,7 +34,7 @@ class TransfersService {
}
}

public async findTransfers(where: Partial<Transfer>, paginationParams: Pagination): Promise<Transfer[]> {
public async findTransfers(where: Prisma.TransferWhereInput, paginationParams: Pagination): Promise<Transfer[]> {
const { skip, take } = this.calculatePaginationParams(paginationParams)
const transfers = await this.transfers.findMany({
where,
Expand All @@ -54,7 +54,7 @@ class TransfersService {
}

public async findAllTransfers(status: TransferStatus | undefined, paginationParams: Pagination): Promise<Transfer[]> {
const where: Partial<Transfer> = {
const where: Prisma.TransferWhereInput = {
status: status,
}

Expand All @@ -76,7 +76,7 @@ class TransfersService {
}

public async findTransfersByTxHash(txHash: string, domainID: number): Promise<Transfer[]> {
let where: Partial<any>
let where: Prisma.DepositWhereInput
domainID == undefined
? (where = { txHash: txHash })
: (where = {
Expand All @@ -97,7 +97,7 @@ class TransfersService {
}

public async findTransfersByAccountAddress(sender: string, status: TransferStatus | undefined, paginationParams: Pagination): Promise<Transfer[]> {
const where: Partial<Transfer> = {
const where: Prisma.TransferWhereInput = {
accountId: sender,
status: status,
}
Expand All @@ -108,7 +108,7 @@ class TransfersService {
}

public async findTransfersByResourceID(resourceID: string, status: TransferStatus | undefined, paginationParams: Pagination): Promise<Transfer[]> {
const where: Partial<Transfer> = {
const where: Prisma.TransferWhereInput = {
resourceID: resourceID,
status: status,
}
Expand All @@ -123,7 +123,7 @@ class TransfersService {
destinationDomainID: number,
paginationParams: Pagination,
): Promise<Transfer[]> {
const where: Partial<Transfer> = {
const where: Prisma.TransferWhereInput = {
fromDomainId: sourceDomainID,
toDomainId: destinationDomainID,
}
Expand All @@ -139,7 +139,7 @@ class TransfersService {
destinationDomainID: number,
paginationParams: Pagination,
): Promise<Transfer[]> {
const where: Partial<Transfer> = {
const where: Prisma.TransferWhereInput = {
resourceID: resourceID,
fromDomainId: sourceDomainID,
toDomainId: destinationDomainID,
Expand All @@ -156,10 +156,20 @@ class TransfersService {
status: TransferStatus | undefined,
paginationParams: Pagination,
): Promise<Transfer[]> {
let where: Partial<Transfer>

domain == DomainType.Source ? (where = { fromDomainId: domainID, status: status }) : (where = { toDomainId: domainID, status: status })

let where: Prisma.TransferWhereInput

if (domain == DomainType.Source) {
where = { fromDomainId: domainID, status: status }
} else if (domain == DomainType.Destination) {
where = { toDomainId: domainID, status: status }
} else {
where = {
OR: [
{ fromDomainId: domainID, status: status },
{ toDomainId: domainID, status: status },
],
}
}
const transfers = this.findTransfers(where, paginationParams)

return transfers
Expand Down
52 changes: 44 additions & 8 deletions tests/e2e/domainRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ describe("Get all transfers with a specific domain as source or destination", fu
}
})

it("Should successfully fetch all transfers from domain 1", async () => {
it("Should successfully fetch all domain 1 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(32)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
}
expect(transfers.length).to.be.deep.equal(35)
})

it("Should successfully fetch all transfers from domain 1 with specified source", async () => {
it("Should successfully fetch all transfers from domain 1", async () => {
Comment thread
mj52951 marked this conversation as resolved.
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>

Expand Down Expand Up @@ -83,6 +79,26 @@ describe("Get all transfers with a specific domain as source or destination", fu
}
})

it("Should successfully fetch all domain 2 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(30)
})

it("Should successfully fetch all transfers from domain 2", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(0)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_2))
}
})

it("Should successfully fetch all transfers to domain 2", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100&domain=destination`)
const transfers = res.data as Array<TransferResponse>
Expand All @@ -95,15 +111,35 @@ describe("Get all transfers with a specific domain as source or destination", fu
}
})

it("Should successfully fetch all transfers from domain 3", async () => {
it("Should successfully fetch all domain 3 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(5)
})

it("Should successfully fetch all transfers from domain 3", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)

for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_3))
}
})

it("Should successfully fetch all transfers to domain 3", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100&domain=destination`)
const transfers = res.data as Array<TransferResponse>

expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(2)

for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_3))
}
})
})