Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for unknown txn types #3003

Merged
merged 21 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9a18682
feat: added support for unknown txn types
maschad Aug 22, 2024
7495302
docs: add changeset
maschad Aug 22, 2024
5dcb8a8
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 22, 2024
dd5cb42
fix: ensure base transaction type is distinguished from unsupported
maschad Aug 22, 2024
9d3efb6
fix: update property check
maschad Aug 22, 2024
dba5a70
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 22, 2024
552ca6c
test: remove unnecessary only
maschad Aug 22, 2024
86c00fd
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 23, 2024
6b88425
fix: remove transaction encoding and decoding + hide UnknowTransactio…
maschad Aug 23, 2024
28849bf
fix: update transaction code
maschad Aug 26, 2024
13c8db6
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 26, 2024
3189053
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 27, 2024
606bae5
fix: ensure retrieval of unknown txns return a warning
maschad Aug 27, 2024
ac7201c
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 27, 2024
e7daa05
chore: clean up message and throw warning for single case
maschad Aug 27, 2024
14500a8
chore: remove unknown transaction type
maschad Aug 29, 2024
75453ec
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 29, 2024
af4f051
chore: remove other unused types
maschad Aug 29, 2024
347ff9b
linting
maschad Aug 29, 2024
c136a24
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 30, 2024
398ae1f
Merge branch 'master' into mc/chore/handle-unknown-txns
maschad Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/honest-toes-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/transactions": patch
"@fuel-ts/account": patch
---

feat: added support for unknown txn types
2 changes: 1 addition & 1 deletion packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
ExcludeResourcesOption,
Provider,
ScriptTransactionRequestLike,
TransactionResponse,
TransactionCost,
EstimateTransactionParams,
CursorPaginationArgs,
Expand All @@ -30,6 +29,7 @@ import type {
GetBalancesResponse,
Coin,
TransactionCostParams,
TransactionResponse,
} from './providers';
import {
withdrawScript,
Expand Down
1 change: 1 addition & 0 deletions packages/account/src/predicate/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class Predicate<
*/
sendTransaction(transactionRequestLike: TransactionRequestLike): Promise<TransactionResponse> {
const transactionRequest = transactionRequestify(transactionRequestLike);

return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
}

Expand Down
81 changes: 81 additions & 0 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
MESSAGE_PROOF_RAW_RESPONSE,
MESSAGE_PROOF,
} from '../../test/fixtures';
import {
MOCK_TX_UNKNOWN_RAW_PAYLOAD,
MOCK_TX_SCRIPT_RAW_PAYLOAD,
} from '../../test/fixtures/transaction-summary';
import { setupTestProviderAndWallets, launchNode, TestMessage } from '../test-utils';

import type { Coin } from './coin';
Expand Down Expand Up @@ -56,6 +60,83 @@ const getCustomFetch =
* @group node
*/
describe('Provider', () => {
it('should throw an error when retrieving a transaction with an unknown transaction type', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;

const mockProvider = await Provider.create(provider.url, {
fetch: getCustomFetch('getTransaction', {
transaction: {
id: '0x1234567890abcdef',
rawPayload: MOCK_TX_UNKNOWN_RAW_PAYLOAD, // Unknown transaction type
},
}),
});

// Spy on console.warn
const consoleWarnSpy = vi.spyOn(console, 'warn');

// Verify that only one transaction was returned (the known type)
const transaction = await mockProvider.getTransaction('0x1234567890abcdef');

expect(transaction).toBeNull();

expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining('Unsupported transaction type encountered')
);

// Clean up
consoleWarnSpy.mockRestore();
});

it('should log a warning when retrieving batch transactions with an unknown transaction type', async () => {
using launched = await setupTestProviderAndWallets();
const { provider: nodeProvider } = launched;

// Create a mock provider with custom getTransactions operation
const mockProvider = await Provider.create(nodeProvider.url, {
fetch: getCustomFetch('getTransactions', {
transactions: {
edges: [
{
node: {
id: '0x1234567890abcdef',
rawPayload: MOCK_TX_UNKNOWN_RAW_PAYLOAD,
},
},
{
node: {
id: '0xabcdef1234567890',
rawPayload: MOCK_TX_SCRIPT_RAW_PAYLOAD,
},
},
],
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
},
},
}),
});

// Spy on console.warn
const consoleWarnSpy = vi.spyOn(console, 'warn');

// Verify that only one transaction was returned (the known type)
const { transactions } = await mockProvider.getTransactions();
expect(transactions.length).toBe(1);

// Check if warning was logged
expect(consoleWarnSpy).toHaveBeenCalledWith(
expect.stringContaining('Unsupported transaction type encountered')
);

// Clean up
consoleWarnSpy.mockRestore();
});

it('can getVersion()', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;
Expand Down
38 changes: 30 additions & 8 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,12 +739,12 @@ Supported fuel-core version: ${supportedVersion}.`
* @param sendTransactionParams - The provider send transaction parameters (optional).
* @returns A promise that resolves to the transaction response object.
*/
// #region Provider-sendTransaction
async sendTransaction(
transactionRequestLike: TransactionRequestLike,
{ estimateTxDependencies = true }: ProviderSendTxParams = {}
): Promise<TransactionResponse> {
const transactionRequest = transactionRequestify(transactionRequestLike);
// #region Provider-sendTransaction
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
if (estimateTxDependencies) {
await this.estimateTxDependencies(transactionRequest);
}
Expand Down Expand Up @@ -1434,13 +1434,24 @@ Supported fuel-core version: ${supportedVersion}.`
transactionId: string
): Promise<Transaction<TTransactionType> | null> {
const { transaction } = await this.operations.getTransaction({ transactionId });

if (!transaction) {
return null;
}
return new TransactionCoder().decode(
arrayify(transaction.rawPayload),
0
)?.[0] as Transaction<TTransactionType>;

try {
return new TransactionCoder().decode(
arrayify(transaction.rawPayload),
0
)?.[0] as Transaction<TTransactionType>;
} catch (error) {
if (error instanceof FuelError && error.code === ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
// eslint-disable-next-line no-console
console.warn('Unsupported transaction type encountered');
return null;
}
throw error;
}
}

/**
Expand All @@ -1454,9 +1465,20 @@ Supported fuel-core version: ${supportedVersion}.`
} = await this.operations.getTransactions(paginationArgs);

const coder = new TransactionCoder();
const transactions = edges.map(
({ node: { rawPayload } }) => coder.decode(arrayify(rawPayload), 0)[0]
);
const transactions = edges
.map(({ node: { rawPayload } }) => {
try {
return coder.decode(arrayify(rawPayload), 0)[0];
} catch (error) {
if (error instanceof FuelError && error.code === ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
// eslint-disable-next-line no-console
console.warn('Unsupported transaction type encountered');
return null;
}
throw error;
}
})
.filter((tx): tx is Transaction => tx !== null);

return { transactions, pageInfo };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/wallet/base-wallet-unlocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { hexlify } from '@fuel-ts/utils';
import { Account } from '../account';
import { transactionRequestify } from '../providers';
import type {
TransactionResponse,
TransactionRequestLike,
CallResult,
Provider,
ProviderSendTxParams,
EstimateTransactionParams,
TransactionRequest,
TransactionResponse,
} from '../providers';
import { Signer } from '../signer';

Expand Down
2 changes: 2 additions & 0 deletions packages/account/test/fixtures/transaction-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,5 @@ export const MOCK_TX_CREATE_RAW_PAYLOAD =
'0x00000000000000010000000000000000b100016b3e4e6c6ec572832e5cd9b5bd9162d1371f932ee28c5a61f5a8607f7e0000000000000000000000000000000900000000000000010000000000000002000000000000000200000000000000000000000000000754000000000000000002cc837ec4516621729d615acb83b4871b34b59772c9ad42674f24cbf232f25b0000000000000000a1bfd8f997bb7654af676f6d8a9ebda7eb1ab63426d7f3e5745fdc1672f0031000000000004c4b4000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000e00000000000000010000000000000000000000000000000000000000000000000000000000000004181c794f94f71f983a1cb57b18ee43be3d1d3a74aa2e3ed4c9e50687a18f015600000000000000000000000000000000000000000000000000000000000000000000000000000002a1bfd8f997bb7654af676f6d8a9ebda7eb1ab63426d7f3e5745fdc1672f0031000000000004c43ec00000000000000000000000000000000000000000000000000000000000000000000000000000594740000034700000000000000000003945dfcc00110fff3005d4060495d47f03213490440764800085d47f033134904407648007c5d47f03413490440764800bf72f0007b36f000001aec5000910001405d43f035104103005fec00005047b00f5e4410005d47f03610451300504bb010724c0020284914c05053b0505fec000a5045400f5e4410005057b03072440020285504405043b0605fec100c5045000f5c4bf0905e4520005047b0705e440000504910085c4ff0985e493000504910105c4ff0a05e4930005d4bf0155fed201150491020724c0010284944c050491030724c0020284954c05045105072480010284504805d43f0371041030072440010340004117240001034001ed05d43f038104103005d47f01672480010340114125043b0105d47f01772480020340114125d43f039104103005d47f01872480008340114125043b0705d47f01972480060340114125d43f03a104103005d47f01a72480010340114125043b0705c4100005d47f01b334110005d43f03b104103005d47f01c72480010340114125043b0105047b0d05d4bf0165fed201a5049100f5c4ff0905e493000504bb0e05c4ff0e85e493000504d20085c53f0f05e4d4000504d20105c53f0f85e4d40005d4ff0205fed301f504d202072500010284fb500504d203072500020284d05005041205072480010284114805043b0e05d47f02172480060340114125d43f03c104103005d47f02272480008340114125c43f090244000001aec5000910001305d40604a5d4900005d4d00015d43f035104103005fec00005047b00f5e4410005047b120725000102847b5005047b0305fec00065051100f5e5010005053b01072540020285105405057b0405fec10085041500f5c5bf0905e416000505bb0505e580000504160085c5ff0985e417000504160105c5ff0a05e4170005d43f0155fed000d50416020725c0010284115c0504160307244002028414440504160507244001028415440134124c05047b050134100007640000e5d43f03d104103005d4bf025724c0010340124135043b120504bb110724c0010284904c05d43f026724c0010340104935c43f090244000005043b0b072480060284114805d47f02772480060340114125d43f028364000001aec5000910000305d40604a5c450000504100085d4bf03e104923005d4ff03072500018340134947248002028ed04805d43f0315fed00045fed10055d43f03f104103001a44a0002dec04115c43f0902440000047000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00fffffffffffffffffffffffffffff47616d65205374617465000000000000436f6e7472616374204964000000000047616d652052656647616d65205265662053636f726500004469726563742047616d6500000000005761732054727565010000000000000064000000000000000a000000000000000000000000018af8000000000000000200000000000000030000000000000004000000000000000500000000000000060000000000000007000000000000000865000000000000000c00000000000000030000000000000000000000000201570000000000000009000000000000000a48656c6c6f2054657374657200000000000000000000000d000000000000000e000000000000000cffffffffffff000048656c6c6f2066726f6d206d61696e20436f6e74726163740000000000000000000000000000000000000000000000000000000000000000000000000000000f00000000b1abb86f000000002151bd4b00000000fdbf0f6a0000000045b1551100000000000003b4000000000000039400000000000003d400000000000003e400000000000003f400000000000003fc000000000000040c000000000000041c00000000000004ac00000000000004dc00000000000004f400000000000000000000004041836759e99b4bd0b1a8d9a622e091bf15cbfe9f975dacc38334dfb084ced1c55d58b4e5b4072d22fd3279bf90b1f3bf6429ce4096626905037cccbc05bec7e4';
export const MOCK_TX_MINT_RAW_PAYLOAD =
'0x0000000000000002000000000000000500000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
export const MOCK_TX_UNKNOWN_RAW_PAYLOAD =
'0x0000000000000006000000000000000500000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
Loading