Skip to content

Commit

Permalink
Merge branch 'ps/feat/prevent-illicit-burn' of github.com:FuelLabs/fu…
Browse files Browse the repository at this point in the history
…els-ts into ps/feat/prevent-illicit-burn
  • Loading branch information
petertonysmith94 committed Jan 9, 2025
2 parents b321ec8 + 43cba99 commit 0179db4
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changeset/sweet-geese-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
101 changes: 101 additions & 0 deletions packages/fuel-gauge/src/transaction-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,107 @@ function getSubscriptionStreamFromFetch(streamHolder: { stream: ReadableStream<U
* @group browser
*/
describe('TransactionResponse', () => {
beforeEach(() => {
vi.resetAllMocks();
});

it('builds tx response from active sendAndAwaitStatus subscription', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [adminWallet],
} = launched;

const submitAndAwaitStatusSpy = vi.spyOn(provider.operations, 'submitAndAwaitStatus');
const statusChangeSpy = vi.spyOn(provider.operations, 'statusChange');
const getTransactionWithReceiptsSpy = vi.spyOn(
provider.operations,
'getTransactionWithReceipts'
);

const transferTx = await adminWallet.transfer(
Wallet.generate().address,
100,
await provider.getBaseAssetId()
);
const result = await transferTx.waitForResult();

expect(transferTx.id).toEqual(result.id);
expect(result.receipts.length).toBe(2);

expect(submitAndAwaitStatusSpy).toHaveBeenCalledTimes(1); // sends tx and gets result
expect(statusChangeSpy).toHaveBeenCalledTimes(0); // we already have the status
expect(getTransactionWithReceiptsSpy).toHaveBeenCalledTimes(0); // we already have the raw tx
});

it('builds tx response from transaction ID', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [adminWallet],
} = launched;

const submitAndAwaitStatusSpy = vi.spyOn(provider.operations, 'submitAndAwaitStatus');
const statusChangeSpy = vi.spyOn(provider.operations, 'statusChange');
const getTransactionWithReceiptsSpy = vi.spyOn(
provider.operations,
'getTransactionWithReceipts'
);

const transferTx = await adminWallet.transfer(
Wallet.generate().address,
100,
await provider.getBaseAssetId()
);
const response = new TransactionResponse(transferTx.id, provider, await provider.getChainId());
const result = await response.waitForResult();

expect(transferTx.id).toEqual(result.id);
expect(result.receipts.length).toBe(2);

expect(submitAndAwaitStatusSpy).toHaveBeenCalledTimes(1); // sends tx
expect(statusChangeSpy).toHaveBeenCalledTimes(1); // awaits result (can get receipts)
expect(getTransactionWithReceiptsSpy).toHaveBeenCalledTimes(1); // gets raw transaction and receipts
});

it('builds tx response from transaction request instance', async () => {
using launched = await launchTestNode();

const {
provider,
wallets: [adminWallet],
} = launched;

const submitAndAwaitStatusSpy = vi.spyOn(provider.operations, 'submitAndAwaitStatus');
const statusChangeSpy = vi.spyOn(provider.operations, 'statusChange');
const getTransactionWithReceiptsSpy = vi.spyOn(
provider.operations,
'getTransactionWithReceipts'
);

const transferTxRequest = await adminWallet.createTransfer(
Wallet.generate().address,
100,
await provider.getBaseAssetId()
);
const transferTx = await adminWallet.sendTransaction(transferTxRequest);
const response = new TransactionResponse(
transferTxRequest,
provider,
await provider.getChainId()
);
const result = await response.waitForResult();

expect(transferTx.id).toEqual(result.id);
expect(result.receipts.length).toBe(2);

expect(submitAndAwaitStatusSpy).toHaveBeenCalledTimes(1); // sends tx
expect(statusChangeSpy).toHaveBeenCalledTimes(1); // awaits result and gets receipts
expect(getTransactionWithReceiptsSpy).toHaveBeenCalledTimes(0); // we already have raw tx
});

it('should ensure create method waits till a transaction response is given', async () => {
using launched = await launchTestNode();

Expand Down

0 comments on commit 0179db4

Please sign in to comment.