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

Support for reading ScVal contract parameters and fuzzing over them #17

Merged
merged 13 commits into from
Jul 30, 2024

Conversation

gtrepta
Copy link
Contributor

@gtrepta gtrepta commented Jul 30, 2024

This implements a number of the available SCVals in soroban as dataclasses that allow reading of the bindings from a soroban contract and generating values for them with hypothesis.

@gtrepta gtrepta marked this pull request as ready for review July 30, 2024 00:47
@gtrepta gtrepta requested a review from bbyalcinkaya July 30, 2024 00:47
Copy link
Member

@bbyalcinkaya bbyalcinkaya left a comment

Choose a reason for hiding this comment

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

Great work on the code! Everything looks good.

Just FYI, if we want to support custom types in bindings in the future, we'll need to find a way to distinguish between structs and tuples (haven't tried with enums) in the bindings JSON generated by the soroban CLI. Right now, we can get away without it since we only need bindings for test contracts. Structs and tuples look the same in the JSON, but they should be encoded differently (Vec for tuples and Map for structs).

For example:

#[contracttype]
pub struct Foo(u32, u32);

#[contracttype]
pub struct Bar {
  x: u32,
  y: u32
}

#[contractimpl]
impl TypesContract {
    pub fn struct_tuple(_env: Env, _tuple: Foo, _struct: Bar) { }
}

The generated JSON for the struct_tuple endpoint using these types will not differentiate between Foo (tuple) and Bar (struct):

{
  "type": "function",
  "doc": "",
  "name": "struct_tuple",
  "inputs": [
    {
      "doc": "",
      "name": "_tuple",
      "value": {
        "type": "custom",
        "name": "Foo"
      }
    },
    {
      "doc": "",
      "name": "_struct",
      "value": {
        "type": "custom",
        "name": "Bar"
      }
    }
  ],
  "outputs": []
}

If we ever decide to support this, we'll need a solution for distinguishing these types.

@rv-jenkins rv-jenkins merged commit 4f2496a into master Jul 30, 2024
3 checks passed
@rv-jenkins rv-jenkins deleted the scval-types branch July 30, 2024 16:01
asavienko added a commit that referenced this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants