Skip to content

Commit

Permalink
Tests for derivation macros with where clauses. (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak authored Aug 19, 2023
1 parent 477177f commit e2f0bdd
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
2 changes: 1 addition & 1 deletion concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ getrandom = { version = "0.2", features = ["custom"], optional = true }

[dependencies.concordium-contracts-common]
path = "../concordium-contracts-common/concordium-contracts-common"
version = "7.0"
version = "7.1"
default-features = false
features = ["smart-contract"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ struct State1<T, A> {
other: A,
}

#[derive(DeserialWithState)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhere<S>
where
S: HasStateApi,
S: Clone, {
test_map: StateMap<u32, String, S>,
}

#[rustfmt::skip] // maintain lack of trailing comma, and empty where clause
mod inner {
use super::*;
#[derive(DeserialWithState)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhereTwo<S>
where
S: HasStateApi,
S: Clone { // no trailing comma
test_map: StateMap<u32, String, S>,
}

#[derive(DeserialWithState)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhereThree<S: Deserial>
where //empty where clause
{
test: S,
}
}

trait ProxyTrait {
type State: HasStateApi;
}
Expand Down
29 changes: 29 additions & 0 deletions concordium-std/tests/derive-deserial/success-generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@ enum MyOtherEnum<A, B> {
Two(A, B),
}

#[derive(Deserial)]
struct WithStateParameterWhere<S>
where
S: Clone,
S: PartialOrd, {
value: S,
}

#[rustfmt::skip] // skip formatting to maintain lack of trailing comma
mod inner {
use super::*;
#[derive(Deserial)]
struct WithStateParameterWhereTwo<S>
where
S: Clone,
// note the lack of comma compared to the test above
S: PartialOrd {
value: S,
}

#[derive(Deserial)]
struct WithStateParameterWhereThree<S>
where // empty where clause
{
value: S,
}
}


#[derive(Deserial)]
#[concordium(bound(deserial = ""))]
struct ExplicitBound<A> {
Expand Down
31 changes: 31 additions & 0 deletions concordium-std/tests/derive-serial/success-generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ struct WithStateParameter<S: HasStateApi> {
test_map: StateMap<u32, String, S>,
}

#[derive(Serial)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhere<S>
where
S: HasStateApi,
S: Clone, {
test_map: StateMap<u32, String, S>,
}

#[rustfmt::skip] // skip formatting to maintain lack of trailing comma
mod inner {
use super::*;
#[derive(Serial)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhereTwo<S>
where
S: HasStateApi,
S: Clone { // note the lack of comma compared to the test above
test_map: StateMap<u32, String, S>,
}

#[derive(Serial)]
#[concordium(state_parameter = "S")]
struct WithStateParameterWhereThree<S: HasStateApi>
where // empty where clause
{
test_map: StateMap<u32, String, S>,
}
}


trait ProxyTrait {
type State: HasStateApi;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cis3-nft-sponsored-txs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cargo concordium build -e --out contract.wasm.v1
Run the following command to run the unit and integration tests:

```
cargo concordium test
cargo concordium test
```
```
cargo test
cargo test
```

0 comments on commit e2f0bdd

Please sign in to comment.