Skip to content

Commit

Permalink
fix: flaky TransactionResponse test (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk authored May 8, 2024
1 parent fb0e12f commit 24b1d0c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .changeset/poor-apes-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
81 changes: 42 additions & 39 deletions packages/fuel-gauge/src/transaction-response.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {} from '@fuel-ts/account/dist/providers/__generated__/operations';
import { generateTestWallet, launchNode } from '@fuel-ts/account/test-utils';
import { ErrorCode } from '@fuel-ts/errors';
import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
Expand Down Expand Up @@ -247,42 +246,46 @@ describe('TransactionResponse', () => {
cleanup();
});

it('should throw error for a SqueezedOut status update [submitAndAwait]', async () => {
const { cleanup, ip, port } = await launchNode({
args: ['--poa-instant', 'false', '--poa-interval-period', '1s', '--tx-pool-ttl', '200ms'],
loggingEnabled: false,
});
const nodeProvider = await Provider.create(`http://${ip}:${port}/v1/graphql`);

const genesisWallet = new WalletUnlocked(
process.env.GENESIS_SECRET || randomBytes(32),
nodeProvider
);

const request = new ScriptTransactionRequest();

request.addCoinOutput(Wallet.generate(), 100, baseAssetId);

const txCost = await genesisWallet.provider.getTransactionCost(request, {
signatureCallback: (tx) => tx.addAccountWitnesses(genesisWallet),
});

request.gasLimit = txCost.gasUsed;
request.maxFee = txCost.maxFee;

await genesisWallet.fund(request, txCost);

request.updateWitnessByOwner(
genesisWallet.address,
await genesisWallet.signTransaction(request)
);

await expectToThrowFuelError(
async () => {
await nodeProvider.sendTransaction(request, { awaitExecution: true });
},
{ code: ErrorCode.TRANSACTION_SQUEEZED_OUT }
);
cleanup();
});
it(
'should throw error for a SqueezedOut status update [submitAndAwait]',
async () => {
const { cleanup, ip, port } = await launchNode({
args: ['--poa-instant', 'false', '--poa-interval-period', '4s', '--tx-pool-ttl', '1s'],
loggingEnabled: false,
});
const nodeProvider = await Provider.create(`http://${ip}:${port}/v1/graphql`);

const genesisWallet = new WalletUnlocked(
process.env.GENESIS_SECRET || randomBytes(32),
nodeProvider
);

const request = new ScriptTransactionRequest();

request.addCoinOutput(Wallet.generate(), 100, baseAssetId);

const txCost = await genesisWallet.provider.getTransactionCost(request, {
signatureCallback: (tx) => tx.addAccountWitnesses(genesisWallet),
});

request.gasLimit = txCost.gasUsed;
request.maxFee = txCost.maxFee;

await genesisWallet.fund(request, txCost);

request.updateWitnessByOwner(
genesisWallet.address,
await genesisWallet.signTransaction(request)
);

await expectToThrowFuelError(
async () => {
await nodeProvider.sendTransaction(request, { awaitExecution: true });
},
{ code: ErrorCode.TRANSACTION_SQUEEZED_OUT }
);
cleanup();
},
{ retry: 10 }
);
});

0 comments on commit 24b1d0c

Please sign in to comment.