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

fix: incorrect coder matching #3162

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/many-beans-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-coder": patch
---

fix: incorrect coder matching
6 changes: 3 additions & 3 deletions packages/abi-coder/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const STR_SLICE_CODER_TYPE = 'str';
export const VOID_TYPE = '()';

export const optionRegEx: RegExp = /^enum (std::option::)?Option$/m;
export const stringRegEx = /str\[(?<length>[0-9]+)\]/;
export const arrayRegEx = /\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
export const structRegEx = /struct.+/;
export const stringRegEx = /^str\[(?<length>[0-9]+)\]/;
export const arrayRegEx = /^\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
export const structRegEx = /^struct.+/;
export const enumRegEx = /^enum.+$/;
export const tupleRegEx = /^\((?<items>.*)\)$/;
export const genericRegEx = /^generic.+$/;
Expand Down
11 changes: 11 additions & 0 deletions packages/fuel-gauge/src/coverage-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,4 +839,15 @@ describe('Coverage Contract', { timeout: 15_000 }, () => {

expect(results).toStrictEqual([1, 2, SmallEnumInput.Empty, INPUT_B, INPUT_A]);
});

it('should handle an enum from a library', async () => {
using contractInstance = await setupContract();

const { waitForResult } = await contractInstance.functions
.echo_enum_namespaced({ GameOver: 1 })
.call();

const { value } = await waitForResult();
expect(value).toStrictEqual({ GameOver: 1 });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"complex-script",
"configurable-contract",
"coverage-contract",
"data-structure-library",
"generic-types-contract",
"large-contract",
"multi-token-contract",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ license = "Apache-2.0"
name = "coverage-contract"

[dependencies]
data-structure-library = { path = "../data-structure-library" }
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::logging::log;
use std::option::Option;
use std::storage::*;
use std::vec::Vec;
use data_structure_library::GameState;

pub struct U8Struct {
i: u8,
Expand Down Expand Up @@ -126,6 +127,7 @@ abi CoverageContract {
inputD: b256,
) -> Vec<b256>;
fn types_result(x: Result<u64, u32>) -> Result<u64, str[10]>;
fn echo_enum_namespaced(value: GameState) -> GameState;
}

pub fn vec_from(vals: [u32; 3]) -> Vec<u32> {
Expand Down Expand Up @@ -463,4 +465,8 @@ impl CoverageContract for Contract {
Err(MyContractError::DivisionByZero) => Err(__to_str_array("DivisError")),
}
}

fn echo_enum_namespaced(value: GameState) -> GameState {
value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "data-structure-library"

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

pub enum GameState {
Playing: u8,
GameOver: u8,
}