Skip to content

Commit

Permalink
chore!: optimize getTransactions query (#3336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Nov 12, 2024
1 parent 1ea2e27 commit 8c77765
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-impalas-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": minor
---

chore!: optimize `getTransactions` query
14 changes: 7 additions & 7 deletions packages/account/src/providers/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ fragment transactionFragment on Transaction {
}
}

fragment transactionRawPayloadFragment on Transaction {
id
rawPayload
}

fragment inputEstimatePredicatesFragment on Input {
... on InputCoin {
predicateGasUsed
Expand Down Expand Up @@ -487,7 +492,7 @@ query getTransactions(
transactions(after: $after, before: $before, first: $first, last: $last) {
edges {
node {
...transactionFragment
rawPayload
}
}
pageInfo {
Expand Down Expand Up @@ -553,7 +558,7 @@ query getBlockWithTransactions($blockId: BlockId, $blockHeight: U32) {
block(id: $blockId, height: $blockHeight) {
...blockFragment
transactions {
...transactionRawPayload
...transactionRawPayloadFragment
}
}
}
Expand All @@ -571,11 +576,6 @@ query getBlocks($after: String, $before: String, $first: Int, $last: Int) {
}
}

fragment transactionRawPayload on Transaction {
id
rawPayload
}

query getCoin($coinId: UtxoId!) {
coin(utxoId: $coinId) {
...coinFragment
Expand Down
42 changes: 42 additions & 0 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,48 @@ Supported fuel-core version: ${mock.supportedVersion}.`
});
});

it('ensures getTransactions does not fetch unused data', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;

await provider.produceBlocks(1);

const { transactions } = await provider.operations.getTransactions({
first: 1,
});

expect(transactions.edges.length).toBe(1);

const expectedData = {
rawPayload: expect.any(String),
};

expect(transactions.edges[0].node).toStrictEqual(expectedData);
});

it('ensures getBlockWithTransactions does not fetch unused transaction data', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;

await provider.produceBlocks(1);

const blockNumber = await provider.getBlockNumber();

const { block } = await provider.operations.getBlockWithTransactions({
blockHeight: blockNumber.toString(),
});

expect(block).toBeDefined();
expect(block?.transactions.length).toBe(1);

const expectedData = {
id: expect.any(String),
rawPayload: expect.any(String),
};

expect(block?.transactions?.[0]).toStrictEqual(expectedData);
});

describe('paginated methods', () => {
test('can properly use getCoins', async () => {
const totalCoins = RESOURCES_PAGE_SIZE_LIMIT + 1;
Expand Down

0 comments on commit 8c77765

Please sign in to comment.