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

chore: add full abi coder tests #3349

Draft
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

petertonysmith94
Copy link
Contributor

@petertonysmith94 petertonysmith94 commented Oct 21, 2024

Summary

  • We've added a feature complete contract (abi-contract) that taking in fixed inputs, and returns an expected value.
    • We did as @nedsalk mentioned that Sway does some precompiling.
  • We have added tests for each of the functions of the contract, currently using our current encoding package @fuel-ts/abi-coder.
    • This will allow us to switch out the Interface for our new refactored package with absolute certainty of no regression.
  • I have added a new custom vitest matcher toEqualBn to make it easier to check returned BN values.

Couple issues

  • For the custom vitest matchers, I struggled to get this working with TS so have added a TS ignore (// @ts-expect-error: Custom matcher 'toEqualBn') for now.
  • I was getting some odd results from some functions whereby the inputs we're being returned as the outputs. These are marked as (Most of these are suffering from the similar issue around returning the input as the output.)

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

Comment on lines +627 to +633
const EXPECTED_ENUM = EnumWithNative::Pending;
const EXPECTED: StructWithEnumArray = StructWithEnumArray {
a: [EXPECTED_ENUM, EXPECTED_ENUM, EXPECTED_ENUM],
};

EXPECTED
}
Copy link
Contributor

@Torres-ssf Torres-ssf Nov 18, 2024

Choose a reason for hiding this comment

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

There’s something odd happening here. The types_struct_with_array_of_enums function is clearly returning a struct containing an array of three EnumWithNative::Pending values:

const EXPECTED_ENUM = EnumWithNative::Pending;
const EXPECTED: StructWithEnumArray = StructWithEnumArray {
    a: [EXPECTED_ENUM, EXPECTED_ENUM, EXPECTED_ENUM],
};

EXPECTED

Based on this, after decoding, we should see the following result:

{ a: ['Pending', 'Pending', 'Pending'] }

However, when the TS SDK decodes the data, the result is:

{ a: ['Pending', 'Checked', 'Pending'] }

At first, this seems like a decoding issue in the TS SDK. But after inspecting the raw receipt ReturnData, I am under the impression that the data returned itself is inconsistent:

// raw receipt
{
  id: '0xa52541ced4559cf68e923e81ffc900d6855994bfabad4dd9f24c4dfea8e4f183',
  pc: '44544',
  is: '11712',
  ptr: '67107840',
  digest: '0x639809bc6d63798b4571d10a078c77219a7191b65eb30d8b08415d8631c1dbd9',
  len: '24',
  receiptType: 'RETURN_DATA',
  data: '0x000000000000000100000000000000000000000000000001',
}

At a first glance, it appears to me that the data should be something like:

0x000000000000000100000000000000010000000000000001

Since the 3 enum values being returned are exactly the same.

@nedsalk @petertonysmith94 Do you guys know what is happening here?

@Torres-ssf
Copy link
Contributor

Torres-ssf commented Nov 18, 2024

@petertonysmith94 I was able to fix and validate many cases here except the following 3:

  • types_struct_with_array_of_enums
  • types_struct_with_multiple_struct_params
  • types_struct_with_complex_nested_struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants