Skip to content

Commit

Permalink
fix: incorrect coder matching (#3162)
Browse files Browse the repository at this point in the history
* chore: added test to provide issue

* chore: fixed RegEx

* fix: incorrect coder matching

* chore: release to NPM

* chore: removed NPM deploy
  • Loading branch information
petertonysmith94 authored Sep 13, 2024
1 parent c21096c commit 9719c1b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
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 });
});
});
1 change: 1 addition & 0 deletions packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml
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 <[email protected]>"]
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,
}

0 comments on commit 9719c1b

Please sign in to comment.