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/validate-blob-ids
  • Loading branch information
danielbate committed Aug 30, 2024
2 parents b195cd9 + a36626a commit 36facf5
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 138 deletions.
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
4 changes: 4 additions & 0 deletions .changeset/lazy-teachers-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: deployed the `create fuels` template
5 changes: 5 additions & 0 deletions .changeset/light-lizards-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-coder": patch
---

fix: remove `u64` from `NumberCoderType`
5 changes: 5 additions & 0 deletions .changeset/thin-shrimps-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/transactions": patch
---

fix: `UtxoIdCoder` output index to be `u16`
1 change: 1 addition & 0 deletions apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ BigNumber
Gwei
onchain
Vercel
vercel
hardcoded
differentiators
updatable
Expand Down
4 changes: 4 additions & 0 deletions apps/docs/src/guide/creating-a-fuel-dapp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

![End result of this guide](../../public/creating-a-fuel-dapp-create-fuels-end-result.png)

You can also check it live, deployed to the Testnet:

- [https://create-fuels-template.vercel.app/](https://create-fuels-template.vercel.app/)

## Initializing the project

The first step is to run the command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This guide builds on the [Creating a Fuel dApp](./index.md) guide. Once you've g

![End result of this guide](../../public/working-with-predicates-end-result.png)

You can also check it live, deployed to the Testnet:

- [https://create-fuels-template.vercel.app/](https://create-fuels-template.vercel.app/)

## Adding a Configurable pin

The current predicate functionality we have is a simple one that checks if the user has a pin. We will modify this predicate to accept a configurable pin. This will allow the user to set their own pin.
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/src/encoding/coders/NumberCoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WORD_SIZE } from '../../utils/constants';

import { Coder } from './AbstractCoder';

type NumberCoderType = 'u8' | 'u16' | 'u32' | 'u64';
type NumberCoderType = 'u8' | 'u16' | 'u32';

const getLength = (baseType: NumberCoderType): number => {
switch (baseType) {
Expand Down
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
if (estimateTxDependencies) {
await this.estimateTxDependencies(transactionRequest);
}
Expand Down Expand Up @@ -1445,13 +1445,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 @@ -1465,9 +1476,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

0 comments on commit 36facf5

Please sign in to comment.