From 9bde64b4fd52023ba086e051a230add481b162a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:34:27 -0300 Subject: [PATCH 01/19] rename JsonAbi MessageType property --- packages/abi-coder/src/types/JsonAbiNew.ts | 2 +- packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/abi-coder/src/types/JsonAbiNew.ts b/packages/abi-coder/src/types/JsonAbiNew.ts index 4d9481c1128..6aff2ad11c1 100644 --- a/packages/abi-coder/src/types/JsonAbiNew.ts +++ b/packages/abi-coder/src/types/JsonAbiNew.ts @@ -91,7 +91,7 @@ export interface LoggedType { } export interface MessageType { - readonly message_id: string; + readonly messageId: string; readonly concreteTypeId: string; } export interface Configurable { diff --git a/packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts b/packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts index 4d9481c1128..6aff2ad11c1 100644 --- a/packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts +++ b/packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts @@ -91,7 +91,7 @@ export interface LoggedType { } export interface MessageType { - readonly message_id: string; + readonly messageId: string; readonly concreteTypeId: string; } export interface Configurable { From d62d87e788d3021d102aef7731a4a258acb19333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:07:59 -0300 Subject: [PATCH 02/19] add smo contract --- .../test/fixtures/forc-projects/Forc.toml | 1 + .../forc-projects/smo-contract/Forc.toml | 7 +++++++ .../forc-projects/smo-contract/src/main.sw | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/Forc.toml create mode 100644 packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml index b7fa116ba4c..f0d5c9fa99f 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml @@ -17,6 +17,7 @@ members = [ "generic-types-contract", "large-contract", "multi-token-contract", + "smo-contract", "options", "payable-annotation", "predicate-address", diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/Forc.toml new file mode 100644 index 00000000000..96cfa63afbd --- /dev/null +++ b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/Forc.toml @@ -0,0 +1,7 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "smo-contract" + +[dependencies] diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw new file mode 100644 index 00000000000..ce2d02b23d3 --- /dev/null +++ b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw @@ -0,0 +1,17 @@ +contract; + +use std::bytes::Bytes; +use std::string::String; +use std::message::send_typed_message; + +abi SMOContract { + #[payable] + fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64); +} + +impl SMOContract for Contract { + #[payable] + fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64) { + send_typed_message(recipient, msg_data, coins); + } +} From 8036e757ecad15dc396e15fb80b417ad5dee8153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:08:15 -0300 Subject: [PATCH 03/19] add test case for smo contract --- packages/fuel-gauge/src/contract.test.ts | 50 +++++++++++++----------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index f0889d0a43e..6e23663868f 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -14,14 +14,16 @@ import { PolicyType, ZeroBytes32, buildFunctionResult, + ReceiptType, } from 'fuels'; -import type { JsonAbi, ScriptTransactionRequest, TransferParams } from 'fuels'; +import type { JsonAbi, ReceiptMessageOut, ScriptTransactionRequest, TransferParams } from 'fuels'; import { expectToThrowFuelError, ASSET_A, ASSET_B, launchTestNode } from 'fuels/test-utils'; import type { DeployContractConfig } from 'fuels/test-utils'; import { CallTestContract, CallTestContractFactory, + SmoContractFactory, StorageTestContract, StorageTestContractFactory, } from '../test/typegen/contracts'; @@ -1235,35 +1237,37 @@ describe('Contract', () => { expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee); }); - it('should ensure "maxFee" and "gasLimit" can be set on a multicall', async () => { - using contract = await setupTestContract(); + it('can call SMO contract', async () => { + using launched = await launchTestNode({ + contractsConfigs: [ + { + factory: SmoContractFactory, + }, + ], + }); - const gasLimit = 500_000; - const maxFee = 250_000; + const { + provider, + wallets: [recipient], + contracts: [contract], + } = launched; - const { waitForResult } = await contract - .multiCall([ - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - contract.functions.foo(1336), - ]) - .txParams({ gasLimit, maxFee }) + const data = [1, 2, 3, 4, 5]; + const baseAssetId = provider.getBaseAssetId(); + + const { waitForResult } = await contract.functions + .send_message(recipient.address.toB256(), data, 1) + .callParams({ forward: [1, baseAssetId] }) .call(); const { - transactionResult: { transaction }, + transactionResult: { receipts }, } = await waitForResult(); - const { scriptGasLimit, policies } = transaction; + const messageOutReceipt = receipts.find( + ({ type }) => ReceiptType.MessageOut === type + ) as ReceiptMessageOut; - const maxFeePolicy = policies?.find((policy) => policy.type === PolicyType.MaxFee); - - expect(scriptGasLimit?.toNumber()).toBe(gasLimit); - expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee); + expect(messageOutReceipt.recipient).toBe(recipient.address.toB256()); }); }); From 99aa1d1c9392c19fbe5dfac4722e0d0f4f022000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:56:31 -0300 Subject: [PATCH 04/19] remove unnused types from contract --- .../test/fixtures/forc-projects/smo-contract/src/main.sw | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw index ce2d02b23d3..056c26c9d8b 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw +++ b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw @@ -1,7 +1,5 @@ contract; -use std::bytes::Bytes; -use std::string::String; use std::message::send_typed_message; abi SMOContract { From 1161bbcaccce96f881284048a2c8509983b372f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:20:01 -0300 Subject: [PATCH 05/19] add new method to exhaustive examples contract --- .../fixtures/forc-projects/exhaustive-examples/src/main.sw | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/abi-coder/test/fixtures/forc-projects/exhaustive-examples/src/main.sw b/packages/abi-coder/test/fixtures/forc-projects/exhaustive-examples/src/main.sw index abed2d93caf..388aaa095ba 100644 --- a/packages/abi-coder/test/fixtures/forc-projects/exhaustive-examples/src/main.sw +++ b/packages/abi-coder/test/fixtures/forc-projects/exhaustive-examples/src/main.sw @@ -2,6 +2,7 @@ contract; use std::b512::B512; use std::bytes::Bytes; use std::string::String; +use std::message::send_typed_message; enum EnumWithGeneric { VariantOne: A, @@ -181,6 +182,8 @@ abi MyContract { arg3: (str[5], bool), arg4: MyOtherStruct, ); + #[payable] + fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64); } impl MyContract for Contract { @@ -339,4 +342,8 @@ impl MyContract for Contract { fn simple_vector(arg: Vec) -> Vec { arg } + #[payable] + fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64) { + send_typed_message(recipient, msg_data, coins); + } } From 0aaecc179f47bcabc89c9f19856a3b9ac64c035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:21:34 -0300 Subject: [PATCH 06/19] add test case to interfaces test --- packages/abi-coder/test/Interface.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/abi-coder/test/Interface.test.ts b/packages/abi-coder/test/Interface.test.ts index 4e28fa37628..dccce733a46 100644 --- a/packages/abi-coder/test/Interface.test.ts +++ b/packages/abi-coder/test/Interface.test.ts @@ -131,6 +131,21 @@ describe('Abi interface', () => { }); }); + describe('messagesTypes', () => { + it('sets messagesTypes properties just fine', () => { + const messagesTypes = exhaustiveExamplesAbi.messagesTypes; + expect(messagesTypes.length).greaterThan(0); + messagesTypes.forEach((messageType) => { + expect(messageType.messageId).toBeDefined(); + expect(messageType.concreteTypeId).toBeDefined(); + const foundType = exhaustiveExamplesAbi.concreteTypes.find( + (id) => id.concreteTypeId === messageType.concreteTypeId + ); + expect(foundType).toBeDefined(); + }); + }); + }); + describe('encoding/decoding', () => { describe('encodes and decodes', () => { it.each([ From 557ab7950f2fbcd82ed56642b969f5588ccf1db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:31:22 -0300 Subject: [PATCH 07/19] add changeset --- .changeset/lovely-rivers-impress.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/lovely-rivers-impress.md diff --git a/.changeset/lovely-rivers-impress.md b/.changeset/lovely-rivers-impress.md new file mode 100644 index 00000000000..a02e6fcd56b --- /dev/null +++ b/.changeset/lovely-rivers-impress.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/abi-typegen": minor +"@fuel-ts/abi-coder": minor +--- + +fix: rename abi `MessageType.messageId` property From 69debec53f3c92b3d3e2caadbb0160d40635d237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:24:48 -0300 Subject: [PATCH 08/19] ajust test case --- packages/fuel-gauge/src/contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 6e23663868f..257abf38443 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1252,11 +1252,11 @@ describe('Contract', () => { contracts: [contract], } = launched; - const data = [1, 2, 3, 4, 5]; + const data = true; const baseAssetId = provider.getBaseAssetId(); const { waitForResult } = await contract.functions - .send_message(recipient.address.toB256(), data, 1) + .send_typed_message_bool(recipient.address.toB256(), data, 1) .callParams({ forward: [1, baseAssetId] }) .call(); From 8425ab62d5c3fedce40994cd1008af17d249032b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:30:11 -0300 Subject: [PATCH 09/19] re-add test case removed by accident --- packages/fuel-gauge/src/contract.test.ts | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 257abf38443..a8cbeaac8b6 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1237,6 +1237,38 @@ describe('Contract', () => { expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee); }); + it('should ensure "maxFee" and "gasLimit" can be set on a multicall', async () => { + using contract = await setupTestContract(); + + const gasLimit = 500_000; + const maxFee = 250_000; + + const { waitForResult } = await contract + .multiCall([ + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + contract.functions.foo(1336), + ]) + .txParams({ gasLimit, maxFee }) + .call(); + + const { + transactionResult: { transaction }, + } = await waitForResult(); + + const { scriptGasLimit, policies } = transaction; + + const maxFeePolicy = policies?.find((policy) => policy.type === PolicyType.MaxFee); + + expect(scriptGasLimit?.toNumber()).toBe(gasLimit); + expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee); + }); + it('can call SMO contract', async () => { using launched = await launchTestNode({ contractsConfigs: [ From 73e5a9e9e39bbfdc9be002cd9f799274e47be557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:32:34 -0300 Subject: [PATCH 10/19] refact test case --- packages/abi-coder/test/Interface.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/abi-coder/test/Interface.test.ts b/packages/abi-coder/test/Interface.test.ts index dccce733a46..b78e507afe7 100644 --- a/packages/abi-coder/test/Interface.test.ts +++ b/packages/abi-coder/test/Interface.test.ts @@ -133,13 +133,13 @@ describe('Abi interface', () => { describe('messagesTypes', () => { it('sets messagesTypes properties just fine', () => { - const messagesTypes = exhaustiveExamplesAbi.messagesTypes; + const { messagesTypes } = exhaustiveExamplesAbi; expect(messagesTypes.length).greaterThan(0); - messagesTypes.forEach((messageType) => { - expect(messageType.messageId).toBeDefined(); - expect(messageType.concreteTypeId).toBeDefined(); + messagesTypes.forEach(({ concreteTypeId, messageId }) => { + expect(messageId).toBeDefined(); + expect(concreteTypeId).toBeDefined(); const foundType = exhaustiveExamplesAbi.concreteTypes.find( - (id) => id.concreteTypeId === messageType.concreteTypeId + (id) => id.concreteTypeId === concreteTypeId ); expect(foundType).toBeDefined(); }); From 999f8f9e0fb9bc8c2d98e94c5b6b58686cd1ade7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:40:49 -0300 Subject: [PATCH 11/19] update changeset --- .changeset/lovely-rivers-impress.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/lovely-rivers-impress.md b/.changeset/lovely-rivers-impress.md index a02e6fcd56b..bb209bb9712 100644 --- a/.changeset/lovely-rivers-impress.md +++ b/.changeset/lovely-rivers-impress.md @@ -1,6 +1,6 @@ --- -"@fuel-ts/abi-typegen": minor -"@fuel-ts/abi-coder": minor +"@fuel-ts/abi-typegen": patch +"@fuel-ts/abi-coder": patch --- fix: rename abi `MessageType.messageId` property From 7771e1a10a34e16863c10f27a5ac4734554e98c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:28:32 -0300 Subject: [PATCH 12/19] update SMO contract interface --- .../fixtures/forc-projects/smo-contract/src/main.sw | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw index 056c26c9d8b..7463a9c2496 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw +++ b/packages/fuel-gauge/test/fixtures/forc-projects/smo-contract/src/main.sw @@ -1,10 +1,15 @@ contract; use std::message::send_typed_message; +use std::bytes::Bytes; abi SMOContract { #[payable] fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64); + #[payable] + fn send_typed_message_u8(recipient: b256, msg_data: u8, coins: u64); + #[payable] + fn send_typed_message_bytes(recipient: b256, msg_data: Bytes, coins: u64); } impl SMOContract for Contract { @@ -12,4 +17,12 @@ impl SMOContract for Contract { fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64) { send_typed_message(recipient, msg_data, coins); } + #[payable] + fn send_typed_message_u8(recipient: b256, msg_data: u8, coins: u64) { + send_typed_message(recipient, msg_data, coins); + } + #[payable] + fn send_typed_message_bytes(recipient: b256, msg_data: Bytes, coins: u64) { + send_typed_message(recipient, msg_data, coins); + } } From aa7dbd24f3efa7b4ffe05bb7f901d52546642174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:29:28 -0300 Subject: [PATCH 13/19] implement decodeMessage at Interface class --- packages/abi-coder/src/Interface.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/abi-coder/src/Interface.ts b/packages/abi-coder/src/Interface.ts index be85aa6f7d3..3d44fbb040f 100644 --- a/packages/abi-coder/src/Interface.ts +++ b/packages/abi-coder/src/Interface.ts @@ -5,6 +5,7 @@ import { arrayify } from '@fuel-ts/utils'; import { AbiCoder } from './AbiCoder'; import { FunctionFragment } from './FunctionFragment'; +import { NumberCoder } from './encoding/coders'; import type { DecodedValue, InputValue } from './encoding/coders/AbstractCoder'; import type { JsonAbiArgument, JsonAbiOld } from './types/JsonAbi'; import type { Configurable, JsonAbi } from './types/JsonAbiNew'; @@ -74,6 +75,24 @@ export class Interface { }); } + decodeMessage(messageData: Uint8Array) { + const [decodedAbiMessageId, offset] = new NumberCoder('u8', { padToWordSize: true }).decode( + messageData, + 0 + ); + const dataOffset = messageData.slice(offset, messageData.length); + + const messageType = this.jsonAbi.messagesTypes.find( + (type) => type.messageId === decodedAbiMessageId.toString() + ); + + if (!messageType) { + // TODO: Add error code and message + throw new FuelError(FuelError.CODES.DECODE_ERROR, 'TBD'); + } + return this.decodeType(messageType.concreteTypeId, dataOffset)[0]; + } + encodeConfigurable(name: string, value: InputValue) { const configurable = this.jsonAbiOld.configurables.find((c) => c.name === name); if (!configurable) { From 4e1fc31d7740da9709552b451ec8376026ef1b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:36:18 -0300 Subject: [PATCH 14/19] decoding message data at assembleResult --- .../transaction-response.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/account/src/providers/transaction-response/transaction-response.ts b/packages/account/src/providers/transaction-response/transaction-response.ts index 93878735add..f20387b199d 100644 --- a/packages/account/src/providers/transaction-response/transaction-response.ts +++ b/packages/account/src/providers/transaction-response/transaction-response.ts @@ -1,3 +1,4 @@ +import { Interface } from '@fuel-ts/abi-coder'; import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { BN } from '@fuel-ts/math'; import { bn } from '@fuel-ts/math'; @@ -24,7 +25,7 @@ import type { Output, TransactionType, } from '@fuel-ts/transactions'; -import { OutputType, TransactionCoder, TxPointerCoder } from '@fuel-ts/transactions'; +import { OutputType, ReceiptType, TransactionCoder, TxPointerCoder } from '@fuel-ts/transactions'; import { arrayify, assertUnreachable } from '@fuel-ts/utils'; import type { @@ -369,6 +370,20 @@ export class TransactionResponse { ); transactionResult.logs = logs; + + const decodedMessage: Record = {}; + + const abiInterface = new Interface(this.abis.main); + + transactionSummary.receipts.forEach((receipt) => { + if (receipt.type === ReceiptType.MessageOut) { + try { + const decoded = abiInterface.decodeMessage(receipt.data); + decodedMessage[receipt.nonce] = decoded; + // eslint-disable-next-line no-empty + } catch {} + } + }); } const { receipts } = transactionResult; From 4ebad43c67b0bcd60f1e1e3eb71ac566786d3d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:41:23 -0300 Subject: [PATCH 15/19] modify test case --- packages/fuel-gauge/src/contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 23a5ba71ccc..e0b6e1506e8 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1124,11 +1124,11 @@ describe('Contract', () => { contracts: [contract], } = launched; - const data = true; + const data = [1, 2, 3, 4, 5, 6, 7, 8]; const baseAssetId = provider.getBaseAssetId(); const { waitForResult } = await contract.functions - .send_typed_message_bool(recipient.address.toB256(), data, 1) + .send_typed_message_bytes(recipient.address.toB256(), data, 1) .callParams({ forward: [1, baseAssetId] }) .call(); From 9d18feba36d8202c3ca7a5a7a9fc6c9516030e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:37:15 -0300 Subject: [PATCH 16/19] modify changeset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nedim Salkić --- .changeset/lovely-rivers-impress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/lovely-rivers-impress.md b/.changeset/lovely-rivers-impress.md index bb209bb9712..35fdf6b03e6 100644 --- a/.changeset/lovely-rivers-impress.md +++ b/.changeset/lovely-rivers-impress.md @@ -3,4 +3,4 @@ "@fuel-ts/abi-coder": patch --- -fix: rename abi `MessageType.messageId` property +feat: support message types From bb3a376269326f94ecccc6c1a609463d145d6662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Fri, 6 Sep 2024 10:38:11 -0300 Subject: [PATCH 17/19] remove uneeded test case --- packages/abi-coder/test/Interface.test.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/abi-coder/test/Interface.test.ts b/packages/abi-coder/test/Interface.test.ts index eb9bf115bb3..0980014ee0f 100644 --- a/packages/abi-coder/test/Interface.test.ts +++ b/packages/abi-coder/test/Interface.test.ts @@ -130,21 +130,6 @@ describe('Abi interface', () => { }); }); - describe('messagesTypes', () => { - it('sets messagesTypes properties just fine', () => { - const { messagesTypes } = exhaustiveExamplesAbi; - expect(messagesTypes.length).greaterThan(0); - messagesTypes.forEach(({ concreteTypeId, messageId }) => { - expect(messageId).toBeDefined(); - expect(concreteTypeId).toBeDefined(); - const foundType = exhaustiveExamplesAbi.concreteTypes.find( - (id) => id.concreteTypeId === concreteTypeId - ); - expect(foundType).toBeDefined(); - }); - }); - }); - describe('encoding/decoding', () => { describe('encodes and decodes', () => { it.each([ From f3b09acda5350e762b8ea944024268d16d57b380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Tue, 17 Sep 2024 21:38:45 -0300 Subject: [PATCH 18/19] remove code to decode message --- packages/abi-coder/src/Interface.ts | 19 ------------------- .../transaction-response.ts | 17 +---------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/packages/abi-coder/src/Interface.ts b/packages/abi-coder/src/Interface.ts index 3d44fbb040f..be85aa6f7d3 100644 --- a/packages/abi-coder/src/Interface.ts +++ b/packages/abi-coder/src/Interface.ts @@ -5,7 +5,6 @@ import { arrayify } from '@fuel-ts/utils'; import { AbiCoder } from './AbiCoder'; import { FunctionFragment } from './FunctionFragment'; -import { NumberCoder } from './encoding/coders'; import type { DecodedValue, InputValue } from './encoding/coders/AbstractCoder'; import type { JsonAbiArgument, JsonAbiOld } from './types/JsonAbi'; import type { Configurable, JsonAbi } from './types/JsonAbiNew'; @@ -75,24 +74,6 @@ export class Interface { }); } - decodeMessage(messageData: Uint8Array) { - const [decodedAbiMessageId, offset] = new NumberCoder('u8', { padToWordSize: true }).decode( - messageData, - 0 - ); - const dataOffset = messageData.slice(offset, messageData.length); - - const messageType = this.jsonAbi.messagesTypes.find( - (type) => type.messageId === decodedAbiMessageId.toString() - ); - - if (!messageType) { - // TODO: Add error code and message - throw new FuelError(FuelError.CODES.DECODE_ERROR, 'TBD'); - } - return this.decodeType(messageType.concreteTypeId, dataOffset)[0]; - } - encodeConfigurable(name: string, value: InputValue) { const configurable = this.jsonAbiOld.configurables.find((c) => c.name === name); if (!configurable) { diff --git a/packages/account/src/providers/transaction-response/transaction-response.ts b/packages/account/src/providers/transaction-response/transaction-response.ts index b2ba11f5b1c..845d41a7263 100644 --- a/packages/account/src/providers/transaction-response/transaction-response.ts +++ b/packages/account/src/providers/transaction-response/transaction-response.ts @@ -1,4 +1,3 @@ -import { Interface } from '@fuel-ts/abi-coder'; import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { BN } from '@fuel-ts/math'; import { bn } from '@fuel-ts/math'; @@ -25,7 +24,7 @@ import type { Output, TransactionType, } from '@fuel-ts/transactions'; -import { OutputType, ReceiptType, TransactionCoder, TxPointerCoder } from '@fuel-ts/transactions'; +import { OutputType, TransactionCoder, TxPointerCoder } from '@fuel-ts/transactions'; import { arrayify, assertUnreachable } from '@fuel-ts/utils'; import type { @@ -379,20 +378,6 @@ export class TransactionResponse { ); transactionResult.logs = logs; - - const decodedMessage: Record = {}; - - const abiInterface = new Interface(this.abis.main); - - transactionSummary.receipts.forEach((receipt) => { - if (receipt.type === ReceiptType.MessageOut) { - try { - const decoded = abiInterface.decodeMessage(receipt.data); - decodedMessage[receipt.nonce] = decoded; - // eslint-disable-next-line no-empty - } catch {} - } - }); } const { receipts } = transactionResult; From 9aeccc14367f8ae379de6d85d607451e2e34d7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Wed, 18 Sep 2024 23:50:50 -0300 Subject: [PATCH 19/19] improve test case --- packages/fuel-gauge/src/contract.test.ts | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 9262f967ec4..23948c13eb4 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1132,19 +1132,32 @@ describe('Contract', () => { const data = [1, 2, 3, 4, 5, 6, 7, 8]; const baseAssetId = provider.getBaseAssetId(); - const { waitForResult } = await contract.functions - .send_typed_message_bytes(recipient.address.toB256(), data, 1) - .callParams({ forward: [1, baseAssetId] }) + const { waitForResult } = await contract + .multiCall([ + contract.functions + .send_typed_message_u8(recipient.address.toB256(), 10, 1) + .callParams({ forward: [1, baseAssetId] }), + contract.functions + .send_typed_message_bool(recipient.address.toB256(), true, 1) + .callParams({ forward: [1, baseAssetId] }), + contract.functions + .send_typed_message_bytes(recipient.address.toB256(), data, 1) + .callParams({ forward: [1, baseAssetId] }), + ]) .call(); const { transactionResult: { receipts }, } = await waitForResult(); - const messageOutReceipt = receipts.find( + const messageOutReceipts = receipts.filter( ({ type }) => ReceiptType.MessageOut === type - ) as ReceiptMessageOut; + ) as ReceiptMessageOut[]; - expect(messageOutReceipt.recipient).toBe(recipient.address.toB256()); + expect(messageOutReceipts.length).toBe(3); + + messageOutReceipts.forEach((receipt) => { + expect(receipt.recipient).toBe(recipient.address.toB256()); + }); }); });