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: support message types #3016

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9bde64b
rename JsonAbi MessageType property
Torres-ssf Aug 22, 2024
d62d87e
add smo contract
Torres-ssf Aug 22, 2024
8036e75
add test case for smo contract
Torres-ssf Aug 22, 2024
99aa1d1
remove unnused types from contract
Torres-ssf Aug 22, 2024
1161bbc
add new method to exhaustive examples contract
Torres-ssf Aug 22, 2024
0aaecc1
add test case to interfaces test
Torres-ssf Aug 22, 2024
557ab79
add changeset
Torres-ssf Aug 22, 2024
69debec
ajust test case
Torres-ssf Aug 23, 2024
8425ab6
re-add test case removed by accident
Torres-ssf Aug 23, 2024
73e5a9e
refact test case
Torres-ssf Aug 23, 2024
999f8f9
update changeset
Torres-ssf Aug 23, 2024
1eb36cf
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Aug 23, 2024
7771e1a
update SMO contract interface
Torres-ssf Aug 28, 2024
aa7dbd2
implement decodeMessage at Interface class
Torres-ssf Aug 28, 2024
4e1fc31
decoding message data at assembleResult
Torres-ssf Aug 28, 2024
94c2014
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Aug 28, 2024
4ebad43
modify test case
Torres-ssf Aug 28, 2024
9d18feb
modify changeset
Torres-ssf Aug 28, 2024
5950c7f
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Sep 6, 2024
bb3a376
remove uneeded test case
Torres-ssf Sep 6, 2024
9721bbf
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Sep 16, 2024
d846eae
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Sep 17, 2024
f3b09ac
remove code to decode message
Torres-ssf Sep 18, 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/lovely-rivers-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/abi-typegen": minor
"@fuel-ts/abi-coder": minor
---

fix: rename abi `MessageType.messageId` property
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/abi-coder/src/types/JsonAbiNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface LoggedType {
}

export interface MessageType {
readonly message_id: string;
readonly messageId: string;
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
readonly concreteTypeId: string;
}
export interface Configurable {
Expand Down
15 changes: 15 additions & 0 deletions packages/abi-coder/test/Interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ describe('Abi interface', () => {
});
});

describe('messagesTypes', () => {
it('sets messagesTypes properties just fine', () => {
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<A> {
VariantOne: A,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -339,4 +342,8 @@ impl MyContract for Contract {
fn simple_vector(arg: Vec<u8>) -> Vec<u8> {
arg
}
#[payable]
fn send_typed_message_bool(recipient: b256, msg_data: bool, coins: u64) {
send_typed_message(recipient, msg_data, coins);
}
Comment on lines +345 to +348
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have a related test?

}
2 changes: 1 addition & 1 deletion packages/abi-typegen/src/types/interfaces/JsonAbiNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface LoggedType {
}

export interface MessageType {
readonly message_id: string;
readonly messageId: string;
readonly concreteTypeId: string;
}
export interface Configurable {
Expand Down
50 changes: 27 additions & 23 deletions packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
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';
Expand Down Expand Up @@ -1235,35 +1237,37 @@
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)

Check failure on line 1259 in packages/fuel-gauge/src/contract.test.ts

View workflow job for this annotation

GitHub Actions / node@18

packages/fuel-gauge/src/contract.test.ts > Contract > can call SMO contract

TypeError: contract.functions.send_message is not a function ❯ packages/fuel-gauge/src/contract.test.ts:1259:8

Check failure on line 1259 in packages/fuel-gauge/src/contract.test.ts

View workflow job for this annotation

GitHub Actions / node@20

packages/fuel-gauge/src/contract.test.ts > Contract > can call SMO contract

TypeError: contract.functions.send_message is not a function ❯ packages/fuel-gauge/src/contract.test.ts:1259:8

Check failure on line 1259 in packages/fuel-gauge/src/contract.test.ts

View workflow job for this annotation

GitHub Actions / node@22

packages/fuel-gauge/src/contract.test.ts > Contract > can call SMO contract

TypeError: contract.functions.send_message is not a function ❯ packages/fuel-gauge/src/contract.test.ts:1259:8

Check failure on line 1259 in packages/fuel-gauge/src/contract.test.ts

View workflow job for this annotation

GitHub Actions / browser

packages/fuel-gauge/src/contract.test.ts > Contract > can call SMO contract

TypeError: contract.functions.send_message is not a function ❯ packages/fuel-gauge/src/contract.test.ts:1259:7
.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());
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"generic-types-contract",
"large-contract",
"multi-token-contract",
"smo-contract",
"options",
"payable-annotation",
"predicate-address",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "smo-contract"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contract;

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);
}
}
Loading