-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
There was a problem hiding this 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.
This implements a number of the available
SCVal
s in soroban as dataclasses that allow reading of the bindings from a soroban contract and generating values for them with hypothesis.