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

SorobanArbitrary to be implemented for (T, V) tuple #1053

Closed
gangov opened this issue Aug 11, 2023 · 4 comments · Fixed by #1125
Closed

SorobanArbitrary to be implemented for (T, V) tuple #1053

gangov opened this issue Aug 11, 2023 · 4 comments · Fixed by #1125

Comments

@gangov
Copy link

gangov commented Aug 11, 2023

What problem does your feature solve?

error: Broken pipe (os error 32)
Error: warning: build failed, waiting for other jobs to finish...
error: could not compile `curve` (lib test) due to 9 previous errors
Error: Aug 08 15:23:48.238 ERROR cargo_tarpaulin: Failed to compile tests!
error[E0277]: the trait bound `(u64, u128): SorobanArbitrary` is not satisfied
Error:    --> packages/curve/src/lib.rs:41:1
    |
41  | #[contracttype]
    | ^^^^^^^^^^^^^^^ the trait `SorobanArbitrary` is not implemented for `(u64, u128)` 

the tuple in question is in a soroban_sdk::Vector within the storage of our contract.

What would you like to see?

SorobanArbitrary to have tuple support

What alternatives are there?

none

@leighmcculloch
Copy link
Member

Thanks for reporting the error. Could you share what the type is that the underneath the contracttype attribute? It's unclear what the type is.

@gangov
Copy link
Author

gangov commented Sep 12, 2023

hey @leighmcculloch sorry for the late reply.
It looks like the following:

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct VerySpecialStruct {
    pub foo: Vec<(u64, u128)>,
}

the above doesn't work.

As a workaround, we changed that to

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct VerySpecialStruct {
    pub foo: Vec<OurType>,
} 

where OurType is

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct OurType {
    x: u64,
    y: u128,
}

@brson
Copy link
Contributor

brson commented Oct 26, 2023

Ah good catch. I forgot about tuples here. I'll look at this asap.

@brson
Copy link
Contributor

brson commented Oct 27, 2023

I've submitted the fix in #1125, which does fix the original reported use case of structs containing vecs of tuples.

I discovered though that structs/enums still cannot contain tuple fields because of #1124

github-merge-queue bot pushed a commit that referenced this issue Oct 28, 2023
### What

Implement SorobanArbitrary for tuples of up to 12 elements.

### Why

This was accidentally omitted previously. Fixes
#1053

### Known limitations

Using tuples in struct fields is still blocked on
#1124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants