Skip to content

Commit

Permalink
feat!: implement abi spec changes (#1465)
Browse files Browse the repository at this point in the history
FuelLabs/fuel-specs#599

### Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have updated the documentation.
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added necessary labels.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: hal3e <git@hal3e.io>
  • Loading branch information
esdrubal and hal3e authored Jul 26, 2024
1 parent bb748fa commit 867ac33
Show file tree
Hide file tree
Showing 29 changed files with 556 additions and 1,397 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.79.0
FORC_VERSION: 0.62.0
FORC_PATCH_BRANCH: ""
FORC_PATCH_BRANCH: "esdrubal/abi_changes"
FORC_PATCH_REVISION: ""
NEXTEST_HIDE_PROGRESS_BAR: "true"
NEXTEST_STATUS_LEVEL: "fail"
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked.
- name: Build Sway test projects w type paths
run: forc build --release --terse --error-on-warnings --json-abi-with-callpaths --path e2e
run: forc build --release --terse --error-on-warnings --path e2e

- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ chrono = "0.4.31"
elliptic-curve = { version = "0.13.8", default-features = false }
eth-keystore = "0.5.0"
flate2 = { version = "1.0", default-features = false }
fuel-abi-types = "0.5.2"
fuel-abi-types = "0.7.0"
futures = "0.3.29"
hex = { version = "0.4.3", default-features = false }
itertools = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cargo fmt --all -- --check &&
forc fmt --check &&
forc build --release --terse &&
cargo clippy --all-targets &&
forc build --release --terse --json-abi-with-callpaths &&
forc build --release --terse &&
cargo clippy --all-targets --all-features &&
cargo test --all-targets --all-features &&
cargo test --all-targets --all-features --workspace &&
Expand Down
2 changes: 1 addition & 1 deletion docs/src/types/custom_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum SomeEnum<T, K> {
}
```

To lessen the impact to developer experience you may use `SomeStruct::new` to initialize the above structure without bothering with the `PhantomData`s:
To lessen the impact to developer experience you may use the `new` method to initialize a structure without bothering with the `PhantomData`s.:

```rust,ignore
{{#include ../../../examples/types/src/lib.rs:unused_generics_struct}}
Expand Down
6 changes: 1 addition & 5 deletions docs/src/types/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ To make working with `SizedAsciiString`s easier, you can use `try_into()` to con
{{#include ../../../packages/fuels-core/src/types/core/sized_ascii_string.rs:conversion}}
```

If your contract's method takes and returns, for instance, a Sway's `str[23]`. When using the SDK, this method will take and return a `SizedAsciiString<23>`, and you can pass a string to it like this:

```rust,ignore
{{#include ../../../e2e/tests/types_contracts.rs:contract_takes_string}}
```
If your contract's method takes and returns, for instance, a Sway's `str[23]`. When using the SDK, this method will take and return a `SizedAsciiString<23>`.
5 changes: 5 additions & 0 deletions e2e/sway/abi/simple_contract/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "simple_contract"
11 changes: 11 additions & 0 deletions e2e/sway/abi/simple_contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract;

abi SimpleContract {
fn takes_u32_returns_bool(arg: u32) -> bool;
}

impl SimpleContract for Contract {
fn takes_u32_returns_bool(_arg: u32) -> bool {
true
}
}
5 changes: 5 additions & 0 deletions e2e/sway/abi/wasm_contract/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "wasm_contract"
20 changes: 20 additions & 0 deletions e2e/sway/abi/wasm_contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
contract;

enum SomeEnum<T> {
V1: (),
V2: T,
}

#[allow(dead_code)]
struct SomeStruct {
a: u32,
b: bool,
}

abi TestContract {
fn test_function(arg: SomeEnum<SomeStruct>);
}

impl TestContract for Contract {
fn test_function(_arg: SomeEnum<SomeStruct>) {}
}
5 changes: 5 additions & 0 deletions e2e/sway/abi/wasm_predicate/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "wasm_predicate"
9 changes: 9 additions & 0 deletions e2e/sway/abi/wasm_predicate/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
predicate;

configurable {
U64: u64 = 128,
}

fn main(val: u64) -> bool {
val == U64
}
17 changes: 10 additions & 7 deletions e2e/sway/types/contracts/generics/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ contract;

use std::hash::*;

struct StructOneUnusedGenericParam<T> {}
#[allow(dead_code)]
struct StructUnusedGeneric<T, K> {
field: u64,
}

#[allow(dead_code)]
enum EnumOneUnusedGenericParam<T> {
One: (),
enum EnumUnusedGeneric<T, K> {
One: u64,
}

struct StructTwoUnusedGenericParams<T, K> {}
Expand Down Expand Up @@ -62,8 +65,8 @@ impl Hash for str[3] {

abi MyContract {
fn unused_generic_args(
arg_1: StructOneUnusedGenericParam<u64>,
arg_2: EnumOneUnusedGenericParam<u32>,
arg_1: StructUnusedGeneric<u64, u32>,
arg_2: EnumUnusedGeneric<u32, u32>,
);
fn two_unused_generic_args(
arg_1: StructTwoUnusedGenericParams<u32, u64>,
Expand All @@ -85,8 +88,8 @@ abi MyContract {

impl MyContract for Contract {
fn unused_generic_args(
_arg_1: StructOneUnusedGenericParam<u64>,
_arg_2: EnumOneUnusedGenericParam<u32>,
_arg_1: StructUnusedGeneric<u64, u32>,
_arg_2: EnumUnusedGeneric<u32, u32>,
) {}

fn two_unused_generic_args(
Expand Down
8 changes: 5 additions & 3 deletions e2e/sway/types/contracts/nested_structs/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
contract;

pub struct SomeStruct {
par1: u32,
field: u32,
field_2: bool,
}

pub struct AllStruct {
Expand Down Expand Up @@ -32,12 +33,13 @@ impl MyContract for Contract {
fn get_struct() -> AllStruct {
AllStruct {
some_struct: SomeStruct {
par1: 12345u32,
field: 12345u32,
field_2: true,
},
}
}
fn check_struct_integrity(arg: AllStruct) -> bool {
arg.some_struct.par1 == 12345u32
arg.some_struct.field == 12345u32 && arg.some_struct.field_2 == true
}

fn nested_struct_with_reserved_keyword_substring(call_data: CallData) -> CallData {
Expand Down
60 changes: 30 additions & 30 deletions e2e/tests/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@ async fn compile_bindings_from_contract_file() {
async fn compile_bindings_from_inline_contract() -> Result<()> {
abigen!(Contract(
name = "SimpleContract",
// abi generated with: "e2e/sway/abi/simple_contract"
abi = r#"
{
"types": [
"programType": "contract",
"specVersion": "1",
"encodingVersion": "1",
"concreteTypes": [
{
"type": "bool",
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903"
},
{
"type": "u32",
"concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc"
}
],
"metadataTypes": [],
"functions": [
{
"inputs": [
{
"typeId": 0,
"type": "bool",
"components": null,
"typeParameters": null
},
{
"typeId": 1,
"type": "u32",
"components": null,
"typeParameters": null
}
],
"functions": [
{
"inputs": [
{
"name": "only_argument",
"type": 1,
"typeArguments": null
}
],
"name": "takes_ints_returns_bool",
"output": {
"name": "",
"type": 0,
"typeArguments": null
}
"name": "_arg",
"concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc"
}
]
],
"name": "takes_u32_returns_bool",
"output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"attributes": null
}
],
"loggedTypes": [],
"messagesTypes": [],
"configurables": []
}
"#,
));
Expand All @@ -94,7 +94,7 @@ async fn compile_bindings_from_inline_contract() -> Result<()> {

let contract_instance = SimpleContract::new(null_contract_id(), wallet);

let call_handler = contract_instance.methods().takes_ints_returns_bool(42_u32);
let call_handler = contract_instance.methods().takes_u32_returns_bool(42_u32);
let encoded_args = call_handler.call.encoded_args.unwrap();

assert_eq!(encoded_args, [0, 0, 0, 42]);
Expand Down
Loading

0 comments on commit 867ac33

Please sign in to comment.