Skip to content

Commit

Permalink
chore!: remove deprecated submitAndAwait operation (#3548)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk authored Jan 6, 2025
1 parent 458b7cf commit d404734
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-meals-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": minor
---

chore!: remove deprecated `submitAndAwait` operation
6 changes: 0 additions & 6 deletions packages/account/src/providers/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,6 @@ query getConsensusParametersVersion {
}
}

subscription submitAndAwait($encodedTransaction: HexString!) {
submitAndAwait(tx: $encodedTransaction) {
...transactionStatusSubscriptionFragment
}
}

subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
submitAndAwaitStatus(tx: $encodedTransaction) {
...transactionStatusSubscriptionFragment
Expand Down
58 changes: 30 additions & 28 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ Supported fuel-core version: ${mock.supportedVersion}.`
vi.spyOn(global, 'fetch').mockImplementationOnce(() => {
const responseObject = {
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SuccessStatus',
time: 'data: 4611686020137152060',
},
Expand All @@ -1436,11 +1436,11 @@ Supported fuel-core version: ${mock.supportedVersion}.`
);
});

for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
expect(submitAndAwait.type).toEqual('SuccessStatus');
expect((<SubmittedStatus>submitAndAwait).time).toEqual('data: 4611686020137152060');
expect(submitAndAwaitStatus.type).toEqual('SuccessStatus');
expect((<SubmittedStatus>submitAndAwaitStatus).time).toEqual('data: 4611686020137152060');
}
});

Expand All @@ -1455,11 +1455,11 @@ Supported fuel-core version: ${mock.supportedVersion}.`
const encoder = new TextEncoder();

controller.enqueue(
encoder.encode(`data:${JSON.stringify({ data: { submitAndAwait: { a: 0 } } })}\n\n`)
encoder.encode(`data:${JSON.stringify({ data: { submitAndAwaitStatus: { a: 0 } } })}\n\n`)
);
controller.enqueue(encoder.encode(':keep-alive-text\n\n'));
controller.enqueue(
encoder.encode(`data:${JSON.stringify({ data: { submitAndAwait: { a: 1 } } })}\n\n`)
encoder.encode(`data:${JSON.stringify({ data: { submitAndAwaitStatus: { a: 1 } } })}\n\n`)
);
controller.close();
},
Expand All @@ -1468,7 +1468,7 @@ Supported fuel-core version: ${mock.supportedVersion}.`

let numberOfEvents = 0;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
numberOfEvents += 1;
Expand All @@ -1484,14 +1484,14 @@ Supported fuel-core version: ${mock.supportedVersion}.`
vi.spyOn(global, 'fetch').mockImplementationOnce(() => {
const event1 = {
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SubmittedStatus',
},
},
};
const event2 = {
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SuccessStatus',
},
},
Expand All @@ -1515,16 +1515,16 @@ Supported fuel-core version: ${mock.supportedVersion}.`

let numberOfEvents = 0;

for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
numberOfEvents += 1;

if (numberOfEvents === 1) {
expect(submitAndAwait.type).toEqual('SubmittedStatus');
expect(submitAndAwaitStatus.type).toEqual('SubmittedStatus');
}
if (numberOfEvents === 2) {
expect(submitAndAwait.type).toEqual('SuccessStatus');
expect(submitAndAwaitStatus.type).toEqual('SuccessStatus');
}
}

Expand All @@ -1537,7 +1537,7 @@ Supported fuel-core version: ${mock.supportedVersion}.`
vi.spyOn(global, 'fetch').mockImplementationOnce(() => {
const responseObject = JSON.stringify({
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SuccessStatus',
},
},
Expand All @@ -1563,10 +1563,10 @@ Supported fuel-core version: ${mock.supportedVersion}.`
);
});

for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
expect(submitAndAwait.type).toEqual('SuccessStatus');
expect(submitAndAwaitStatus.type).toEqual('SuccessStatus');
}
});

Expand All @@ -1577,14 +1577,14 @@ Supported fuel-core version: ${mock.supportedVersion}.`
vi.spyOn(global, 'fetch').mockImplementationOnce(() => {
const event1 = {
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SubmittedStatus',
},
},
};
const event2 = JSON.stringify({
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SuccessStatus',
},
},
Expand All @@ -1611,16 +1611,16 @@ Supported fuel-core version: ${mock.supportedVersion}.`

let numberOfEvents = 0;

for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
numberOfEvents += 1;

if (numberOfEvents === 1) {
expect(submitAndAwait.type).toEqual('SubmittedStatus');
expect(submitAndAwaitStatus.type).toEqual('SubmittedStatus');
}
if (numberOfEvents === 2) {
expect(submitAndAwait.type).toEqual('SuccessStatus');
expect(submitAndAwaitStatus.type).toEqual('SuccessStatus');
}
}

Expand All @@ -1634,14 +1634,14 @@ Supported fuel-core version: ${mock.supportedVersion}.`
vi.spyOn(global, 'fetch').mockImplementationOnce(() => {
const event1 = JSON.stringify({
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SubmittedStatus',
},
},
});
const event2 = JSON.stringify({
data: {
submitAndAwait: {
submitAndAwaitStatus: {
type: 'SuccessStatus',
},
},
Expand Down Expand Up @@ -1670,16 +1670,16 @@ Supported fuel-core version: ${mock.supportedVersion}.`

let numberOfEvents = 0;

for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus({
encodedTransaction: "it's mocked so doesn't matter",
})) {
numberOfEvents += 1;

if (numberOfEvents === 1) {
expect(submitAndAwait.type).toEqual('SubmittedStatus');
expect(submitAndAwaitStatus.type).toEqual('SubmittedStatus');
}
if (numberOfEvents === 2) {
expect(submitAndAwait.type).toEqual('SuccessStatus');
expect(submitAndAwaitStatus.type).toEqual('SuccessStatus');
}
}

Expand Down Expand Up @@ -1708,9 +1708,11 @@ Supported fuel-core version: ${mock.supportedVersion}.`
await expectToThrowFuelError(
async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const { submitAndAwait } of await provider.operations.submitAndAwait({
encodedTransaction: "it's mocked so doesn't matter",
})) {
for await (const { submitAndAwaitStatus } of await provider.operations.submitAndAwaitStatus(
{
encodedTransaction: "it's mocked so doesn't matter",
}
)) {
// shouldn't be reached!
expect(true).toBeFalsy();
}
Expand Down
15 changes: 1 addition & 14 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,7 @@ type NodeInfoCache = Record<string, NodeInfo>;

type Operations = ReturnType<typeof getOperationsSdk>;

type SdkOperations = Omit<
Operations,
'submitAndAwait' | 'statusChange' | 'submitAndAwaitStatus'
> & {
/**
* This method is DEPRECATED and will be REMOVED in v1.
*
* This method will hang until the transaction is fully processed, as described in https://github.com/FuelLabs/fuel-core/issues/2108.
*
* Please use the `submitAndAwaitStatus` method instead.
*/
submitAndAwait: (
...args: Parameters<Operations['submitAndAwait']>
) => Promise<ReturnType<Operations['submitAndAwait']>>;
type SdkOperations = Omit<Operations, 'statusChange' | 'submitAndAwaitStatus'> & {
statusChange: (
...args: Parameters<Operations['statusChange']>
) => Promise<ReturnType<Operations['statusChange']>>;
Expand Down
10 changes: 6 additions & 4 deletions packages/fuel-gauge/src/transaction-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('TransactionResponse', () => {
);

it(
'should throw error for a SqueezedOut status update [waitForResult]',
'should throw error for a SqueezedOut status update [submitAndAwaitStatus]',
{ timeout: 10_000, retry: 10 },
async () => {
/**
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('TransactionResponse', () => {
);

it(
'should throw error for a SqueezedOut status update [submitAndAwait]',
'should throw error for a SqueezedOut status update [statusChange]',
{ retry: 10 },
async () => {
using launched = await launchTestNode({
Expand Down Expand Up @@ -294,11 +294,13 @@ describe('TransactionResponse', () => {
genesisWallet.address,
await genesisWallet.signTransaction(request)
);
const submit = await provider.sendTransaction(request);

const txResponse = new TransactionResponse(submit.id, provider, await provider.getChainId());

await expectToThrowFuelError(
async () => {
const submit = await provider.sendTransaction(request);
await submit.waitForResult();
await txResponse.waitForResult();
},
{ code: ErrorCode.TRANSACTION_SQUEEZED_OUT }
);
Expand Down

0 comments on commit d404734

Please sign in to comment.