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

Merged
merged 27 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 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
1dccc91
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Sep 19, 2024
9aeccc1
improve test case
Torres-ssf Sep 19, 2024
6c5e3ad
Merge branch 'master' into st/fix/rename-abi-message-id-property
Torres-ssf Sep 19, 2024
dbf68cb
Merge branch 'master' into st/fix/rename-abi-message-id-property
nedsalk Sep 19, 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": patch
"@fuel-ts/abi-coder": patch
---

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;
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([
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);
}
Torres-ssf marked this conversation as resolved.
Show resolved Hide resolved
}
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
38 changes: 37 additions & 1 deletion packages/fuel-gauge/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1266,4 +1268,38 @@ describe('Contract', () => {
expect(scriptGasLimit?.toNumber()).toBe(gasLimit);
expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee);
});

it('can call SMO contract', async () => {
using launched = await launchTestNode({
contractsConfigs: [
{
factory: SmoContractFactory,
},
],
});

const {
provider,
wallets: [recipient],
contracts: [contract],
} = launched;

const data = true;
const baseAssetId = provider.getBaseAssetId();

const { waitForResult } = await contract.functions
.send_typed_message_bool(recipient.address.toB256(), data, 1)
.callParams({ forward: [1, baseAssetId] })
.call();

const {
transactionResult: { receipts },
} = await waitForResult();

const messageOutReceipt = receipts.find(
({ type }) => ReceiptType.MessageOut === type
) as ReceiptMessageOut;

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