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: fix overly broad tuple type check #1315

Merged
merged 2 commits into from
Aug 31, 2023
Merged

Conversation

deekerno
Copy link
Contributor

@deekerno deekerno commented Aug 30, 2023

Description

While debugging an issue for a grantee, I noticed that is_tuple_type() was causing the unit type (()) to not be included as part of the hash table keeps track of types in a contract ABI. After fixing that, I noticed that we needed to add a unit type check to is_nondecodable_type() so that we do not create a decoder for it.

Testing steps

On develop:

  1. cargo build -p forc-index
  2. Create a new indexer.
  3. Change the fuel-indexer-utils dependency to use the local package (make sure you're still on develop).
  4. Save the following reproduction ABI and adjust the indexer manifest accordingly:
{
  "types": [
    {
      "typeId": 0,
      "type": "()",
      "components": [],
      "typeParameters": null
    },
    {
      "typeId": 1,
      "type": "enum ExampleEnum",
      "components": [
        {
          "name": "A",
          "type": 0,
          "typeArguments": null
        }
      ],
      "typeParameters": null
    }
  ],
  "functions": [
    {
      "inputs": [
        {
          "name": "e",
          "type": 1,
          "typeArguments": null
        }
      ],
      "name": "example_fn",
      "output": {
        "name": "",
        "type": 0,
        "typeArguments": null
      },
      "attributes": null
    }
  ],
  "loggedTypes": [],
  "messagesTypes": [],
  "configurables": []
}
  1. cargo build

The build should fail with the error:
message: Could not derive TypeApplication param types.: InvalidData("type id 0 not found in type lookup").

On this branch:

  1. Switch to this branch and ensure that you have the changes from this PR present locally.
  2. Run cargo build again.

The indexer should successfully build.

Changelog

  • 2c87dd4 - fix type check
  • 1e1900e - upgrade test contracts to Sway v0.45.0

Notes

The ABI included above was generated for the following Sway contract using Sway v0.45:

contract;

pub enum ExampleEnum {
    A: (),
}

abi BugReproduction {
    fn example_fn(e: ExampleEnum);
}

impl BugReproduction for Contract {
    fn example_fn(e: ExampleEnum) {
        match e {
            ExampleEnum::A => {},
        }
    }
}

@deekerno deekerno added the bug Something isn't working label Aug 30, 2023
@deekerno deekerno self-assigned this Aug 30, 2023
@deekerno deekerno marked this pull request as ready for review August 31, 2023 00:15
Copy link
Contributor

@ra0x3 ra0x3 left a comment

Choose a reason for hiding this comment

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

  • Looks Ok thanks @deekerno
  • Left a small comment regarding style (not a blocker for merge)
  • We can cut a patch release for this if necessary - but beta-3 is only gonna last for a few more days anyway

packages/fuel-indexer-macros/src/helpers.rs Show resolved Hide resolved
@deekerno deekerno merged commit a01f5ab into develop Aug 31, 2023
21 checks passed
@deekerno deekerno deleted the deekerno/unit-type-stuff branch August 31, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants