Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
Browse files Browse the repository at this point in the history
…/feat/implement-browser-testing-with-runner-groups
  • Loading branch information
danielbate committed Aug 30, 2023
2 parents 5f0ff54 + 35364da commit 0549bbe
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-spoons-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/providers": minor
---

add static method create to TransactionReponse class
2 changes: 2 additions & 0 deletions .changeset/swift-spiders-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
21 changes: 21 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,24 @@ jobs:
if: env.SHOULD_DEPLOY_DOCS == 'true'
id: deployment
uses: actions/deploy-pages@v1

- name: Checkout API Docs
if: env.SHOULD_DEPLOY_DOCS == 'true'
uses: actions/checkout@v3
with:
ref: docs

- name: Generate and Push API Docs
if: env.SHOULD_DEPLOY_DOCS == 'true'
run: |
git pull origin master --no-edit
pnpm install
pnpm build
rm -f apps/docs/.gitignore
git add apps/docs/src/api/
git add apps/docs/.typedoc/api-links.json
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -m "docs: API docs"
git push
git restore apps/docs/.gitignore
76 changes: 76 additions & 0 deletions packages/fuel-gauge/src/transaction-response.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { generateTestWallet } from '@fuel-ts/wallet/test-utils';
import type { WalletUnlocked } from 'fuels';
import { FUEL_NETWORK_URL, Provider, TransactionResponse, Wallet } from 'fuels';

describe('TransactionSummary', () => {
let provider: Provider;
let adminWallet: WalletUnlocked;

beforeAll(async () => {
provider = new Provider(FUEL_NETWORK_URL);
adminWallet = await generateTestWallet(provider, [[1_000]]);
});

it('should ensure create method waits till a transaction response is given', async () => {
const destination = Wallet.generate();

const { id: transactionId } = await adminWallet.transfer(destination.address, 100);

const response = await TransactionResponse.create(transactionId, provider);

expect(response.gqlTransaction).toBeDefined();
expect(response.gqlTransaction?.status).toBeDefined();
expect(response.gqlTransaction?.id).toBe(transactionId);
});

it('should ensure getTransactionSummary fetchs a transaction and assembles transaction summary', async () => {
const destination = Wallet.generate();

const { id: transactionId } = await adminWallet.transfer(destination.address, 100);

const response = new TransactionResponse(transactionId, provider);

expect(response.gqlTransaction).toBeUndefined();

const transactionSummary = await response.getTransactionSummary();

expect(transactionSummary.id).toBeDefined();
expect(transactionSummary.fee).toBeDefined();
expect(transactionSummary.gasUsed).toBeDefined();
expect(transactionSummary.operations).toBeDefined();
expect(transactionSummary.type).toBeDefined();
expect(transactionSummary.blockId).toBeDefined();
expect(transactionSummary.time).toBeDefined();
expect(transactionSummary.status).toBeDefined();
expect(transactionSummary.receipts).toBeDefined();
expect(transactionSummary.mintedAssets).toBeDefined();
expect(transactionSummary.burnedAssets).toBeDefined();
expect(transactionSummary.isTypeMint).toBeDefined();
expect(transactionSummary.isTypeCreate).toBeDefined();
expect(transactionSummary.isTypeScript).toBeDefined();
expect(transactionSummary.isStatusFailure).toBeDefined();
expect(transactionSummary.isStatusSuccess).toBeDefined();
expect(transactionSummary.isStatusPending).toBeDefined();
expect(transactionSummary.transaction).toBeDefined();

expect(response.gqlTransaction).toBeDefined();
expect(response.gqlTransaction?.status).toBeDefined();
expect(response.gqlTransaction?.id).toBe(transactionId);
});

it('should ensure waitForResult always waits for the transaction to be processed', async () => {
const destination = Wallet.generate();

const { id: transactionId } = await adminWallet.transfer(destination.address, 100);

const response = new TransactionResponse(transactionId, provider);

expect(response.gqlTransaction).toBeUndefined();

await response.waitForResult();

expect(response.gqlTransaction?.status?.type).toBeDefined();
expect(response.gqlTransaction?.status?.type).not.toEqual('SubmittedStatus');
expect(response.gqlTransaction?.id).toBe(transactionId);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ export class TransactionResponse {
this.provider = provider;
}

/**
* Async constructor for `TransactionResponse`. This method can be used to create
* an instance of `TransactionResponse` and wait for the transaction to be fetched
* from the chain, ensuring that the `gqlTransaction` property is set.
*
* @param id - The transaction ID.
* @param provider - The provider.
*/
static async create(id: string, provider: Provider): Promise<TransactionResponse> {
const response = new TransactionResponse(id, provider);
await response.fetch();
return response;
}

/**
* Fetch the transaction with receipts from the provider.
*
Expand Down

0 comments on commit 0549bbe

Please sign in to comment.